你好,我这里有一张图片
然后文本被推到顶部?
是否有可以使其位于中心的属性?
这是我试过的 CSS。
text-align: center;
margin: center;
最佳答案
为此你需要line-height
。我也添加了您自己的图片以供引用:
* {font-family: 'Segoe UI'; font-size: 10pt;}
.tabs, .tabs li {margin: 0; padding: 0; list-style: none; display: block;}
.tabs li {display: inline-block; background-color: #ccc; line-height: 50px; padding: 0 10px; border-top: 2px solid #999;}
.theImg {background: url("http://i.stack.imgur.com/rld5h.png") center center no-repeat; line-height: 45px; width: 122px; text-align: center; margin: 20px; font-weight: bold;}
<ul class="tabs">
<li>Tab 1</li>
<li>Tab 2</li>
<li>Tab 3</li>
</ul>
<!-- Using your code! -->
<div class="theImg">Text</div>
关于css - 垂直居中某些文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27843300/