html - Can an :after background-image be used to overlap the next element? -
i have image i'd add :after element nav bar. point being :after cover top portion of next section (this part of design).
the :after set position: absolute top: 100% , seems disappear under next element , z-index hasn't helped. when top set less 100%, can see :after element above nav.
the markup:
<nav>contents</nav> <div>contents</div>
the css:
nav { width: 100%; position: relative; } nav:after { content: ''; width: 100%; height: 66px; background-image: url('image.png'); background-repeat: repeat-x; position: absolute; left: 0; top: 100%; } no css div yet...
thanks in advance!
all need set z-index on content div lower of pseudo-element note content div must have position setting on other static...position:relative sufficient.
alternatively, set z-index
of pseudo-element higher of div (which default 1).
nav { width: 100%; position: relative; height: 50px; background: lightgreen; } nav:after { content: ''; width: 100%; height: 66px; background: rgba(0, 0, 255, 0.5); background-repeat: repeat-x; position: absolute; left: 0; top: 100%; z-index: 2; } div { height: 260px; position: relative; background: rgba(255, 0, 0, 0.5); }
<nav>nav</nav> <div>contents</div>
Comments
Post a Comment