以flexbox为中心的CSS文本
这个问题在这里已经有了答案:
要将.item儿童放在.parent中心,请使用以下代码:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
<style>
.parent {
display: flex;
align-items: center;
justify-content: center;
height: 200px;
}
.item {
align-content: center;
}
</style>
</head>
<body>
<div class="example">
<h2> Display: flex </h2>
<div class="example-content">
<div class="parent">
<div class="item">If you wanna</div>
<div class="item">Then you gotta</div>
<div class="item">Go findz it</div>
</div>
</div>
</div>
</body>
</html>
你需要添加align-items:center
和一个新的display:flex
到孩子
body {
margin: 0
}
.parent {
display: flex;
flex-direction: row-reverse;
justify-content: space-around;
flex-wrap: wrap;
border: black solid;
color: white
}
.item {
display: flex;
align-items: center;
height: 200px;
background: lightgreen;
}
<div class="example">
<h2> Display: flex </h2>
<div class="example-content">
<div class="parent">
<div class="item">If you wanna</div>
<div class="item">Then you gotta</div>
<div class="item">Go findz it</div>
</div>
</div>
</div>
链接地址: http://www.djcxy.com/p/76001.html