Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how can i set custom bullet image of li tag?

Tags:

css

html-lists

I am trying to set custom image as a bullet. when i am using background or background-image tag it is work but not align properly with list category. And when i am using list-style-image it is not displaying the image as a bullet.

Problem :

Css

enter image description here

Firebug

enter image description here

Image is also displaying in firebug when i move my mouse over on it

Wrong final output

enter image description here

Solution :

Correct Output what i want

enter image description here

like image 242
Anandkumar Mehta Avatar asked Apr 10 '13 10:04

Anandkumar Mehta


People also ask

How do I change the bullet image Li?

To change the bullet to an image, we will add two new CSS classes one for the <ul> element the other one for the <li> element. For the list class, we will set the padding and the margin to "0" and set the list-style-type to none.

How do I add an image to ul li tag?

Firstly, you need to create the List Item using a li list item tag. Within that List Item tag, you can place your image. You add an image within the Image tag img.

How do I make an image a bullet point?

On the Home tab, in the Paragraph group, click the arrow next to Bullets, and then click Define New Bullet. In Word for Windows: Click Symbol or Picture, and then choose any symbol or picture that you want to use.


1 Answers

Here's one method that I tend to lean on. Add a before to the li, size it as required and add a background image to it.

Then just sprinkle some flexbox on to stop the text wrapping underneath the bullet.

I made a quick jsfiddle to demonstrate it

li {
    display: flex;
    align-items: center;
    margin: 10px 0;

    line-height: 30px;

    list-style: none;
}

li:before {
    display: block;
    flex-shrink: 0;
    width: 33px;
    height: 33px;
    margin-right: 10px;

    vertical-align: middle;

    background: url('https://image.flaticon.com/icons/png/128/1168/1168671.png') no-repeat left center;
    background-size: contain;

    content: '';
}
like image 185
Adam Tomat Avatar answered Oct 21 '22 12:10

Adam Tomat