[英]Why won't my text center here?
我有以下CSS:
.me-header {
display: inline-block;
position: relative;
top: 50px;
left: 10px;
}
.me-header a {
color: #333;
font: 10px "Lucida Grande", Helvetica, sans-serif;
text-decoration: none
}
.resume-header {
display: inline-block;
position: relative;
top: 50px;
left: 100px;
}
.resume-header a {
color: #333;
font: 10px "Lucida Grande", Helvetica, sans-serif;
text-align: center;
text-decoration: none
}
.center-text {
text-align: center;
}
以及以下HTML:
<div class="me-header">
<a href="#"><img src="media/me-icon.png" alt="Picture of Christian Selig"><br> <span class="center-text">Contact Me</span></a>
</div>
<div class="resume-header">
<a href="resume.pdf"><img src="media/resume-icon.png" alt="Resume icon" title="Click to download resume (PDF)"><br> <span class="center-text">Resume (PDF)</span></a>
</div>
但是我的文字仍然左对齐。 为什么?
a
和span
都是内联元素-因此它们的宽度仅与其内容相同。 因此,当您将文本居中时,它将在inline元素内居中,但是inline元素显示在左侧。
如果设置text-align: center;
在父块元素上它将起作用。
如果要使整个块居中,请使用自动边距。
你可以做
.center-text
{
display: table;
margin: 0 auto;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.