1. 程式人生 > 其它 >flex下 超出兩行顯示... 並垂直居中

flex下 超出兩行顯示... 並垂直居中

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Document</title>
</head>
<style>
* {
margin: 0px;
padding: 0px;
}
ul {
width: 600px;
height: 200px;
background-color: pink;

display: flex;
flex-wrap: wrap;
align-items: center;
justify-content: space-around;
}
li {
list-style: none;
height: 60px;
line-height: 20px;
padding: 10px;
width: 180px;
box-sizing: border-box;
/* border: 2px blue solid; */
background-color: #dfdfdf;
border-radius: 30px;
text-align: center;
display: flex;
align-items: center;
}

.box {
display: table;
width: 160px;
/* border: 2px blue dashed; */
}
.wrap {
letter-spacing: 0;
overflow: hidden;
display: -webkit-box;
text-overflow: ellipsis;
-webkit-line-clamp: 2;
-webkit-box-orient: vertical;
font-size:12px;
}
</style>
<body>
<ul>
<li>
<div class="box">
<div class="wrap">我是文字隨便幾行我可以自動折行,水平居中多了不顯示多了不顯示多了不顯示</div>
</div>
</li>
<li>
<div class="box">
<div class="wrap">水平居中</div>
</div>
</li>
<li>
<div class="box">
<div class="wrap">我是文字隨便幾行我可以自動折行,水平居中</div>
</div>
</li>
<li>
<div class="box">
<div class="wrap">我是文字隨便幾行我可以自動折行,水平居中</div>
</div>
</li>
<li>
<div class="box">
<div class="wrap">我是文字隨便幾行我可以自動折行,水平居中</div>
</div>
</li>
<li>
<div class="box">
<div class="wrap">我是文字隨便幾行我可以自動折行,水平居中</div>
</div>
</li>
<li>
<div class="box">
<div class="wrap">我是文字隨便幾行我可以自動折行,水平居中</div>
</div>
</li>
<li>
<div class="box">
<div class="wrap">我是文字隨便幾行我可以自動折行,水平居中</div>
</div>
</li>
<li>
<div class="box">
<div class="wrap">我是文字隨便幾行我可以自動折行,水平居中</div>
</div>
</li>
</ul>
</body>
</html>


轉自:https://blog.csdn.net/billycoder/article/details/122640705