Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CSS remove gap between the text and list-style-image [duplicate]

Tags:

html

css

For my ul list items I added a picture using list-style-image property.

example what I have: JSFiddle

ul {
  list-style-image: url('http://placehold.it/50x40');
}
<ul>
  <li>Coffee</li>
  <li>Tea</li>
  <li>Coca Cola</li>
</ul>

I would like my text (e.g. "Coffee") within the li items to touch the pictures - have no gap between the list item image and its description.

like image 809
Helen3061371 Avatar asked Sep 28 '16 12:09

Helen3061371


People also ask

How do you remove space between image and text in CSS?

HTML. Line Height Property: The CSS line-height-property can be used to set the height of the line, whose value is set to normal, by default. By setting the height of the container at 0%, the white space can be removed.

How do you remove extra space in CSS?

apply float:left and that will remove the space so the text doesn't have to be on 1 line.


2 Answers

One solution is to remove the list style and add the image before the li element via pseudo class :before

ul {
  list-style: none;
}

ul li:before {
  content: url(http://placehold.it/50x40);  
  display: inline-block;   
  vertical-align: middle;
}
<ul>
  <li>Coffee</li>
  <li>Tee</li>
  <li>Cola</li>
</ul>
like image 67
Andy Tschiersch Avatar answered Sep 25 '22 12:09

Andy Tschiersch


It seems that you cannot directly control the space between the list-style-image (or bullet) and the li content.

In order to make it happen you can use the image as background

li {
  list-style-type: none;
  background-image: url('http://placehold.it/50x40');
  background-repeat: no-repeat;
  background-size: 15px 15px;
  padding-left: 15px;
}

https://jsfiddle.net/gd2rtb70/

You can also look at this answer here

like image 42
Alekos Dordas Avatar answered Sep 22 '22 12:09

Alekos Dordas