


In web page layout, sometimes for the overall beauty of the web page, it may be necessary to set some parts of the web page to have a transparent background color. So how to set the background color to be transparent? This article will introduce to you how to set the background color to be transparent using CSS.
There are two ways to set the background color transparency in css: One is to set it through rgba, and the other is to set it through backgroud and opacity.
Let’s take a look at the specific examples of these two methods in css to achieve transparent background color
1. Set the background color to be transparent through backgroud and opacity
The attribute value in the background attribute is relatively simple, so I won’t go into details here. You can refer to the css learning manual to learn about it. Let’s take a brief look at the opacity attribute here.
opacity attributeThe "opacity" of the parameter is represented by a number, ranging from 0.0 to 1.0. Fully transparent is 0.0, and fully opaque is 1.0, in other words, a higher number means the element is more opaque. In addition to "opacity" parameters, there is also inherit Inherits the properties of the parent layer, but browser support is poor and is not recommended.
After reading the introduction of the two attributes, let's look at a specific example of setting the background color transparency through backgroud and opacity.
The code is as follows:
<div class="box"></div>
.box{ width:300px; height:200px; margin:0 auto; border:1px solid #ccc; background:red; opacity:0.2; }
The background color is transparent The effect is as follows:
Instructions: Set the background color transparency through backgroud and opacity. If there is text on the background, the text will also become transparent, just like the effect below
So it depends on the situation to use this method to set the background color to be transparent.
Recommended related articles:
1. How to achieve background transparency in css in web design? (Example)
2.Two methods to achieve translucent background color in css
3.How to set transparency in css? Two methods of setting transparency (code examples)
Related video tutorials:
1.CSS Video Tutorial-Jade Girl Heart Sutra Edition
2. Set the background color to be transparent through rgba method
The so-called RGBA color is the three primary colors of RGB plus ALPHA. Provides transparency properties while adding color to the background.
Usage: background:rgba(R,G, B, A);
Let’s look at a specific example of setting the background color transparency through rgba:
<div class="title_div">背景颜色透明</div>
.title_div{ width: 200px; height: 200px; line-height: 30px; text-align: center; margin:0 auto; background-color:rgba(220,38,38,0.2); }
The effect of setting background color transparency in rgba method is as follows:
Description: By setting background color transparency in rgba method, you can set the background color to be transparent and the text to be opaque, but the compatibility of this method is limited. No, it is not compatible with IE browser
This article ends here. For more knowledge about css, you can refer to the php Chinese websitecss video tutorial, css3 video tutorial, css learning manual and css3 learning manual for further study.
The above is the detailed content of How to set the background color to be transparent in css? Introduction to two methods of setting background color transparency in css. For more information, please follow other related articles on the PHP Chinese website!

In a perfect world, our projects would have unlimited resources and time. Our teams would begin coding with well thought out and highly refined UX designs.

Oh, the Many Ways to Make Triangular Breadcrumb Ribbons

SVG has its own set of elements, attributes and properties to the extent that inline SVG code can get long and complex. By leveraging CSS and some of the forthcoming features of the SVG 2 specification, we can reduce that code for cleaner markup.

You might not know this, but JavaScript has stealthily accumulated quite a number of observers in recent times, and Intersection Observer is a part of that

We may not need to throw out all CSS animations. Remember, it’s prefers-reduced-motion, not prefers-no-motion.

PWA (Progressive Web Apps) have been with us for some time now. Yet, each time I try explaining it to clients, the same question pops up: "Will my users be

It's extremely surprising to me that HTML has never had any way to include other HTML files within it. Nor does there seem to be anything on the horizon that

There are a lot of different ways to use SVG. Depending on which way, the tactic for recoloring that SVG in different states or conditions — :hover,


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

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

Hot Article

Hot Tools

MantisBT
Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

Dreamweaver Mac version
Visual web development tools

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

PhpStorm Mac version
The latest (2018.2.1) professional PHP integrated development tool

WebStorm Mac version
Useful JavaScript development tools