Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

change background opacity with CSS

Tags:

css

how I can change opacity of div background that doesn't make change opacity of text or anything inside of that?

<html lang="en">
<head>
    <meta charset="UTF-8">
    <title></title>
</head>
<body>

    <div class="bg">
        <h1>welcome</h1>
        <p>Hello world. Welcome to my site</p>
    </div>

</body>
</html>



<style>
    .bg{
        background-color: black;
        color: #ffffff;
    }
</style>
like image 241
guidance Avatar asked Aug 16 '14 08:08

guidance


People also ask

How do you control opacity in CSS?

Transparency using RGBA In addition to RGB, you can use an RGB color value with an alpha channel (RGBA) - which specifies the opacity for a color. An RGBA color value is specified with: rgba(red, green, blue, alpha). The alpha parameter is a number between 0.0 (fully transparent) and 1.0 (fully opaque).

How do I make the background transparent opacity in CSS?

Changing the opacity of the background color only To achieve this, use a color value which has an alpha channel—such as rgba. As with opacity , a value of 1 for the alpha channel value makes the color fully opaque. Therefore background-color: rgba(0,0,0,. 5); will set the background color to 50% opacity.

How do I make black opacity in CSS?

You have to add the following CSS property to achieve the transparency levels. This sets the background-color of an element to black with 50% opacity. The last value in an rgba value is the alpha value. An alpha value of 1 is equal to 100% opacity, and 0.5 (or .

What is CSS opacity transparency?

The opacity CSS property sets the opacity of an element. Opacity is the degree to which content behind an element is hidden, and is the opposite of transparency.


1 Answers

Have you tried to use the RGBa notation, where 'a' stands for alpha (opacity or transparency)?

<style>
  .bg {
     background-color: rgba(0, 0, 0, 0.5);
     color: #ffffff;
   }
   </style>
like image 200
Fabio Avatar answered Sep 30 '22 05:09

Fabio