Home >Web Front-end >CSS Tutorial >How Can I Apply Opacity to a CSS Color Variable While Preserving Background Images?
:root { --color: #f0f0f0; }<p>You can apply 80% opacity to it with:
#element { background-color: rgba(var(--color), 0.8); }<p>This results in:
<p><p>where the background color of the element has 80% opacity while maintaining the background image. <p>Implementation Note: <p>This method is supported by all major browsers. However, it's worth noting that it converts the hex value to decimal RGB, which may affect the accuracy of the color representation in some situations.
The above is the detailed content of How Can I Apply Opacity to a CSS Color Variable While Preserving Background Images?. For more information, please follow other related articles on the PHP Chinese website!