【发布时间】:2015-05-04 21:58:36
【问题描述】:
我想使用after 创建一个带有文本附加到元素的带边框元素。文本需要在边框内居中,看起来像一个按钮。目前文本位于底部。我尝试使用flex webkit,但它仅将文本水平居中。
#wrapper {
background-image: none;
border:1px solid #021a40 !important;
left: 0px !important;
top: 115px !important;
&:after {
content: 'Some Text';
display: -webkit-flex;
display: flex;
-webkit-align-items: center;
align-items: center;
-webkit-justify-content: center;
justify-content: center;
}
如果我在文本所在的after 中添加填充,它会扩展边框...并且不会将文本放在边框的中心:
padding-bottom: 15px;
如何让文本在边框中间居中?
另外,如果我尝试使用margin-left/right: auto 居中,它会将文本放在左下角:
&:after {
content: 'Some Text';
display: block;
margin-left: auto;
margin-right: auto;
}
【问题讨论】:
-
父元素是固定高度吗?字符串总是固定长度吗?