To achieve a transparent background with opaque text, use the rgba color value in CSS to set the background color. The rgba function takes four parameters: red, green, blue, and alpha (transparency), where alpha ranges from 0 (fully transparent) to 1 (fully opaque).
Here is a simple example:
css.transparent-background { /* Set text color to opaque black */ color: #000000; /* Set background color to semi-transparent white */ background-color: rgba(255, 255, 255, 0.5); }
In the CSS class above, the text color is specified using a hexadecimal value, ensuring opaque text. The background color uses rgba with alpha set to 0.5, meaning the background is semi-transparent. This achieves a semi-transparent background while keeping the text content opaque.
HTML elements using this class are as follows:
html<div class="transparent-background"> This text has a semi-transparent background, but the text itself is opaque. </div>
Using this approach, the text remains opaque regardless of the background color chosen.