简体   繁体   English

垂直对齐内联元素中的文本

[英]Vertically align text in an inline element

Problem 问题

So I'm creating a simple navigation menu which contains a div of a tags. 所以我创建其中包含了一个简单的导航菜单diva标签。 Currently it looks like this: 目前它看起来像这样:

在此输入图像描述

The follow are my HTML and CSS: 以下是我的HTML和CSS:

HTML HTML

<div id="tabcontent-container">
    <div class="tabcontent-menu">
        <a href="#">WLAN Jumpstart</a>
        <a href="#">Mobility</a>
        <a href="#">Guest Access Jumpstart</a>
    </div>
</div>

The CSS CSS

#tabcontent-container { padding: 15px 0px; position: relative; text-align: center; border-radius: 25px; -webkit-border-radius: 25px; }
.tabcontent-menu {}
.tabcontent-menu a { text-decoration: none; color: white; font-size: 30px; border-right: 1px solid white; line-height: 33px; padding: 0 22px; display: inline-block; width: 200px; height: 70px; vertical-align: top; }
.tabcontent-menu a:last-child { border:none; }
.tabcontent-menu a:hover { color:#000; }

Working example on Jsfiddle.net Jsfiddle.net上的工作示例

The Question 问题

I'm wondering if there is an easier way to align the middle "Mobility" a tag to the middle. 我不知道是否有是使中间的“移动性”更简单的方法a标签中间。 The other two links look fine because they are double line. 其他两个链接看起来很好,因为它们是双线的。 I purposely made them double line for a reason, and now just need the middle one to middle align some how. 我故意将它们作为双线制作,现在只需要中间的一个中间对齐一些如何。

Any suggestions? 有什么建议?

You can use vertical-align: middle to adjust the position vertically. 您可以使用vertical-align: middle来垂直调整位置。 Since that only works on table cells, set display: table-cell for the .tabcontent-menu a 由于这仅适用于表格单元格,因此请为.tabcontent-menu a设置display: table-cell

http://jsfiddle.net/H9VHs/8/ http://jsfiddle.net/H9VHs/8/

I usually accomplish something like this by varying the line-height . 我通常通过改变line-height来完成这样的事情。

.tabcontent-menu a.midline {
 line-height: 64px;   
}

See it here: http://jsfiddle.net/PZVnq/ 在这里看到: http//jsfiddle.net/PZVnq/

Documentation/Further Reading 文件/进一步阅读

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM