Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

list-style-image svg smaller in webkit

Tags:

css

svg

I've got a bit of an odd problem with my svg list-style-image in google chrome.

.services ul {
list-style-image: url('images/check.svg');
list-style-position: inside;
padding: 0;
margin: 0;
}

The image size is supposed to be 16px x 16px. But it appears way smaller, about half of the size. If I switch to png, the size is correct. In other browsers it seems allright.

Any ideas?

like image 785
Jando Avatar asked Mar 04 '14 17:03

Jando


People also ask

How do I reduce the size of a list-style-image?

Resize the image. Use a background-image and padding instead (easiest method). Use an SVG without a defined size using viewBox that will then resize to 1em when used as a list-style-image (Kudos to Jeremy).

What is the use of list-style-image?

The list-style-image CSS property sets an image to be used as the list item marker. It is often more convenient to use the shorthand list-style .

Which style attribute value is used to set the image of a list item?

The list-style-image property replaces the list-item marker with an image.

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. Hope this helps explain it a bit better.


2 Answers

since you are calling the SVG image; you have to define SVG on your page as well. It is also mandatory to define the height and width as well in your SVG otherwise by default its take 1em width and height if not mentioned.

<svg height="16px" width="16px" viewBox="0 0 16 16"  version='1.1' xmlns='http://www.w3.org/2000/svg'>
</svg>

It would be better way to call the image by using background:url this way a height and width can given to image, so the SVG image could rendered properly.

.services li:before { 
content:''; 
display:inline-block; 
height:1em; 
width:1em; 
background-image:url('images/check.svg'); 
background-size:contain; 
background-repeat:no-repeat; 
padding-left: 2em; 
}
like image 105
Kheema Pandey Avatar answered Oct 18 '22 00:10

Kheema Pandey


I had the same problem, especially with the size on iOs devices. I solved it by using a :before attribute

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

.usp ul li:before {
    content: url('images/check.svg');
    width: 16px;
    height: 16px;
    margin-right: 10px;
}
like image 30
MikeyMo Avatar answered Oct 17 '22 23:10

MikeyMo