When laying out the page, in order to give users a different visual effect, you need to set the background color of the div to a semi-transparent state. Do you know how to set it? Next, let’s talk about how to make the background color of a div semi-transparent in two ways, as well as the advantages and disadvantages of the two methods. Friends who are interested can come and have a look, I hope it will be helpful to you. First, we use the familiar CSS property opacity to change the background color of the div. describe: The background color of the large div outside is yellow, and the background color of the small div inside is red. Now we need to set the background color of the large div to be semi-transparent. We set the opacity attribute value to 0.5. The code is as follows: HTML part: <div class="aa"> <divclass="bb"I am the content</div> </div> CSS part: .aa{ width: 250px; height: 250px; background: yellow; opacity: 0.5; } .bb{ width: 150px; height: 150px; background: red; } Effect picture: As shown in the figure, the background color does become translucent, but the background and text of the small div inside become translucent. This may not be the effect we want, so we generally do not use this method. Of course, if you want everything in the div to be transparent during page layout, use opacity. The code is as follows: .aa{ width: 250px; height: 250px; background-color: rgba(255,255,0,0.5); } .bb{ width: 150px; height: 150px; background: red; } Effect picture: It is clear from the picture that after the transparency of the large div is changed, it has no effect on the background and text inside. So we usually use background-color:rgba(0,0,0,0~1) to set the background color transparent. The above introduces two ways to change the transparency of the div background color. They each have their own advantages and disadvantages. The specific method to be used should be based on the needs. Beginners can practice more to deepen their understanding. I hope it will be helpful to you. |
<<: HTML implements read-only text box and cannot modify the content
>>: A designer complains about Hammer's official website again
Table of contents What is Proxy Mode? Introducing...
There are currently three ways to display the cen...
Table of contents 1. What is a prototype? 2. Prot...
Most of the commands below need to be entered in ...
1. Space rules Whitespace within HTML code is usu...
1. After creating the web project, you now need t...
Optimizing and refining information is always the ...
Programmers must deal with MySQL a lot, and it ca...
As more and more developers use SASS, we need to ...
count(*) accomplish 1. MyISAM: Stores the total n...
Preface Note: The test database version is MySQL ...
This article uses an example to illustrate the us...
When implementing this function, the method I bor...
Pitfalls encountered I spent the whole afternoon ...
As the most commonly used layout element, DIV play...