HTML Element Style How to - Create list item with div and image as bullet








Question

We would like to know how to create list item with div and image as bullet.

Answer


<!DOCTYPE html>
<html>
<head>
<style type='text/css'>
div#con {<!--  w  w w  .  j ava2  s.co  m-->
  width: 300px;
  height: 400px;
}

div.item {
  border-bottom: 1px dashed red;
}

div.item div.img {
  float: left;
  width: 22px;
  height: 25px;
  background-image: url('http://www.java2s.com/style/download.png');
  background-repeat: no-repeat;
  background-position: center left;
  text-align: center;
  vertical-align: middle;
}

div.clear {
  clear: both
}
</style>
</head>
<body>
  <div id="con">
    <div class="item">
      <div class="img">1</div>
      <div class="content">
        name:name<br /> age:age<br />
      </div>
      <div class="clear"></div>
    </div>
    <div class="item">
      <div class="img">2</div>
      <div class="content">
        name:name<br /> otherattribute:xxx<br />
      </div>
      <div class="clear"></div>
    </div>
    <div class="item">
      <div class="img">3</div>
      <div class="content">
        name:name<br />
      </div>
      <div class="clear"></div>
    </div>
  </div>
</body>
</html>

The code above is rendered as follows: