Detailed explanation of css opacity property
This chapter brings you a detailed explanation of css opacity opacity, so that everyone can understand what the opacity attribute is and some characteristics of the opacity attribute. It has certain reference value. Friends in need can refer to it. I hope it will be helpful to you.
1. Opacity attribute
1. Opacity
It is customary to say "transparency", In fact, it should be called "opacity". Opacity means: opaque, while the default value of the background color: transparent means "transparent". So opacity is used to set the opacity. The value ranges from [0.0~1.0], which means from completely transparent to completely opaque. 0.0 is the same as transparent. It cannot be seen but it exists.
Default value: 1, completely opaque.
Inherited: Inherited by default. So when you set opacity to the parent element, all child elements will also inherit the opacity attribute.
<style> div{ background-color: red; } .opacity{ opacity: 0.5; } </style> --------------------------- <div> 文本和背景色都受到不透明度级别的影响。 </div> <br/> <div class="opacity"> 文本和背景色都受到不透明度级别的影响。 </div>
Rendering:
#All browsers support the opacity attribute, and IE8 and earlier versions support the alternative filter attribute.
filter:alpha(opacity=number), number value is [0~100], 0 is completely transparent, 100 is opaque.
So for compatibility, it can be written as:
.opacity{ opacity: 0.5; filter:alpha(opacity=50); }
2. Set opacity for child elements
The parent element sets opacity, and the child elements also set opacity. The opacity set by the child element does not work under IE. Under ff and Chrome, the final opacity of the child element = parent element opacity * child element opacity.
This can explain why after the parent element sets the opacity, the child element sets the opacity to 1 [that is, completely opaque] but it does not take effect.
Example:
<!DOCTYPE html> <html> <meta charset="utf-8"> <head> <title>透明度by starof</title> <style> div{ background-color: red; } .opacity{ opacity: 0.5; } .sonOpacity{ opacity: 0.3; } </style> <body> <div> <p>不设置opacity效果<p> </div> <div class="opacity"> <p>父元素(div)设置opacity:0.5效果</p> </div> <div class="opacity"> <p class="sonOpacity">父元素(div)设置opacity:0.5,同时子元素(p)设置opacity:0.3效果</p> </div> </body> </html>
Rendering:
##3. Effect display
1) Semi-transparent background effect can produce the following effects:<!DOCTYPE html> <html> <head> <title>b.html</title> <meta charset="UTF-8"> <style> .background{ width: 400px; height: 250px; margin:15px; background:url(img/wl.jpg) no-repeat; border: 1px solid red; } .opacity{ width: 350px; height: 204px; margin:20px; padding:0; background-color: #ffffff; border: 1px solid black; /* for IE */ filter:alpha(opacity=60); /* CSS3 standard */ opacity:0.6; } P{ margin: 30px 40px; line-height:1.5; } </style> </head> <body> <div class="background"> <div class="opacity"> <p>一段文字一段文字一段文字一段文字一段文字一段文字一段文字一段文字一段文字一段文字一段文字一段文字一段文字一段文字一段文字一段文字一段文字一段文字一段文字一段文字</p> </div> </div> </body> </html>
<!DOCTYPE html> <html> <meta charset="utf-8"> <head> <title>透明度by starof</title> <style> .opacity{ opacity: 0.5; } .sonOpacity{ opacity: 0.5; } .sonOpacity2{ opacity: 0.25; } </style> <body> <div> <p>不设置opacity效果<p> </div> <div class="opacity"> <p>父元素(div)设置opacity:0.5效果</p> </div> <div class="opacity"> <p class="sonOpacity">父元素(div)设置opacity:0.5,同时子元素(p)设置opacity:0.5效果</p> </div> <div> <p class="sonOpacity2">父元素(div)不设置opacity,子元素(p)设置opacity:0.25效果,和上面的文字透明度一样</p> </div> </body> </html>
##2. Comparison of opacity and rgba modes Syntax:
rgba(r,g,b,a);
[R:red,G:green,B:blue,A:alpha]
The first three parameters are rgb values, the value is [0~255] , the last parameter represents transparency, value [0~1].
background-color: rgba(255,0,0,0.5);
Look at an example of comparing opacity and rgba:
<style type="text/css"> div{ display: inline-block; width: 200px; height: 100px; text-align: center; font-size: 20px; } .opacity{ background-color: rgb(255,0,0); opacity: 0.5; } .rgba{ background-color: rgba(255,0,0,0.5); } </style> ---------------------------------------------- <body > <div class="opacity"> <p>opacity效果</p> </div> <div class="rgba"> <p>transparent效果</p> </div> </body>
Rendering:
The above is the detailed content of Detailed explanation of css opacity property. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



Using Bootstrap in Vue.js is divided into five steps: Install Bootstrap. Import Bootstrap in main.js. Use the Bootstrap component directly in the template. Optional: Custom style. Optional: Use plug-ins.

HTML defines the web structure, CSS is responsible for style and layout, and JavaScript gives dynamic interaction. The three perform their duties in web development and jointly build a colorful website.

There are two ways to create a Bootstrap split line: using the tag, which creates a horizontal split line. Use the CSS border property to create custom style split lines.

WebdevelopmentreliesonHTML,CSS,andJavaScript:1)HTMLstructurescontent,2)CSSstylesit,and3)JavaScriptaddsinteractivity,formingthebasisofmodernwebexperiences.

To adjust the size of elements in Bootstrap, you can use the dimension class, which includes: adjusting width: .col-, .w-, .mw-adjust height: .h-, .min-h-, .max-h-

To set up the Bootstrap framework, you need to follow these steps: 1. Reference the Bootstrap file via CDN; 2. Download and host the file on your own server; 3. Include the Bootstrap file in HTML; 4. Compile Sass/Less as needed; 5. Import a custom file (optional). Once setup is complete, you can use Bootstrap's grid systems, components, and styles to create responsive websites and applications.

There are several ways to insert images in Bootstrap: insert images directly, using the HTML img tag. With the Bootstrap image component, you can provide responsive images and more styles. Set the image size, use the img-fluid class to make the image adaptable. Set the border, using the img-bordered class. Set the rounded corners and use the img-rounded class. Set the shadow, use the shadow class. Resize and position the image, using CSS style. Using the background image, use the background-image CSS property.

How to use the Bootstrap button? Introduce Bootstrap CSS to create button elements and add Bootstrap button class to add button text
