Home Web Front-end Front-end Q&A What is rgba in css3

What is rgba in css3

Mar 17, 2022 pm 05:19 PM
css3 rgba

rgba is a function that defines color in CSS3. The syntax is "rgba(R,G,B,A)", which represents red (R), green (G), blue (B) and transparency. (A) changes and superimposes each other to obtain various colors; the value range of parameters R, G, and B is "0~255", and the value range of A is "0~1".

What is rgba in css3

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

RGB is a color standard, which is a variety of colors obtained by the changes and superposition of red (R), green (G), and blue (B). RGBA is based on RGB and adds parameters to control alpha transparency.

Syntax:

rgba(R,G,B,A)
Copy after login

Parameters:

R: red value. Positive integer | Percent

G: Green value. Positive integer | Percent

 B: Blue value. Positive integer | Percent

 A: Transparency. Value range between 0 and 1

Value range:

 : Hue (hue). 0 (or 360) represents red, 120 represents green, and 240 represents blue. Of course, other values ​​​​can be used to determine other colors;

 : Saturation (saturation). The value is a value between 0% and 100%;

 : Lightness (brightness). The value is a value between 0% and 100%;

 : alpha (transparency). The value is between 0 and 1;

Simple explanation:

RGB color mode (also translated as "red, green and blue", less commonly used) is the industrial A color standard that obtains various colors by changing the three color channels of red (R), green (G), and blue (B) and superimposing them on each other. RGB represents The colors of the three channels of red, green and blue, this standard includes almost all colors that human vision can perceive, and is one of the most widely used color systems currently.

RGBA has additional parameters to control Alpha transparency based on RGB. For the above three parameters R, G, and B, the positive integer value range is: 0 - 255. The value range of the percentage value is: 0.0% - 100.0%. Values ​​outside the range are rounded to the nearest value limit. Not all browsers support using percentage values. The A parameter has a value between 0 and 1 and cannot be negative.

Browser compatibility:

What is rgba in css3

If Pang Tong says RGBA is for making transparent colors (transparent background color, transparent border color, transparent foreground color, etc.), Everyone can't help but think of opacity. It is usually used to make the background color in our CSS2, but if you want to use it to make the border color or the foreground color, then it can only stand on the side, and it is powerless.

Now let's take a look at a comparison example of RGBA and Opacity. HTML code:

<div class="example-opacity">
  <p>Opacity效果</p>
  <ul>
   <li class="opacity opacity1">100%</li>
   <li class="opacity opacity2">80%</li>
   <li class="opacity opacity3">60%</li>
   <li class="opacity opacity4">40%</li>
   <li class="opacity opacity5">20%</li>
   <li class="opacity opacity6">0</li>
  </ul>
  <p>CSS3的RGBA效果</p>
  <ul>
   <li class="rgba rgba1">1</li>
   <li class="rgba rgba2">0.8</li>
   <li class="rgba rgba3">0.6</li>
   <li class="rgba rgba4">0.4</li>
   <li class="rgba rgba5">0.2</li>
   <li class="rgba rgba6">0</li>
 </ul>
</div>
Copy after login

We apply relevant styles to the li in these two uls respectively. In li.opacity, I use Use Opacity in CSS2 and in li.rgba we use the new RGBA property of CSS3.

Opacity style

li.opacity{
  float: left;
  width: 50px;
  height: 50px;
}
li.opacity1 {
   background: rgb(255,255,0);
   opacity: 1;
   filter:alpha(opaity=100);
}
li.opacity2 {
  background: rgb(255,255,0);
  opacity: 0.8;
  filter:alpha(opaity=80);
}
li.opacity3 {
  background: rgb(255,255,0);
  opacity: 0.6;
  filter:alpha(opaity=60);
}
li.opacity4 {
  background: rgb(255,255,0);
  opacity: 0.4;
  filter:alpha(opaity=40);
}
li.opacity5 {
  background: rgb(255,255,0);
  opacity: 0.2;
  filter:alpha(opaity=20);
}
li.opacity6 {
  background: rgb(255,255,0);
  opacity: 0;
  filter:alpha(opaity=0);
}
Copy after login

RGBA sample:

li.rgba {
  float: left;
  width: 50px;
  height: 50px;
}
li.rgba1 {
  background: rgba(255,255,0,1);
}
li.rgba2 {
  background: rgba(255,255,0,0.8);
}
li.rgba3 {
  background: rgba(255,255,0,0.6);
}
li.rgba4 {
  background: rgba(255,255,0,0.4);
}
li.rgba5 {
  background: rgba(255,255,0,0.2);
}
li.rgba6 {
  background: rgba(255,255,0,0);
}
Copy after login

Let’s take a look at its effect:

What is rgba in css3

We have the effect It can be seen that the similarity between them is that the background color is exactly the same, but the difference is the problem that has always given everyone a headache, that is, the descendant elements of Opacity will have transparency along with it, so the words in our Opacity will have transparency value along with it. The drop is becoming increasingly unclear, whereas RGBA does not have such a problem.

(Learning video sharing: css video tutorial, web front-end)

The above is the detailed content of What is rgba in css3. For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

How to achieve wave effect with pure CSS3? (code example) How to achieve wave effect with pure CSS3? (code example) Jun 28, 2022 pm 01:39 PM

How to achieve wave effect with pure CSS3? This article will introduce to you how to use SVG and CSS animation to create wave effects. I hope it will be helpful to you!

Use CSS skillfully to realize various strange-shaped buttons (with code) Use CSS skillfully to realize various strange-shaped buttons (with code) Jul 19, 2022 am 11:28 AM

This article will show you how to use CSS to easily realize various weird-shaped buttons that appear frequently. I hope it will be helpful to you!

How to hide elements in css without taking up space How to hide elements in css without taking up space Jun 01, 2022 pm 07:15 PM

Two methods: 1. Using the display attribute, just add the "display:none;" style to the element. 2. Use the position and top attributes to set the absolute positioning of the element to hide the element. Just add the "position:absolute;top:-9999px;" style to the element.

How to implement lace borders in css3 How to implement lace borders in css3 Sep 16, 2022 pm 07:11 PM

In CSS, you can use the border-image attribute to achieve a lace border. The border-image attribute can use images to create borders, that is, add a background image to the border. You only need to specify the background image as a lace style; the syntax "border-image: url (image path) offsets the image border width inward. Whether outset is repeated;".

How to enlarge the image by clicking the mouse in css3 How to enlarge the image by clicking the mouse in css3 Apr 25, 2022 pm 04:52 PM

Implementation method: 1. Use the ":active" selector to select the state of the mouse click on the picture; 2. Use the transform attribute and scale() function to achieve the picture magnification effect, the syntax "img:active {transform: scale(x-axis magnification, y Axis magnification);}".

It turns out that text carousel and image carousel can also be realized using pure CSS! It turns out that text carousel and image carousel can also be realized using pure CSS! Jun 10, 2022 pm 01:00 PM

How to create text carousel and image carousel? The first thing everyone thinks of is whether to use js. In fact, text carousel and image carousel can also be realized using pure CSS. Let’s take a look at the implementation method. I hope it will be helpful to everyone!

How to set animation rotation speed in css3 How to set animation rotation speed in css3 Apr 28, 2022 pm 04:32 PM

In CSS3, you can use the "animation-timing-function" attribute to set the animation rotation speed. This attribute is used to specify how the animation will complete a cycle and set the speed curve of the animation. The syntax is "element {animation-timing-function: speed attribute value;}".

Does css3 animation effect have deformation? Does css3 animation effect have deformation? Apr 28, 2022 pm 02:20 PM

The animation effect in css3 has deformation; you can use "animation: animation attribute @keyframes ..{..{transform: transformation attribute}}" to achieve deformation animation effect. The animation attribute is used to set the animation style, and the transform attribute is used to set the deformation style. .

See all articles