垂直对齐标签中的跨度
这是我的标记。解决方案必须针对跨度中的单线或双线动态工作。所以它应该是可以添加到其中每一个并且工作正常的CSS。从internet上看,这似乎是不可能的。请证明我错了。
<ul style="text-align:center; list-style-type: none;">
<li style="width: 200px">
<a href="http://www.bing.com" style="display: block; height:35px; background: Black;">
<span>Vertical Align This Text</span>
</a>
</li>
</ul>
<ul style="text-align:center; list-style-type: none;">
<li style="width: 200px">
<a href="http://www.bing.com" style="display: block; height:35px; background: Black;">
<span>Vertical Align This Text With Double Line As Well</span>
</a>
</li>
</ul>
So here is my markup. Solution has to work dynamically for a single line or double line in the span. So it should be css that can be added to each of these and work fine. From looking on the internez this seems to be impossible. Please prove me wrong.
<ul style="text-align:center; list-style-type: none;">
<li style="width: 200px">
<a href="http://www.bing.com" style="display: block; height:35px; background: Black;">
<span>Vertical Align This Text</span>
</a>
</li>
</ul>
<ul style="text-align:center; list-style-type: none;">
<li style="width: 200px">
<a href="http://www.bing.com" style="display: block; height:35px; background: Black;">
<span>Vertical Align This Text With Double Line As Well</span>
</a>
</li>
</ul>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
这对我有用:
为了方便起见,CSS代码:
This works for me:
CSS code for convenience:
由于您包含的
有一个设置的
height
值,因此您可以使用 ol'line-height
技巧将其设置为相同的值值,在本例中:不过,只有当您的
不比
宽时,这才有效。对于双线,您需要将
设置为高度的一半 (35px 高度除以2行),所以大约17px。如果您有三行,则适用于 35px/3 ~ 11px。但正如你可以想象的那样,它在某一时刻看起来会被压扁。
因此,根据内容,您可能需要使用相对/绝对定位、较小的字体或更少的内容;)
Since your containing
<a>
have a setheight
value, you can use the ol'line-height
trick of setting it to the same value, in this case:This will only work, though, if your
<span>
isn't wider than your<li>
. In the case with the double line, you'd need to set the<line-height>
to half the<a>
's height (35px height divided by 2 lines), so around 17px. If you had three lines, it would work with 35px/3 ~ 11px. But as you can imagine, it will look smooshed at one point.So depending on the content you might have to with the relative/absolute positioning, a smaller font, or just less content ;)
为您的
和
提供以下 CSS 属性
检查工作示例,网址为 http://jsfiddle.net/r4Wsx/
Give your
<li>
and<a>
the following CSS propertiesCheck working example at http://jsfiddle.net/r4Wsx/