How to set transparency in css - transparent block. Creating a transparent background in HTML and CSS (opacity and RGBA effects) The element is transparent

In this lesson we will look at the following CSS properties - opacity and RGBA. The Opacity property is responsible only for the transparency of elements, and the RGBA function is responsible for color and transparency if you specify an alpha channel transparency value.

CSS transparency Opacity

The digital value for opacity is set in the range from 0.0 to 1.0, where zero is complete transparency, and one, on the contrary, is absolute opacity. For example, in order to see 50% transparency, you need to set the value to 0.5. It must be kept in mind that opacity applies to everything child elements parent. This means that text on a translucent background will also be translucent. And this is a very significant drawback; the text does not stand out so well.




Transparency via CSS Opacity



The screenshot clearly shows that the black text has become as translucent as the blue background.

Div(
background: url(images/yourimage.jpg); /* Background image */
width: 750px;
height: 100px;
margin: auto;
}
.blue (
background: #027av4; /* Color translucent background */
opacity: 0.3; /* Background translucency value */
height: 70px;
}
h1 (
padding: 6px;
font-family: Arial Black;
font-weight: bolder;
font-size: 50px;
}

CSS transparency in RGBA format

The RGBA color format is a more modern alternative to the opacity property. R (red), G (green), B (blue) – means: red, green, blue. The last letter A stands for the alpha channel, which sets the transparency. RGBA, unlike Opacity, does not affect child elements.

Now let's look at our example using RGBA. Let's replace these lines in the styles.

Background: ##027av4; /* Background color */
opacity: 0.3; /* background translucency value */

to the next one line

Background: rgba(2, 127, 212, 0.3);

As you can see, the transparency value of 0.3 is the same for both methods.

Result of the RGBA example:

The second screenshot looks much better than the first.

By playing with the translucency of the background of blocks, you can achieve interesting effects on your website. It is important that these translucent blocks go on top of a colorful design, such as a photograph. Only in this case the effect will be noticeable. This technique has been used in design for a long time, even before the advent of any CSS3, it was implemented purely in graphics programs.

If the customer requires that the layout look good in older versions of the browser Internet Explorer, then add the filter property and do not forget to comment it out so that the validity of the code does not suffer.



.blue (
background: rgba(0, 120, 201, 0.3);
filter: alpha(Opacity=30); /* Transparency in IE */
}

Conclusion

The RGBA format is supported by all modern browsers, with the exception of Internet Explorer. It is also very important that RGBA is flexible; it acts only on a specific given element, without affecting its children. It is clear that this is more convenient for the layout designer. My choice is definitely in favor of the RGBA format for achieving transparency in CSS.

For better consolidation of the material and greater clarity, I suggest you go through.

orem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry"s standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting It was popularized in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.
It is a long established fact that a reader will be distracted by the readable content of a page when looking at its layout. The point of using Lorem Ipsum is that it has a more-or-less normal distribution of letters, as opposed to using "Content here, content here", making it look like readable English. Many desktop publishing packages and web page editors now use Lorem Ipsum as their default model text, and a search for "lorem ipsum" will uncover many web sites still in their infancy. Various versions have evolved over the years, sometimes by accident, sometimes on purpose (injected humor and the like).

So, today we will talk about transparency in html pages. You've probably come across transparent pop-up blocks, be it a photo gallery or login forms on some popular website. There are many uses for transparency in HTML. So how is it made and where can it be used?

Well, first of all, let’s understand that our document has not only one monitor plane - it is generally 3-dimensional, I mentioned this in the article “Z-index”. Accordingly, even a completely transparent layer, if it were at the top of the display stack, would block access to other elements. This is one of the main uses of transparent blocks. Although a shading effect is usually used, a completely transparent layer will work exactly the same. So, for example, a lot of popular photo galleries work; a shaded layer is organized in which photos and controls for them are displayed. The rest of the page is “covered” with a (semi) transparent layer, blocking access to all other elements on the page. Those. You will not be able to leave the page by clicking any link on it - all the text is covered with a background. To return to the body of the site, they usually provide controls for closing the gallery, login form, etc. Control showing/hiding transparent blocks using javascript. Unfortunately, there is no alternative to it. Without using it, the user will either not see the transparent block at all, or will not be able to close it without leaving the current page. I note that visibility or display properties are used for this.

So how is transparency actually organized in html? Setting element transparency is generally not included in the CSS specification, so you have to use several instructions at once to create it. Some browsers (ie) will work with one option, others with another. Ie uses the built-in filter functionality, other browsers use the "opacity" property, which is set in the range from 0 (completely transparent object) to 1 (completely opaque). For example, in the case of 30% transparency, you should write "opacity:0.30; filter:alpha(opacity=30); ". The properties, as can be seen from the example, are similar - only in the first case a number from 0 to 1 is used, in the second a percentage notation is used. An example of such a block: