Sam*_*row 5 html css pseudo-element
我创建了一个伪元素来放置一个无序列表,css 如下:
ul.pricing-column {
width: 200px;
height: 400px;
background: red;
position: relative;
margin: 50px;
}
.pricing-column.featured::after {
content: "Most Popular";
background: #52BDE6 none repeat scroll 0% 0%;
color: #FFF;
width: 80px;
border-radius: 100%;
position: absolute;
top: -10px;
left: -10px;
z-index: 1000;
text-transform: uppercase;
font-weight: 700;
font-size: 0.9em;
line-height: 0.9em;
padding: 10px;
display: inline-block;
height: 80px;
text-align: center;
}Run Code Online (Sandbox Code Playgroud)
<ul class="pricing-column featured">
</ul>Run Code Online (Sandbox Code Playgroud)
但是,有了这个,伪元素内的文本位于我元素的顶部 - 有没有办法让它垂直居中?
这是一个小提琴
小智 4
最简单的方法?添加填充顶部。稍微困难一点但更好的方法是使用 Flexbox。
这些属性将做
display: -webkit-flex;
display: flex;
-webkit-flex-direction: column;
flex-direction: column;
-webkit-align-items: center;
align-items: center;
-webkit-justify-content: center;
justify-content: center;
text-align: center;
Run Code Online (Sandbox Code Playgroud)
http://jsfiddle.net/6dqxt2r3/4/