文本超出部分显示省略号
单行
overflow: hidden; text-overflow:ellipsis; white-space: nowrap;
多行
display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 3; // 最多显示几行 overflow: hidden;
水平垂直居中的方式
flex
// 父容器 display: flex; justify-content: center; align-items: center;
position
// 父容器 position: relative; // 子容器 position:absolute; margin:auto; top:0; bottom:0; left:0; right:0;
position+transform
// 父容器 position: relative; // 子容器 position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%);
table-cell
<div class="box"> <div class="content"> <div class="inner"></div> </div> </div> html, body { height: 100%; width: 100%; margin: 0; } .box { display: table; height: 100%; width: 100%; } .content { display: table-cell; vertical-align: middle; text-align: center; } .inner { background-color: #000; display: inline-block; width: 200px; height: 200px; }
利用伪元素画三角
.info-tab { position: relative; } .info-tab::after { content: ''; border: 4px solid transparent; border-top-color: #2c8ac2; position: absolute; top: 0; }