"opacity css element showing through" Code Answer's
You're definitely familiar with the best coding language CSS that developers use to develop their projects and they get all their queries like "opacity css element showing through" answered properly. Developers are finding an appropriate answer about opacity css element showing through related to the CSS coding language. By visiting this online portal developers get answers concerning CSS codes question like opacity css element showing through. Enter your desired code related query in the search bar and get every piece of information about CSS code related question on opacity css element showing through.
opacity css element showing through
Opacity Affects Stacking Order
Consider the following HTML snippet:
<div class="wrapper tweak">
<div class="overlay">
<p>The Overlay Panel</p>
</div>
<div class="content">
<p>The main Content panel with a motif:
<b>♥</b> <b class="foggy">♠</b></p>
</div>
</div>
and the following CSS:
.wrapper {
position: relative;
outline: 1px solid blue;
}
.overlay {
position: absolute;
top: 0;
left: 0;
background-color: white;
border: 1px dotted blue;
width: 400px;
}
.content p b {
background-color: black;
color: white;
padding: 0 10px;
opacity: 1.0; /* default value */
}
.content p b.foggy {
opacity: 0.4;
}
.tweak .overlay {
z-index: 1;
}
Basically, I have a wrapper with two child div's, .overlay and .content. Note that the overlay is ahead of the content in the code (DOM). If it were after, you would not have seen the problem in the first place.
The content has two bold elements with two different opacity values.
See the basic line in the demo fiddle is at: http://jsfiddle.net/audetwebdesign/DxQZv/
When you enable the overlay, the .foggy element with opacity of 0.4 appears in front of the overlay. The stacking order for this arrangement is, from back to front: the in-flow content with opacity of 1.0 (default), the absolutely positioned overlay, then the element with opacity 0.4.
However, if you explicitly set z-index: 1 to the .overlay (add the .tweak class), then .overlay gets placed higher in the stacking order.
There are other ways of adjusting the z-index value to get the same effect, but this may be the simplest.
Reference:
See 9.9.1 Specifying the stack level: the 'z-index' property in the CSS2 spec
and 3.2. Transparency: the ‘opacity’ property in the CSS3 Color Module spec.
Technically, adding an opacity value (other than 1.0) to an element creates a new stacking context with z-index of 0, which is also what happens with a positioned element.
However, when two elements have the same z-index, they are painted in the order they appear in the DOM (tree order). In this case, the overlay is painted first followed by the bold element with opacity of 0.4, which is why it appears in front of the overlay.
There is also an earlier question that deals with the same issue:
What has bigger priority: opacity or z-index in browsers?
which I found after I posted my answer.
All those coders who are working on the CSS based application and are stuck on opacity css element showing through can get a collection of related answers to their query. Programmers need to enter their query on opacity css element showing through related to CSS code and they'll get their ambiguities clear immediately. On our webpage, there are tutorials about opacity css element showing through for the programmers working on CSS code while coding their module. Coders are also allowed to rectify already present answers of opacity css element showing through while working on the CSS language code. Developers can add up suggestions if they deem fit any other answer relating to "opacity css element showing through". Visit this developer's friendly online web community, CodeProZone, and get your queries like opacity css element showing through resolved professionally and stay updated to the latest CSS updates.