Search code examples
htmlcssmenuresizable

CSS! Horizontal resizable menu ul li, how to spread it on full width of the display?


the site is resizable, so I can not use px, and sometimes it's a trouble with last items, they falling down when window go into small length, how to avoid this? let's see my single page:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>li menu</title>
</head>

<body>
<style>
div {
    width: 100%;
    height: 3%;
    background: red;
    opacity: 0.7;
}
ul {
    width:100%;
    list-style:none;
    padding: 0;
    margin: 0;
}

ul li {
 background-color:yellow;
 display: inline;
 text-align: center;
 width:30%;
}
</style>
<div>
    <ul>
        <li>item 1</li>
        <li>item 2</li>
        <li>item 3</li>
        <li>item 4</li>
        <li>item 5</li>
    </ul>
</div>

</body>
</html>

Solution

  • You can add white-space: nowrap; to your UL element http://jsfiddle.net/jvrCH/ But in this case menu elements will go off screen when not enough space.