Skip to content Skip to sidebar Skip to footer

How Can I Display A Header Element Above My Content?

How can I display all headers above the content divs? ('above' on the z-axis) so that the visible z-order is: CONTENT 1 (bottom-most element) CONTENT 2 HEADER 1 HEADER 2 (top-most

Solution 1:

The only way to achieve this is to be sure all your elements belong to the same stacking context so you need to avoid all the properties that creates stacking context like transfrom, opacity, fixed position, etc on the article elements:

article.oneheader {
  background: blue;
  color:#fff;
}
article.twoheader {
  background: red;
  color:#fff;
  width:200px;
}

article.two {
  margin-top:-115px;
}

header {
  width: 280px;
  height: 20px;
  margin:5px10px;
  position:relative;
  z-index:1;
 }
articlediv {
  position:relative;
  z-index:-1;
  background:green;
  height:100px;
  margin-top:-8px;
  color:#fff;
}
article.twodiv {
 background:pink;
}
<articleclass="one"><header><span>HEADER 1</span></header><div><span>CONTENT 1</span></div></article><articleclass="two"><header><span>HEADER 2</span></header><div><span>CONTENT 2</span></div></article>

Solution 2:

This is impossible. The article elements are position: fixed so they establish their own stacking contexts.

You can only position the header and div within the three-dimensional box established by the article.

This means you cannot have the content of one article between different parts of the content of another.

Post a Comment for "How Can I Display A Header Element Above My Content?"