Center a Simple CSS Horizontal Navigation Bar Made by Using Float

* {
box-sizing: border-box;
}
body {
margin: 0;
padding: 0;
background-color: #ccc;
}
nav ul {
list-style: none;
padding: 0;
margin: 0;
background-color: #444;
text-align: center; /* step 4*/
overflow: auto; /* step 5*/
}
nav li {
float: left; /* step 1 */
width: 20%; /* step 3*/
}
nav a {
display: block; /* step 2 */
}
/* common text style */
nav a {
font-family: sans-serif;
font-size: 1.2rem;
height: 3rem; /* vertically center */
line-height: 3rem; /* vertically center */
color: #fff;
text-decoration: none; /* remove underline */
}
nav a:hover {
background-color: #005f5f;
}
nav a.active {
background-color: #eee;
color: #444;
cursor: default;
}
nav {
width: 80%;
margin: 0 auto;
}

--

--

Love podcasts or audiobooks? Learn on the go with our new app.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store