HTML Element Style How to - Wrap li items when taller than parent container








Question

We would like to know how to wrap li items when taller than parent container.

Answer


<!DOCTYPE html>
<html>
<head>
<style type='text/css'>
ul {<!--from   w w w  . ja  v a  2s.co m-->
  height: 90px;
  width: 100%;
  display: block;
  background-color: grey;
  overflow: hidden;
}

li {
  height: 20px;
  width: 60px;
  background-color: red;
  float: left;
  width: 50%;
}
</style>
</head>
<body>
  <ul>
    <li>test</li>
    <li>test</li>
    <li>test</li>
    <li>test</li>
    <li>test</li>
    <li>test</li>
    <li>test</li>
    <li></li>
    <li></li>
    <li></li>
    <li></li>
    <li></li>
  </ul>
</body>
</html>

The code above is rendered as follows: