We would like to know how to float list items to create horizontal menu.
<!DOCTYPE html>
<html lang="en">
<head>
<title>Example of clearing floats</title>
<style type="text/css">
ul {<!--from w w w .ja va2s. c o m-->
margin: 20px;
padding: 0;
list-style: none;
}
ul li {
float: left;
margin-right: 10px;
}
ul li a {
display: block;
height: 30px;
line-height: 30px;
padding: 0 20px;
color: #ffffff;
background: #92bdcc;
font-size: 16px;
font-weight: bold;
text-decoration: none;
}
ul li a:hover {
color: #ffffff;
background: #e1a7b8;
}
</style>
</head>
<body>
<ul>
<li><a href="#">Home</a></li>
<li><a href="#">About Us</a></li>
<li><a href="#">Contact</a></li>
</ul>
</body>
</html>
The code above is rendered as follows: