[英]How to center text and a subline in a list item?
I had a list that was structured like this: 我有一个结构如下的列表:
<ul>
<li>
<a href="#">Link</a>
</li>
</ul>
I wanted each of my list items to have a height of 50px, so I set the line-height of <a>
to 50px and it worked fine. 我希望每个列表项的高度都为50px,因此我将<a>
的行高设置为50px,它可以正常工作。
However, now I'm trying to add a sub-line to each <a>
tag so that it looks like this: 但是,现在我试图在每个<a>
标记中添加一个子行,使其看起来像这样:
<ul>
<li>
<a href="#">
Link
<span class="sub-line">Link Info</span>
</a>
</li>
</ul>
The sub-line would be a smaller font and would show up comfortably under the link text. 子行将是较小的字体,并会舒适地显示在链接文本下。 I've been messing around with display and line-height and absolute positioning, but I've had no luck coming up with a clean solution. 我一直在搞乱显示,行高和绝对位置,但是我没有运气想出一个干净的解决方案。 Help would be greatly appreciated! 帮助将不胜感激!
You can just use display: block
to put the sub line below the link text with a smaller font 您可以只使用display: block
将子行放在链接文本下方,并使用较小的字体
.sub-line {
display: block;
font-size: 80%;
}
To reduce the distance 减少距离
line-height: 50%;
and to center both horizontally 并同时水平居中
li {
text-align: center;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.