Home >Web Front-end >CSS Tutorial >How to Create a Fading Background Without Affecting Child Element Visibility Using HTML/CSS?
Problem:
Implementing a fading effect for the background while keeping a child element visible can be challenging using opacity alone. This is encountered when attempting to create a popup box that highlights itself by dimming the underlying content.
Solution:
To achieve the desired effect, combine opacity with background color as follows:
<code class="css">#container { border: solid gold 1px; width: 400px; height: 200px; background:rgba(56,255,255,0.1); } #box { border: solid silver 1px; margin: 10px; width: 300px; height: 100px; background:rgba(205,206,255,0.1); }</code>
By setting the background property with a rgba value, you specify the opacity of the container, which represents the content behind the popup box, while preserving the visibility of the #box element. The rgb values represent the color, while the a value indicates the transparency level.
To apply this approach, implement the CSS code provided and include the following HTML:
<code class="html"><div id="container"> container text <div id="box"> box text </div> </div></code>
The above is the detailed content of How to Create a Fading Background Without Affecting Child Element Visibility Using HTML/CSS?. For more information, please follow other related articles on the PHP Chinese website!