html - Background image z-index issue with image element -


i wanna make overlay background image image. code here. how can put background image on img element?

my html is;

<div id="sidebar">         <div class="editor-select">             <img src="http://i.imgur.com/mh3noqh.jpg" alt="img"/>         </div>     </div> 

my css is;

  #sidebar{   width: 344px;   background: url("http://i.imgur.com/bqc7nyp.png") no-repeat top right !important;   float: left;   height: 500px;   margin-top: 45px;   padding: 8px;   position: relative;   z-index: 1000; }  .editor-select{   width: 350px;   height: 360px;   position: relative; }  .editor-select>img{       width: 320px;     height: 160px;    z-index : -1; } 

you can't. img element contained within #sidebar element, makes img element on top of #sidebar element. cannot position parent element on top of child.

pure css solution

what can do, however, use pseudo-element (:before or :after), positioned on top of img element (which i've offset 6px on 4 sides allow image overlap properly):

.editor-select:after {       content: '';       position: absolute;       top: -6px;       left: -6px;       height: 172px;       width: 332px;       background: url("http://i.imgur.com/bqc7nyp.png") no-repeat top right } 

codepen demo.

demo


Comments

Popular posts from this blog

commonjs - How to write a typescript definition file for a node module that exports a function? -

openid - Okta: Failed to get authorization code through API call -

thorough guide for profiling racket code -