【发布时间】:2016-05-12 13:02:46
【问题描述】:
对于具有多行标题的 div,文本与中心完美对齐。然而,对于单行标题,情况并非如此(即使 text-align 设置为 center)。文本将自身与父跨度的左边框对齐。看起来绝对是微不足道的,但还没有成功。
span.text-content {
background: rgba(255,255,255,0.5);
color: white;
cursor: pointer;
display: inline-block;
height: 100%;
left: 0;
position: absolute;
top: 0;
width: 100%;
opacity:0;
}
span.text-content span {
display: table-cell;
text-align: center;
vertical-align: middle;
color: #000;
font-weight: 900;
text-transform: uppercase;
position:absolute;
top: 45%;
}
<span class="text-content"><span>Post Title</span></span>
【问题讨论】:
-
你想水平居中对齐吗?
-
首先如果你使用 display: table-cell 父级必须有 display: table
标签: html css text-align