How to make div appear in front of another?

HtmlCss

Html Problem Overview


Please refer to the codes below :

<ul>
 <li style="height:100px; overflow:hidden;">
  <div style="height:500px; background-color:black;">
  </div>
 </li>
</ul>

From the codes above, we know that we can only see 100px height of

black background. My question is how can we see 500px height of <div> black background? In other words, how can I make the <div> appear in front of <li> ?

Html Solutions


Solution 1 - Html

Use the CSS z-index property. Elements with a greater z-index value are positioned in front of elements with smaller z-index values.

Note that for this to work, you also need to set a position style (position:absolute, position:relative, or position:fixed) on both/all of the elements you want to order.

Solution 2 - Html

You can set the z-index in css

<div style="z-index: -1"></div>

Solution 3 - Html

In order an element to appear in front of another you have to give higher z-index to the front element, and lower z-index to the back element, also you should indicate position: absolute/fixed...

Example:

<div style="z-index:100; position: fixed;">Hello</div>
<div style="z-index: -1;">World</div>

Solution 4 - Html

Upper div use higher z-index and lower div use lower z-index then use absolute/fixed/relative position

Solution 5 - Html

The black div will display the full 500px unless overflow:hidden is set on the 100px li

Solution 6 - Html

I think you're missing something.

http://jsfiddle.net/ZNtKj/

<ul>
 <li style="height:100px;overflow:hidden;">
  <div style="height:500px; background-color:black;">
  </div>
 </li>
</ul>
<ul>
 <li style="height:100px;">
  <div style="height:500px; background-color:red;">
  </div>
 </li>
</ul>

In FF4, this displays a 100px black bar, followed by a 500px red block.

A little bit different example:

http://jsfiddle.net/ZNtKj/1/

<ul>
 <li style="height:100px;overflow:hidden;">
  <div style="height:500px; background-color:black;">
  </div>
 </li>
</ul>
<ul>
 <li style="height:100px;">
  <div style="height:500px; background-color:red;">
  </div>
 </li>
 <li style="height:100px;overflow:hidden;">
  <div style="height:500px; background-color:blue;">
  </div>
 </li>
 <li style="height:100px;overflow:hidden;">
  <div style="height:500px; background-color:green;">
  </div>
 </li>
</ul>

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
Questionzac1987View Question on Stackoverflow
Solution 1 - HtmlarothView Answer on Stackoverflow
Solution 2 - HtmlGreg RandallView Answer on Stackoverflow
Solution 3 - HtmlJasur ShukurovView Answer on Stackoverflow
Solution 4 - Htmldinuka samindaView Answer on Stackoverflow
Solution 5 - HtmlDavid John SmithView Answer on Stackoverflow
Solution 6 - HtmlJared FarrishView Answer on Stackoverflow