简体   繁体   中英

css list-style-image is not on (vertical) center

I have this simple ul li script with list-style-image.

The problem is that the image is not (vertical) center.

vertical-align is not helpful here.

Any idea ?

http://jsfiddle.net/nDX6g/

ul {
    margin-top: 10px;
    padding-left: 50px;
    color: #3C4355;
    margin-bottom: 6px;
}

li {
    margin-left: 20px;
    color: #3C4355;
    line-height: 20px;
    list-style-image: url('http://forum.bizportal.co.il/NewSite/emoticons/smiley9.gif');
}




<ul>
    <li>Text 1</li>
    <li>Text 2</li>
</ul>

Example: http://jsfiddle.net/nDX6g/3/

li {
   list-style: none;
}

li:before {
   content: url(...);
   display: inline-block;
   vertical-align: middle;
   margin-right: .5em;
}

if your items may span on two (or more) lines, then try this other fiddle: http://jsfiddle.net/nDX6g/4/

Screenshot:

在此处输入图片说明

You can use background image to adjust background position properly:

li {
    margin-left: 20px;
    color: #3C4355;
    line-height: 20px;
    background: url('http://forum.bizportal.co.il/NewSite/emoticons/smiley9.gif') 0 0 no-repeat;
    padding-left: 20px;
    list-style-type: none;
}

Demo: http://jsfiddle.net/dfsq/nDX6g/2/

Check this demo jsFiddle

CSS

ul {
    margin-top: 10px;
    padding-left: 50px;
    color: #3C4355;
    margin-bottom: 6px;
}

li {
    margin-left: 20px;
    color: #3C4355;
    line-height: 20px;
    padding: 0px 0px 0px 25px;
    list-style: none;
    background: url('http://forum.bizportal.co.il/NewSite/emoticons/smiley9.gif') no-repeat left top;
}

Result

在此处输入图片说明

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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