CSS Float Property - Horizontal Float Based Navigation Menu

Here's how you can use the CSS float property to create a horizontal navigation menu.

<html>

<head>
<meta charset="UTF-8">
<title>Float-based Horizontal Navigation Menu</title>
<meta name="description" content="Float-based Horizontal Navigation Menu">
<style>
	#wrapper {
		width: 980px; 
		margin: 10px auto; 
	}
	header {
		border-bottom: 1px solid black; 
		padding: 20px; 
	}
	footer {
		border-top: 1px solid black; 
		padding: 20px; 
	}
	nav {
		overflow: hidden;
		border-bottom: 1px solid black; 
		padding-bottom: 1em; 
	}
	nav ul {
		padding: 0;
		margin: 0;
	}
	nav li {
		float: left; 
		width: auto; 
		list-style-type: none; 
		padding: 5px; 
		margin: 0; 
	}
	nav li a {
		text-decoration: none; 
		border: 1px solid black;
		padding: 5px; 
	}
</style>
</head>

<body>
	<div id="wrapper">
		<header>
			<h1>Site Title - Header</h1>
			<p>Slogan Text</p>
		</header>
		
		<nav>
			<h2>Navigation Menu</h2>
			<ul>
				<li><a href="#" title="title-1">Button-1</a></li>
				<li><a href="#" title="title-2">Button-2</a></li>
				<li><a href="#" title="title-3">Button-3</a></li>
				<li><a href="#" title="title-4">Button-4</a></li>
			</ul>
		</nav>
		
		<main>
			<h2>Content Area</h2>
			<p>Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.</p>
			<p>Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.</p>
		</main>
		
		<footer>
			<h2>Footer</h2>
			<p>Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when</p>
		</footer>
	</div> 	<!-- End of #wrapper -->
</body>

</html>

Here's some explanation about the code: 

  • For the sake of convenience and centering, "#wrapper" has been given a fixed width and it's been centered.
  • "nav" has been given the CSS rule, "overflow: hidden;" to clear the floated "li's" related to the navigation menu.
  • all the "li's" have been floated to left.
  • the rest of the code related to the navigation menu is just to make the links and other components to look like buttons and give them an overall navigation menu-like look.