<!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<link rel="stylesheet" href="./web.css">
</head>
<body>
<div id="first">
This is a DIV Container
</div>
<div id="second">
DIVs are a powerful way to modularize presentation
</div>
</body>
</html>
在html文件同级新建文本,命名为web.css,一下是css外部样式:(若是整体居中就把注释去掉,不用就删掉)
body,html{
padding:0;
margin:0;
width:100vw;
height:100vh;
}
body{
/* display:flex;
flex-direction: column;
justify-content: center;
align-items: center; */
}
div{
width:200px;
height: 200px;
margin:5px;
border: 3px dashed green;
display:flex;
justify-content: center;
align-items: center;
}
div:nth-child(2){
position: relative;
top:-30px;
}