使用 css 将锚点垂直居中在 span 和 li 内

发布于 2024-09-12 07:04:19 字数 1144 浏览 2 评论 0原文

我正在使用 jQuery 选项卡,并且在选项卡标题中添加了一些跨度,以便我可以使用背景图像。这是标记:

<ul>
    <li><span class='tab_outer'><span class='tab_inner'><span class='tab'><a href="#orderInfo">
        Order Info</a></span></span></span></li>
    <li><span class='tab_outer'><span class='tab_inner'><span class='tab'><a href="#notes">
        Notes</a></span></span></span></li>
    <li><span class='tab_outer'><span class='tab_inner'><span class='tab'><a href="#eventLog">
        Event Log</a></span></span></span></li>  
</ul>

问题:锚点内的文本显示在锚点块的最底部。如果我能把它向上移动三个像素,那就完美了。以下是我认为相关的所有 CSS:

.tab_outer, .tab_inner, .tab
{
    display: inline-block;
    font-size: 11px;
    list-style: none;
}

.tab_outer
{
    margin-bottom: -3px;
    padding-right: 3px;
    margin-top: 4px;
}

.tab_inner
{
    margin-bottom: -1px;
    padding-left: 3px;
}

.tab
{
    margin-top: 0px;
    padding: 0px 4px 0px 4px;
    margin-bottom: -1px;
}

I'm using jQuery tabs, and I added some spans to the tab headers so I could use a background image. Here's the markup:

<ul>
    <li><span class='tab_outer'><span class='tab_inner'><span class='tab'><a href="#orderInfo">
        Order Info</a></span></span></span></li>
    <li><span class='tab_outer'><span class='tab_inner'><span class='tab'><a href="#notes">
        Notes</a></span></span></span></li>
    <li><span class='tab_outer'><span class='tab_inner'><span class='tab'><a href="#eventLog">
        Event Log</a></span></span></span></li>  
</ul>

The problem: the text inside the anchors is displaying on the very bottom of the anchor's block. If I could just move it up like, three pixels, it'd be perfect. Here's all the CSS that I think is relevant:

.tab_outer, .tab_inner, .tab
{
    display: inline-block;
    font-size: 11px;
    list-style: none;
}

.tab_outer
{
    margin-bottom: -3px;
    padding-right: 3px;
    margin-top: 4px;
}

.tab_inner
{
    margin-bottom: -1px;
    padding-left: 3px;
}

.tab
{
    margin-top: 0px;
    padding: 0px 4px 0px 4px;
    margin-bottom: -1px;
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

反话 2024-09-19 07:04:19

尝试行高和垂直对齐属性:

.tab_outer  {
  line-height: 32px; /* Put the corresponding size here */
  vertical-align: middle;
}

或者您可以调整填充:

.tab_outer {
  padding-bottom: 3px;
}

Try the line-height and vertical-align properties:

.tab_outer  {
  line-height: 32px; /* Put the corresponding size here */
  vertical-align: middle;
}

Alternatively you can adjust the padding:

.tab_outer {
  padding-bottom: 3px;
}
清旖 2024-09-19 07:04:19
margin: 0px;
padding: 0px;
vertical-align: super;
margin: 0px;
padding: 0px;
vertical-align: super;
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文