简体   繁体   English

如何与我的子弹图像对齐 <li> 内容?

[英]How can I line up my bullet images with my <li> content?

Heres a screenshot to make it clear. 下面是一个截图,以表明它。 I'm trying to figure out a robust way of making the bullet images vertically aligned to my li content. 我正试图找出一种强有力的方法,使子弹图像垂直对齐我的内容。 As you can see my content is currently too high. 如您所见,我的内容目前太高了。

Many thanks 'over-flowers'... 非常感谢'过花'......

http://dl.getdropbox.com/u/240752/list-example.gif http://dl.getdropbox.com/u/240752/list-example.gif

Well, some css code to see how you currently set your bullet images would be useful ;-) 好吧,一些css代码,看看你目前如何设置你的子弹图像将是有用的;-)

Instead of actually setting the 'list-style-image' property, I've had far more consistent results with setting a background-image property for the li element. 我没有实际设置'list-style-image'属性,而是为li元素设置了background-image属性,从而获得了更加一致的结果。 You can then control the positioning with pixel accuracy. 然后,您可以使用像素精度控制定位。 Remember to set a suitable left-padding value to push your list item contents clear of the bullet image. 请记住设置合适的左边填充值以将列表项内容推送到子弹图像之外。

I like @bryn's answer. 我喜欢@bryn的回答。 One example I've used successfully: 我成功使用的一个例子:

#content ul li {
    margin: 3px -20px 3px 20px;
    padding: 0 0 0 0;
    list-style: none;
    background: url(newbullet.gif) no-repeat 0 3px;
}

The negative right margin may or may not be needed in your case. 在您的情况下可能需要也可能不需要负的右边距。 You may need to adjust to meet your specific needs depending on your image. 您可能需要根据图像进行调整以满足您的特定需求。 (My image is 14 x 15.) You must specifically set margins and padding if you want a similar look across browsers as Firefox and IE use different defaults for displaying bullets. (我的图像是14 x 15。)如果你想在浏览器中看到类似的外观,你必须专门设置边距填充,因为Firefox和IE使用不同的默认值来显示项目符号。

You can use something like this in your css... 你可以在你的CSS中使用这样的东西......

#content li{

    list-style-image: url(../images/bullet.gif);

}

use background-image, for your li elements, add padding. 使用background-image,为你的li元素添加填充。

.box li{
    padding-left: 20px;
    background-image: url("img/list_icon.jpg");
    background-repeat: no-repeat;
    background-position: 0px 2px;
    margin-top: 6px;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM