Set The Opacity Only to Background Color Not On The Text In Css

admin_img Posted By Bajarangi soft , Posted On 09-10-2020

The opacity property is used in the image to describes the transparency of the image. The value of opacity lies between 0.0 to 1.0 where the low value represents high transparent and high value represents low transparent. The percentage of opacity is calculated as Opacity% = Opacity * 100

Opacity In CSS

To set the opacity only to the background and not the text inside it. It can be set by using the RGBA color values instead of the opacity property because using the opacity property can make the text inside it fully transparent element.
Syntax:

element {
    background: rgba(red, green, blue, alpha);
    // CSS property
}
Example
<!DOCTYPE html>
<html>
<head>
    <title>rgba property</title>
    <style>
        h1 {
            color: #e3a425;
        }
        h1, h2 {
            text-align: center;
        }
        div {
            background: rgb(241, 118, 60);
            padding: 10px;
            text-align:justify;
        }

        div.first {
            /*setting alpha = 0.1*/
            background: rgba(236, 168, 155, 0.1);
        }

        div.second {
            /*setting alpha = 0.3*/
            background: rgba(229, 212, 212, 0.3);
        }

        div.third {
            /*setting alpha = 0.6*/
            background: rgba(234, 128, 58, 0.6);
        }
    </style>
</head>
<body>
<h1>BARAJARANGI SOFT</h1>
<h2>Using RGBA color values:</h2>
<div class="first">
    <p>This paragraph is shown at 10% opacity.</p></div>
<div class="second">
    <p>This paragraph is shown at 30% opacity.</p></div>
<div class="third">
    <p>This paragraph is shown at 60% opacity.</p></div>
<div><p>This is default.</p></div>
</body>
</html>

Related Post