Cross Browser Solution for Image Marker in CSS


In order to display an image marker properly in all browsers, a cross-browser solution is required. The text alignment after the image marker is sometimes distorted. To achieve a uniform output, we specify the image to be used as a marker as background and align it accordingly.

Example

The following examples illustrate styling of lists −

 Live Demo

<!DOCTYPE html>
<html>
<head>
<style>
ul{
   list-style-type: none;
   padding: 0px;
   margin: 0px;
   font-size: 1.5em;
}
ul li{
   background-image: url("https://www.tutorialspoint.com/images/spring.png");
   background-repeat: no-repeat;
   background-position: 0px 5px;
   padding-left: 24px;
}
</style>
</head>
<body>
<h2>Tutorials</h2>
<ul>
<li>Java</li>
<li>C#</li>
<li>C</li>
<li>C++</li>
<li>Spring</li>
<li>Hibernate</li>
</ul>
</body>
</html>

Output

This gives the following output −

Example

 Live Demo

<!DOCTYPE html>
<html>
<head>
<style>
ul{
   box-shadow: inset 0 0 8px orange;
   list-style-type: none;
   padding: 12px;
   padding-left: 20px;
   margin: 2px;
   font-size: 1.35em;
}
ul li{
   background-image: url("https://www.tutorialspoint.com/images/css.png");
   background-repeat: no-repeat;
   background-position: 0px 5px;
   padding-left: 40px;
   font-style: italic;
}
</style>
</head>
<body>
<p>Requirements:</p>
<ul>
<li>Tutorials</li>
<li>Interview QA</li>
<li>Quiz</li>
</ul>
</body>
</html>

Output

This gives the following output −

Updated on: 06-Jan-2020

112 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements