Jump to content

z-index doesn't work


Recommended Posts

See my code first

 <!DOCTYPE html><html><head><style> h1 {z-index:2;} img{position:absolute;left:0px;top:0px;z-index:1;}</style></head> <body><h1>This is a heading</h1><img src="w3css.gif" width="100" height="140" /><p>The z-index isn't working. The header should be in front of the image, but it isn't..</p></body></html>

Actually the code is from http://www.w3schools.com/cssref/tryit.asp?filename=trycss_zindex , i edited the code...Does z-index not work if we put positive numbers ?

Link to post
Share on other sites

An element must have position: absolute, position: relative; or position: fixed in order for z-index to have any effect. Give the <img> element a negative z-index and it will work fine for putting it behind the header. If you'd rather give the header a positive z-index you'll have to set the position property.

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...