三种CSS方式实现弹出窗口(popup window)

本文介绍了三种使用CSS实现弹出窗口(popup window)上下居中布局的方法:1) 使用display: flex; 2) 使用position: absolute + margin负值; 3) 使用position: absolute + transform: translate(-50%, -50%)。文章指出,这些方法同样适用于保持元素始终居中,并推荐使用display: flex;的方式,因为其简洁易懂。" 125465848,14643086,SECS/GEM软件开发与应用指南,"['SEMI标准', '设备通讯', '软件开发', 'SECS协议', '硬件接口']
摘要由CSDN通过智能技术生成

1. 使用display: flex;进行上下居中布局

在容器里面添加以下几行css语句

 display: flex; 
 justify-content: center; 
 align-items: center;

注意: 设为Flex布局以后,子元素的float、clear和vertical-align属性将失效。

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <style>
        body{
   
            margin: 0;
            padding: 0;
            height: 9999px; //模仿内容很长的页面
        }
        .popup__wrapper {
   
            position: fixed;
            top: 0;
            left: 0;
            right: 0;
            bottom: 0;
            background-color: rgba(0, 0, 0, 0.5);
            z-index: 999;
            display: flex;
            justify-content: center;
            align-items: center;
        }
        .popup {
   
            box-sizing: border-box;
            width: 670px;
            height: 300px;
            background: #fff;
            text-align: center;
            padding: 70px 10px 20px 10px;
            border-radius: 4px;
        }
        .popup__title{
   
            font-size: 30px;
            font-weight: 600;
            color: #004165;
            margin-bottom: 20px;
        }
        .popup__btnWrapper {
   
            width: 50%;
            margin: 0 auto;
            display: flex;
            justify-content: space-between;
        }
        .popup__text{
   
            font-size: 20px;
            margin-bottom: 50px;
        }
        button{
   
            width: 154px;
            cursor: pointer;
            border-radius: 4px<
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值