CSS: vertical alignment of text in li element does not work

I use list-style for li elements and single-line text.

enter image description here

But it looks bad, so I want to vertically align the text to the middle of the image.

Should I use vertical alignment: middle, right? But that did not work for me.

<html>
    <head>
        <title> This is an demo </title>
        <style>
            body {
                background-color: #464443;
                color: white;
            }
            ul {
                list-style-image: url('bg.png');
            }

            li {
                vertical-align: middle;
            }

        </style>
    </head>

    <body>
        <ul>
            <li>abc</li>
            <li>abc</li>
            <li>abc</li>
            <li>abc</li>
        </ul>
    </body>
</html>
+5
source share
3 answers

A satisfactory way to do this (imo) is to not use the list-style-image style, instead using the background property to set the β€œbullet” instead (note that I replaced my own placeholder image since I just copied / inserted from the violin). The size of capital and other sizes depends on the size of the "bullet" image.

: http://jsfiddle.net/huBpa/1/

body {
  background-color: #464443;
  color: white;
}

 ul {
   list-style: none;
   padding: 0;
   margin: 0;
 }

 li {
   background: url('http://lorempixel.com/output/technics-q-c-32-32-1.jpg') no-repeat;
   line-height: 32px;
   vertical-align: middle;
   padding-left: 40px;
 }​
+14

, . padding , .

    ul {
            list-style: none;
            margin-left: 0;
            padding-left: 0;
    }

    li {
            padding: 10px 10px 15px 20px;
            background-image: url(images/arrow.png);
            background-repeat: no-repeat;
            background-position: 0px;
    }
+4

Add row string to li. Make sure it is the same height as the image.

`

li {
            vertical-align: middle;
            line-height: 30px; 
        }
-1
source

All Articles