Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Vertically center <li> text with bullet image?

So I am trying to figure out how I can vertically align some text that I have with a custom bullet image. Here is what I have:

<ul>
    <li>LINE OF TEXT</li>
    <li>LINE OF TEXT</li>
    <li>LINE OF TEXT</li>
</ul>

And for the CSS...

#div .class
{
    color: #4c361c;
    font-size: 13px;
    list-style-image: url(../images/image.png);
}

#div .class li{ }

Does anyone have anyideas on how to go about doing this?

like image 957
user1804933 Avatar asked Dec 03 '12 01:12

user1804933


People also ask

How do you center text vertically in a Li?

Inorder to make vertical-align: middle; work, you need to use display: table; for your ul element and display: table-cell; for li elements and than you can use vertical-align: middle; for li elements. You don't need to provide any explicit margins , paddings to make your text vertically middle.

How do I vertically align text with icons?

If you want to make a text appear vertically aligned next to a Font Awesome icon, you can use the CSS vertical-align property set to “middle” and also, specify the line-height property. Change the size of the icon with the font-size property.

How do I vertically align text in a picture?

We need to create a parent element that contain both image and text. After declaring the parent element as flexbox using display: flex; we can align the items to the center using align-items: center;. Example: This example uses flexbox to vertically align text next to an image using CSS.


1 Answers

Here's a demo.

Using a background image can get you the desired effect.

HTML

<ul>
    <li>One</li>
    <li>Two</li>
    <li>Three</li>
    <li>Four</li>
</ul>

CSS

ul {
    list-style: none;
}

ul > li {
  background: url('../imgpath/bullet-image.png') no-repeat left center;

  /* Adjust the padding for your custom bullet image */
  padding: 10px 0 10px 34px;
}
like image 119
james Avatar answered Sep 29 '22 02:09

james