css - 垂直居中某些文本

标签 css

你好,我这里有一张图片

http://puu.sh/eeOTZ/1e14f8b0ce.png

然后文本被推到顶部?

是否有可以使其位于中心的属性?

这是我试过的 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/

相关文章:

javascript - 我如何知道跨度(div) block 中转运的​​内容的宽度和高度

javascript - 动画菜单 : shall I use canvas or javascript?

javascript - js切换: making an anchor trigger a toggle in a different page

html - 如何在每个菜单按钮之后放置 e/?

javascript - 重置时输入字段文本CSS

css - 我无法处理绝对位置的 z-index

javascript - 在滚动发生之前获取旧值

css - Rails 3 - link_to 应用样式

CSS ID 的问题。无法样式

html - 从中心开始的 CSS 线性渐变