Example of how to achieve semi-transparent background image and opaque content in CSS3

Example of how to achieve semi-transparent background image and opaque content in CSS3

I encountered this problem when I was making the login page for my previous blog. I suddenly wanted to use the effect of a transparent background image and opaque content. Here I will talk about my two ideas.

Effect display:

Content is semi-transparent

insert image description here

Opaque content

insert image description here

The most common approach is to set the opacity of the element. This setting results in both the content and the background being semi-transparent, which seriously affects the visual effect and does not achieve the above effect.

Method 1: Set background-color:rgba(). This method can only set the transparency of the background color.

If the background is a picture, the above method will not apply. Here are two methods:

The first one is to use the pseudo-element :: before. We do this by adding a background to the pseudo-element and setting the background transparency of the pseudo-element.

.login_box::before{
            content:"";
           
            background-image:url(images/one.jpg);
            opacity:0.5; //Transparency setting z-index:-1;
            background-size:500px 300px;
            width:500px; 
            height:300px;
            position:absolute;
            //Be sure to set position:absolute so that you can set the z-index so that the background is in the next layer of the content top:0px;
            left:0px;
            border-radius:40px;
        }
         .login_box{
            position:fixed;
            left:50%;
            top:200px;
            width:500px;
            height:300px;
            margin-left:-250px;
            border-radius:40px;
            box-shadow: 10px 10px 5px #888;
            border:1px solid #666;
 
            text-align:center;
        }

The method is similar to pseudo-elements. We can set different divs, place the content in the divs inside, set the background of the parent div, and then set the transparency. The layout is as follows:

<div class="bg">
    <div class="content">
    Contents
</div>

This can also achieve the same effect

This is the end of this article about the example of how to achieve semi-transparent background images with opaque content in CSS3. For more related CSS3 background images with semi-transparent content and opaque content, please search 123WORDPRESS.COM’s previous articles or continue to browse the related articles below. I hope that everyone will support 123WORDPRESS.COM in the future!

<<:  uni-app WeChat applet authorization login implementation steps

>>:  How to set the height of the autosize textarea in Element UI

Recommend

Detailed explanation of basic interaction of javascript

Table of contents 1. How to obtain elements Get i...

Detailed explanation of basic operation commands for Linux network settings

Table of contents View network configuration View...

How to maintain MySQL indexes and data tables

Table of contents Find and fix table conflicts Up...

Example of writing mobile H5 to invoke APP (IOS, Android)

iOS 1. URL scheme This solution is basically for ...

Basic installation process of mysql5.7.19 under winx64 (details)

1. Download https://dev.mysql.com/downloads/mysql...

Use href in html to pop up a file download dialog box when clicking a link

I learned a new trick today. I didn’t know it befo...

Implementation steps for setting up the React+Ant Design development environment

Basics 1. Use scaffolding to create a project and...

Vue implements left and right sliding effect example code

Preface The effect problems used in personal actu...

SQL interview question: Find the sum of time differences (ignore duplicates)

When I was interviewing for a BI position at a ce...

How to set the page you are viewing to not allow Baidu to save its snapshot

Today, when I searched for a page on Baidu, becaus...

Detailed explanation of CSS elastic box flex-grow, flex-shrink, flex-basis

The functions of the three attributes flex-grow, ...

IDEA configuration process of Docker

IDEA is the most commonly used development tool f...

Html Select uses the selected attribute to set the default selection

Adding the attribute selected = "selected&quo...

What is BFC? How to clear floats using CSS pseudo elements

BFC Concept: The block formatting context is an i...

How to recover accidentally deleted messages files in Linux

If there are files that are being used by a proce...