如何使具有负左值的CSS背景位置可见?

发布于 2024-12-21 12:26:47 字数 521 浏览 4 评论 0原文

我有一个带有 list-style:none;

    元素和带有 padding:20px;< 的
  • 元素/code> 和 background-image:url(images/bullet.gif) no-repeat -20px 10px;

子弹不可见。 我现在使用的解决方法是背景位置和

  • 元素 position:relative;padding-left:20px;margin-left:- 0 而不是 -20px 20 像素;
  • 有更好的方法吗?

    编辑:我需要将项目符号放在

      框之外。这就是使用负保证金的原因。

    谢谢。

    I have a <ul> element with list-style:none; and <li> with padding:20px; and background-image:url(images/bullet.gif) no-repeat -20px 10px;.

    The bullet is not visible.
    The workaround I'm using now is 0 instead -20px for the background-position and for the <li> element position:relative;padding-left:20px;margin-left:-20px;.

    Is there a better way of doing this?

    EDIT: I need the bullet to be outside of the <ul> box. This being the reason for using negative margin.

    Thank you.

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

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

    发布评论

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

    评论(2

    慕烟庭风 2024-12-28 12:26:47

    这是一个 jsfiddle 示例。 http://jsfiddle.net/jesseatkinson/z2qss/
    你的 CSS 应该是这样的。

    ul li {
        background: url(../bullet.gif) left center no-repeat transparent;
        padding-left: 40px;
        list-style: none; 
    }
    

    Here is a jsfiddle example. http://jsfiddle.net/jesseatkinson/z2qss/.
    Your CSS should look like this.

    ul li {
        background: url(../bullet.gif) left center no-repeat transparent;
        padding-left: 40px;
        list-style: none; 
    }
    
    ~没有更多了~
    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文