Home > Article > Web Front-end > Why Does My Text Inherit Background Opacity in CSS?
CSS Background Opacity Revisited
When using CSS, you might encounter a scenario where you set a background opacity and expect the text within that container to remain fully opaque. However, you find that the text also inherits the background's opacity, resulting in a faded appearance.
This behavior is inherent in CSS. Children elements, including text, inherit the opacity properties of their parent elements. To address this issue, there are a few options:
<code class="css">background-color: rgba(0, 0, 0, 0.5);</code>
This code will set the background color to 50% transparent black, allowing the text to remain fully opaque.
The above is the detailed content of Why Does My Text Inherit Background Opacity in CSS?. For more information, please follow other related articles on the PHP Chinese website!