目录
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<