HTML Element Style How to - Left align menu icon for list item








Question

We would like to know how to left align menu icon for list item.

Answer


<!DOCTYPE html>
<html>
<head>
<style>
ul {<!--from   w  w w .j a  va 2  s.com-->
  margin: 0;
  padding: 0;
}

ul li {
  padding: 4px;
}

.icon_name_here:before {
  content: '';
  width: 24px;
  height: 24px;
  display: block;
  float: left;
  padding: 4px;
  background: url('http://www.java2s.com/style/download.png') no-repeat 0 0;
}
</style>
</head>
<body>
  <ul>
    <li class="icon_name_here">Item1</li>
    <li>Item2</li>
  </ul>
</body>
</html>

The code above is rendered as follows: