如何垂直居中文本Test Text
?见here
我希望文本和边框底部之间的距离等于文本和边框顶部之间的距离。 `
答案 0 :(得分:4)
对于单行文字,请使用等于line-height
的{{1}}(或向上舍入到偶数)。
height

#a {
display: inline-block;
padding-right: 20px;
padding-left: 15px;
font-family: 'Roboto';
font-size: 12px;
font-weight: bold;
font-stretch: condensed;
COLOR: white;
border-left: 10px solid transparent;
border-bottom: 25px solid;
border-bottom-color: #FF3300;
height: 0;
line-height: 26px;
top: 50%;
}

答案 1 :(得分:2)
使用line-height: 25px
(仅适用于单行文字)。
#a {
display: inline-block;
padding-right: 20px;
padding-left: 15px;
font-family: 'Roboto';
font-size: 12px;
line-height: 25px;
font-weight: bold;
font-stretch: condensed;
COLOR: white;
border-left: 10px solid transparent;
border-bottom: 25px solid;
border-bottom-color: #FF3300;
height: 0;
top: 50%;
}
<span id="a">TEST TEXT</span>
答案 2 :(得分:0)
对左侧部分使用:before
伪元素,行高不适用于bottom-border
。我更新了你的小提琴:
答案 3 :(得分:0)
.area {
width: 300px;
height: 300px;
position: relative;
}
.bubble {
position: absolute;
left: 93px;
top: 21px;
width: 135px;
height: 84px;
display: table;
}
.bubble p {
display: table-cell;
vertical-align: middle;
text-align: center;
&#13;
<div class="area">
<div class="bubble">
<p>To look best, text should really be centered inside this bubble both vertically and horizontally.</p>
</div>
</div>
&#13;