HTML Element Style How to - Cover ul completely without fixed width of li








Question

We would like to know how to cover ul completely without fixed width of li.

Answer


<!DOCTYPE html>
<html>
<head>
<style type='text/css'>
ul {<!-- w  ww. j a v  a  2s.co m-->
  background: #aaa;
  display: table;
  width: 100%; /* Tables are not 100% width like block elements */
  margin: 0;
  padding: 0;
  list-style: none;
}

li {
  display: table-cell;
  text-align: center;
}

li a {
  display: block;
  padding: 5px 10px;
  color: #fff;
}
</style>
</head>
<body>
  <ul>
    <li><a href="#">Test</a></li>
    <li><a href="#">Test</a></li>
    <li><a href="#">Test</a></li>
  </ul>
</body>
</html>

The code above is rendered as follows: