css - Why position: relative; places background elements their existent on front? -


.main-column h2 {     padding-top: 110px;     padding-bottom: 110px;     background: url('someimagehere.png') no-repeat center top;     margin: 0 auto;     position: relative; /*so image stays on top.*/ }  .text-column {     width: 215px;     background-color: yellow;     margin-top: -120px; /*so enters inside h2*/     padding-top: 120px;     margin-left: auto;     margin-right: auto; }  <div class="main-column">  <h2>hello tittle 1</h2>   <div class="text-column">    <p>i'm on column 1 , it</p>    <p>i'm on column 1 well</p>   </div> </div> 

this works, don't it.

why given "position: relative" h2, place background image there visible, on top of other element yellow background color?

again, code works. i'm asking on understanding behavior.

please advice

using position:relative or position:absolute or position:fixed allows use z-index value determine order of stacking.

if set z-index:-1 on h2 should push behind other elements. alternatively set position:relative on other element , set higher z-index on that.


Comments

Popular posts from this blog

basic authentication with http post params android -

vb.net - Virtual Keyboard commands -

css - Firefox for ubuntu renders wrong colors -