Super simple navigation menu

By | January 2, 2014

Here is a super simple navigation bar. Customize it for your site, with colors and fonts.
This is just a super simple base recipe:

First the html:

<ul class="menubar">
 <li><a href="#">hem</a></li>
 <li><a href="#">info</a></li>
 <li><a href="#">tjänster</a></li>
 <li><a href="#">kontakt</a></li>
</ul>


We end up with this as our base structure:
1

Then the CSS:
We start by setting the ul element margin and padding to zero. Unless you need some other values. This is just to make sure we don’t get any freaky rogue pixels messing with the menu.

.menubar
{
	margin: 0;
	padding: 0;
}

Then set the list objects to float to the left, instead of stacking like a vertical list. We also set the list-style to none, to remove the list dots. Last we set every list object to have the width of 25% of the containing element. This is because we have four buttons. If we add one we need to make it 20%. This may of course be set to a certain pixel amount (i.e. width: 200px)

.menubar li
{
	float: left;
	list-style:none;
	width: 25%;
}

This is what we’ve got now:
2

The buttons will highlight and be clickable because they are actually hyperlinks. So we set the hyperlinks to display as blocks with 5px padding around the text. Also, we remove the text-decoration. We don’t want the button texts to be underlined. We also set the color and background color of the buttons.

.menubar li a
{
	background-color: grey;
	color: white;
	display: block;
	padding: 5px;
	text-decoration:none;
}

The last bit is to make sure the buttons shift background color when the user hover over them.

.menubar li a:hover
{
	background-color: red;
}

Now we have working navigation bar:
3

If you want to add borders, change fonts, center text etc.  Do that to the a-elements. That way you won’t have to keep track of every single pixel. The li-elements will stay at 25% even if you add borders to the a-elements:

.menubar li a
{
	background-color: grey;
	color: white;
	display: block;
	text-decoration:none;

	border: solid 1px #999;
	text-align:center;
}

The final result looks like this:
3

Here’s the full HTML and CSS:

HTML

<ul class="menubar">
 <li><a href="#">hem</a></li>
 <li><a href="#">info</a></li>
 <li><a href="#">tjänster</a></li>
 <li><a href="#">kontakt</a></li>
</ul>

CSS

.menubar
{
	margin: 0;
	padding: 0;
}

.menubar li
{
	float: left;
	list-style:none;
	width: 25%;
}

.menubar li a
{
	background-color: grey;
	color: white;
	display: block;
	text-decoration:none;
	border: solid 1px #999;
	text-align:center;
}

.menubar li a:hover
{
	background-color: red;
}

Leave a Reply

Your email address will not be published. Required fields are marked *