【问题标题】:Why is my hover background being shifted为什么我的悬停背景被移动
【发布时间】:2011-07-05 11:01:39
【问题描述】:

我正在制作一些标签,使用背景图片作为悬停状态背景。唯一看起来不错的是“Day”。我想,因为它只有 3 个字符,而其他选项卡是 4 个字符。有没有办法让悬停背景以它们为中心?这是列表的 css。

    li {
    font: 9pt "Helvetica Neue", Helvetica, Arial, "Trebuchet MS", Trebuchet, serif;
    margin-top: .192333333em;
    float: right;
    height: 19px;
    width: 40px;
    margin-left: 10px;
    display: inline-block;
    margin: 7px;
}
li.current {
    background: url('img/red-current-bg.png') no-repeat;
    line-height: 1.6em;
}

ul#tabnav { 
    margin: 0;
}

ul#tabnav li a {
    text-shadow: 0 1px #800000;
    text-decoration: none;
    padding: 8px 11px;
    line-height: 1.6em;
}

ul#tabnav li:hover {
    background: url('img/red-current-bg.png') 0 0 no-repeat;
}

【问题讨论】:

    标签: css hover html-lists


    【解决方案1】:

    你可以只调整背景的水平位置来调整像素或居中吗?

    ul#tabnav li:hover {
      background: url('img/red-current-bg.png') 3px 0 no-repeat;
    }
                                or
    ul#tabnav li:hover {
      background: url('img/red-current-bg.png') center top no-repeat;
    }
    

    【讨论】:

    • 我明白了。不得不稍微弄乱 li 上的填充并更改右边距设置。感谢您的帮助:)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-07-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-05-17
    相关资源
    最近更新 更多