Servage Magazine

Information about YOUR hosting company – where we give you a clear picture of what we think and do!

Create a cool CSS-based tab-menu

Friday, December 6th, 2019 by Helge

This time we showtabmenu how to create a nice-looking tab-menu, based purely on HTML and CSS.

See a live tabmenu example here.

First, we want to have the menu code created in HTML. I find that the most appropriate way of doing this, is by creating the menu as a list. Thereby non-supporting browsers will still show the menu as a list, which somewhat resembles a menu. Everyone else will see the cool tab-menu :-)

<ul class="tabmenu">
  <li><a href="">Overview</a></li>
  <li class="active"><a href="">About</a></li>
  <li><a href="">Products</a></li>
  <li><a href="">Contact</a></li>
  <li><a href="">Login</a></li>
</ul>

So far this is somewhat similar to the dropdown menu, except we don’t have sub-items. This tab-menu and the dropdown could actually be combined by the clever developer ;-)

Next, we create the CSS for the menu, which will turn the simple list into something nicer.

.tabmenu {
	font-family: Arial, Verdana;
	font-size: 1em;
	height: 32px;
	border-bottom: 1px solid #333333;
	margin-bottom: 20px;
	padding-left: 15px;
}
.tabmenu li {
	list-style-type: none;
	list-style-position: inside;
	float: left;
	margin: 0;
	padding: 0;
	font-size: 16px;
}
.tabmenu li.title {
	padding: 6px 20px 0 0;
}
.tabmenu a {
	display: block;
	height: 25px;
	padding: 6px 15px 0 15px;
	color: #009900;
	text-decoration: none;
}
.tabmenu a:hover {
	color: #990000;
	text-decoration: underline;
}
.tabmenu li.active a {
	text-decoration: none;
	background-image: none;
	border: 1px solid #333333;
	border-bottom-color: #ffffff;
	color: #333333;
}

That’s it. Enjoy! Please feel free to submit any feedback how to extend or improve this snippet.

Create a cool CSS-based tab-menu, 4.8 out of 5 based on 6 ratings
Categories: Guides & Tutorials, Tips & Tricks

Keywords: , ,

You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.

No comments yet (leave a comment)

You are welcome to initiate a conversation about this blog entry.

Leave a comment

You must be logged in to post a comment.