Example of how to set div background transparent

Example of how to set div background transparent

There are two common ways to make div background transparent:

1. Set the opacity attribute to a value of 0~1, 0 for transparent and 1 for opaque. However, this method will also make the content on the div transparent.

The effect is as follows:

insert image description here

2. Set the background-color in rgba format. The format is: background-color:rgba(0,0,0,0~1), where 0 means transparent and 1 means opaque.

insert image description here

The code is as follows :

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        .id{
            width: 600px;
            height: 300px;
        
        }
        .tm1{
            margin: 40 auto;
            text-align: center;
            line-height: 200px;
            width: 800px;
            height: 200px;
            background-color: yellow;
            opacity: 0.6;
        }
        .tm2{
            margin: 40 auto;
            text-align: center;
            line-height: 200px;
            width: 800px;
            height: 200px;
            background-color: rgba(255, 255, 0, 0.5);
        }
    </style>
</head>
<body>
    <!--Background div-->
    <div class="id">
    <!--Transparent div method 1-->
    <div class="tm1">Transparent div method 1, set the transparency through opacity, the text on the div is also transparent: opacity: 0.6;</div><br>
    <!--Transparent div method 2-->
    <div class="tm2">Transparent div method 2, set transparency through rgba, the text on the div is not transparent: background-color:rgba(255,0,0,0.5);</div>
</div>
</body>
</html>

Here is another point to note:
The rgba() function uses the superposition of red®, green (G), blue (B), and transparency (A) to generate a variety of colors.

RGBA stands for Red, Green, Blue, Alpha (English: Red, Green, Blue, Alpha).
Red (R) An integer between 0 and 255, representing the red component of the color. .
Green (G) An integer between 0 and 255 representing the green component of the color.
Blue (B) An integer between 0 and 255, representing the blue component of the color.
Transparency (A) takes values ​​between 0 and 1, representing transparency.
You can search for rgba values ​​on Baidu Encyclopedia.
Similar to:

insert image description here

Color code comparison chart link:
https://www.sioe.cn/yingyong/yanse-rgb-16/

This is the end of this article about examples of how to set div background transparency. For more relevant div background transparency content, please search 123WORDPRESS.COM's previous articles or continue to browse the following related articles. I hope you will support 123WORDPRESS.COM in the future!

<<:  Importance of background color declaration when writing styles

>>:  Detailed steps for manually configuring the IP address in Linux

Recommend

Example code for implementing verification code login in SMS API in Node

1. Node server setup + database connection The op...

Three ways to draw a heart shape with CSS

Below, we introduce three ways to draw heart shap...

Mysql varchar type sum example operation

Some friends, when learning about databases, acci...

How to configure MGR single master and multiple slaves in MySQL 8.0.15

1. Introduction MySQL Group Replication (MGR for ...

A detailed introduction to deploying RabbitMQ environment with docker

Prerequisites: Docker is already installed 1. Fin...

Detailed explanation of the use of Arguments object in JavaScript

Table of contents Preface Basic Concepts of Argum...

Detailed examples of Docker-compose networks

Today I experimented with the network settings un...

Detailed tutorial on installing ElasticSearch 6.x in docker

First, pull the image (or just create a container...

The Complete Guide to Grid Layout in CSS

Grid is a two-dimensional grid layout system. Wit...

Solution to Chinese garbled characters when operating MySQL database in CMD

I searched on Baidu. . Some people say to use the...