Jesin's Blog

Welcome to the Portal of Technology

  • Facebook
  • GitHub
  • RSS
  • Twitter
  • Home
  • Categories
    • Domains
    • Linux
    • Networking
    • PHP
    • Virtualization
    • Web Design
    • Web Servers
    • Windows
  • WordPress Plugins
    • Custom Error Pages
    • HTTP Digest Authentication
    • Mailgun Email Validator
  • Toolbox
    • DNS Lookup Tool
    • htdigest Generator Tool Online
    • htpasswd Generator Tool Online
    • HTTP Headers Lookup Tool
    • MD5 Encryption Tool
    • Open Port Check Tool
    • SHA-1 Encryption Tool
    • URL Encoding/Decoding Tool
  • About Me
  • Contact Me
  • Sitemap
Home ›
Web Design ›
CSS Horizontal Navigation Menu

CSS Horizontal Navigation Menu

January 4, 2011 Web Design Jesin A 2 Comments

web design category thumbnail

CSS Horizontal Navigation Menu is the basic menu sent on most of the websites just below the  logo. It is very easy to create this type of menu using HTML unordered lists and CSS. It is search engine friendly and uses a tableless design. The CSS Horizontal Menu will be created with a hover effect to spice up things. This will change the color and style of a menu item when the mouse pointer is moved over it. Lets start step-by-step building the CSS Horizontal Menu

Creating a CSS Horizontal Menu

Using the HTML <ul> tag create an unordered list of items for you menu. All items should be hyperlinks pointing to their respective pages.

<ul id="menu">
<li><a href="index.html">Home</a></li>
<li><a href="services.html">Services</a></li>
<li><a href="careers.html">Careers</a></li>
<li><a href="about-us.html">About Us</a></li>
<li><a href="contact-us.html">Contact Us</a></li>
</ul>

The ID attribute is added to the ul tag so that CSS ID selector can be used to apply styles. When this HTML file is opened in a web browser you’ll see bullets before each menu item. The next step is to remove it using CSS. Our aim is to remove the bullets, remove the indented space and make it horizontal. Add the following code inside the head tag.

<style type="text/css">
ul#menu {
list-style-type: none;
padding: 0;
margin: 0;
}
ul#menu li {
display: inline;
}
</style>

The list-style-type: none will remove the bullet style and padding: 0 will set the space between the list and left side to zero. The li elements are block elements which means each element takes up one full line. To make them all appear in one single line display:inline is used. The menu items must now be spaced out. For this the padding attribute if the a tag will be modified.

ul#menu a {
padding: 4px 10px;
float: left;
}

The first value 4px sets the padding for the top and bottom, the 10px value is for left and right. These values can be modified according to your requirements. Now the menu has become horizontal and the items have been spaced out. The links look ugly in generic blue color. The following CSS code will modify the link text color and give it a background color.

ul#menu a {
padding: 4px 10px;
float: left;
color: #f0ffff;
background-color: grey;
text-decoration: none;
}

The text-decoration attribute is set to none to remove the underlining of the link text. The final touch is to add a hover effect for the menu items. Whenever the mouse pointer is moved over an item its color, style and background color must be changed. This is done using the pseudo class hover.

ul#menu a:hover {
color: #fffff0;
text-decoration: underline;
background-color: #000;
}

The demo of the entire code is available here. CSS Horizontal Menu

Related posts:

web design category thumbnailHow to create a horizontal drop down menu in CSS web design category thumbnailCSS Tableless Design Tutorial networking category thumbnailHow to configure frame relay in Cisco Packet Tracer windows category thumbnailDisable Right Clicking on the Desktop php category thumbnailCheckbox in PHP

Tags: css, html

Comments

  1. Nathaniel Tetteh says

    June 16, 2012 at 7:13 am

    Thank you very much Jesin, in fact I wanna be your best friend. Please

    Reply

Trackbacks

  1. CSS Tableless Design Tutorial | Jesin's Blog says:
    June 29, 2013 at 8:52 pm

    […] to color the page. View a live demo of the CSS Tableless Tutorial example. You can add the CSS Horizontal Navigation Menu to this template.  Notice that the sidebar of the pages never expand even if the #content element […]

    Reply

Leave a Reply Cancel reply

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

Get a wealth of information delivered to your inbox. Subscribe and never miss a single article.

  • Tutorials and howtos
  • Code, scripts and commands
  • Online Tools

* No spam, unsubscribe anytime

Hire Me

  • SSL installation and hardening (A+ on Qualys SSL test)
  • Apache & Nginx configuration
  • Email deliverability improvement (10/10 on Mail Tester & MailGenius)
  • WordPress customization, optimization and migration
  • and much more…

    Tools

    • DNS Lookup Tool
    • htdigest Generator Tool Online
    • htpasswd Generator Tool Online
    • HTTP Headers Lookup Tool
    • MD5 Encryption Tool
    • Open Port Check Tool
    • SHA-1 Encryption Tool
    • URL Encoding/Decoding Tool

    Nav

    • Home
    • About Me
    • Contact Me
    • Privacy Policy
    • Sitemap
    Vultr SSD VPS

    Creative Commons License
    Jesin's Blog by Jesin A is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.
    Based on a work at websistent.com.