通过 justify-content align-items 实现居中
article {
display: flex;
border: solid 5px silver;
border-color: #8A2BE2;
width: 450px;
height: 280px;
background: red; /* */
flex-direction: row;
justify-content: center;
align-items: center;
}
代码:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" content="width=device-width, initial-scale=1.0">
<title></title>
<style type="text/css">
* {
padding: 0px;
margin: 0px;
}
body {
padding-left: 0px;
padding-top: 15px;
}
article {
display: flex;
border: solid 5px silver;
border-color: #8A2BE2;
width: 450px;
height: 280px;
background: red; /* */
flex-direction: row;
justify-content: center;
align-items: center;
}
article * {
width: 100px;
height: 100px;
}
.first {
background: #87CEEB;
}
.second {
background: #FFA07A;
}
.third {
background: lightpink;
}
.fourth {
background: lightgreen;
}
</style>
</head>
<body>
<article>
<div class="first">第一</div>
<div class="second">第二</div>
<div class="third">第三</div>
<div class="fourth">第四</div>
</article>
</body>
</html>
网友评论