Home  >  Article  >  Web Front-end  >  How to set background gray and transparency in css3

How to set background gray and transparency in css3

WBOY
WBOYOriginal
2021-12-10 14:15:4911458browse

Method: 1. Use the background attribute to set the background color to gray, just add the "background:#c0c0c0;" style to the element; 2. Use the opacity attribute to set the transparency of the element, just add "opacity" to the element :Transparency value;" style is enough.

How to set background gray and transparency in css3

The operating environment of this tutorial: Windows 10 system, CSS3&&HTML5 version, Dell G3 computer.

How to set the background to gray and transparent in css3

In css, you can use the background attribute to set the background to gray, just add " background:#c0c0c0" style is enough.

In CSS, you can use the opacity attribute to set the transparency of an element. The opacity attribute sets the opacity level of an element. Specifies opacity. From 0.0 (fully transparent) to 1.0 (fully opaque).

The example is as follows:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>
<body>
    <style>
      .div1{
        width:200px;
        height:200px;
        background:#c0c0c0 ;
      }
      .div2{
        width:200px;
        height:200px;
        background:#c0c0c0;
        opacity:0.5;
      }
    </style>
    设置灰色:
<div class="div1"></div>
设置灰色且透明度:
<div class="div2"></div>
</body>
</html>

Output result:

How to set background gray and transparency in css3

(Learning video sharing: css video tutorial)

The above is the detailed content of How to set background gray and transparency in css3. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn