CSS to achieve pop-up window up and down center left and right and transparent background lock window effect

CSS to achieve pop-up window up and down center left and right and transparent background lock window effect

There is a simple CSS method to realize the pop-up box after clicking, centering it up, down, left, and right, and adding a gray transparent mask to lock the window and clear the scroll bar

insert image description here

HTML code

<div class="box">
	<div class="boxs">
	    <!-- White pop-up window-->
	</div>
</div>

CSS Code

html, body {
     width: 100%;
     height: 100%;
 }
 .box {
     display: none;
     width: 100%;
     height: 100%;
     position: fixed;
     left:0;
     top:0;
     background-color:rgba(0,0,0,0.5);
 }
 .boxs {
     width: 400px;
     height: 300px;
     background: #fff;
     box-shadow: 1px 7px 18px 0px rgba(84, 115, 128, 0.11);
     border-radius: 4px;
     cursor: pointer;
     position: absolute;
     left: 50%;
     top: 50%;
     margin-top: -150px;
     margin-left: -200px;
 }

Using position:fixed to fix transparent background elements can effectively lock the window to prevent the scroll bar from scrolling, and positioning inside the parent element can be used to center the child element up, down, left, and right. As for the pop-up operation, you only need to link the click event with the display attribute of the outer div, which is none and block.

This is the end of this article about how to use CSS to center the pop-up window with a transparent background and lock the window. For more information about how to center the pop-up window with a transparent background and lock the window, please search previous articles on 123WORDPRESS.COM or continue to browse the related articles below. I hope you will support 123WORDPRESS.COM in the future!

<<:  Tutorial on building nextcloud personal network disk with Docker

>>:  Detailed explanation of various HTTP return status codes

Recommend

Summary of seven sorting algorithms implemented in JavaScript (recommended!)

Table of contents Preface Bubble Sort Basic Algor...

Docker installation rocketMQ tutorial (most detailed)

RocketMQ is a distributed, queue-based messaging ...

Nginx monitoring issues under Linux

nginx installation Ensure that the virtual machin...

Chinese website user experience rankings

<br />User experience is increasingly valued...

CSS3 speeds up and delays transitions

1. Use the speed control function to control the ...

Analysis of several situations where MySQL index fails

1. Best left prefix principle - If multiple colum...

Solution to define the minimum height of span has no effect

The span tag is often used when making HTML web pa...

Docker image import and export code examples

Import and export of Docker images This article i...

Detailed tutorial on installing MySQL 5.7.20 on RedHat 6.5/CentOS 6.5

Download the rpm installation package MySQL offic...

MySql8 WITH RECURSIVE recursive query parent-child collection method

background When developing a feature similar to c...

Pagination Examples and Good Practices

<br />Structure and hierarchy reduce complex...

Problems and pitfalls of installing Mysql5.7.23 in Win10 environment

I read many tutorials, but found that I could nev...