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

Problems and solutions encountered when connecting node to mysql database

I installed a new version of MySQL (8.0.21) today...

MYSQL stored procedures, that is, a summary of common logical knowledge points

Mysql stored procedure 1. Create stored procedure...

JavaScript anti-shake and throttling detailed explanation

Table of contents Debounce Throttle Summarize Deb...

Example tutorial on using the sum function in MySQL

Introduction Today I will share the use of the su...

Markup Language - Image Replacement

Click here to return to the 123WORDPRESS.COM HTML ...

Webservice remote debugging and timeout operation principle analysis

WebService Remote Debugging In .NET, the remote d...

Analysis of Linux boot system methods

This article describes how to boot the Linux syst...

One minute to experience the smoothness of html+vue+element-ui

Technology Fan html web page, you must know vue f...

Display ellipsis effect when table cell content exceeds (implementation code)

illustrate In front-end development, you often en...

Determine whether MySQL update will lock the table through examples

Two cases: 1. With index 2. Without index Prerequ...

Three ways to refresh iframe

Copy code The code is as follows: <iframe src=...

Detailed explanation of :key in VUE v-for

When key is not added to the v-for tag. <!DOCT...