Codes for CSS Navigation menu

The power of CSS navigation menus on websites remains unparallel. You need to create the right set of codes for CSS and your website will be a fascinating site for all.

HTML code for CSS Menu

To begin with, you need to know the HTML code for CSS menu:

<div id= "nav-menu">
    <ul>
        <li><a href= "#">Services</a></li>
        <li><a href= "#">About Us</a></li>
        <li><a href= "#">Contact Us</a></li>
    </ul>
</div>

That is it! Too simple!

Creating the Boxes

Once the menu items are all lined up against one another, you can take a good look at it. So the CSS rule that rules here is:

#nav-menu li a {
    background: url("background.gif") #fff bottom left repeat-x;
    height: 2em;
    line-height: 2em;
    float: left;
    width: 9em;
    display: block;
    border: 0.1em solid #dcdce9;
    color: #0d2474;
    text-decoration: none;
    text-align: center;
}

The background CSS command is most important. In it, we will specify the URL of the background image for a white background behind this image, for the image to be in the bottom-left of the box and for it to be repeated along the x-axis (i.e. horizontally). If we had not specified the background image to be in the bottom of the box, it would be placed in the top left corner. This would cause the white background color to be visible right below the background image, and not above like it is now.

Removing bullets

You can remove the bullets through a set of new CSS rule:

#nav-menu ul {
    list-style: none;
    padding: 0;
    margin: 0;
}

the important CSS command is the first one, list-style: none, which says that we do not want any kind of bullet in our navigation menu. The others are also so important that they ensure maximum control over the layout and to make sure the text displays in the center of the box.

No wrapping

There is one final CSS rule that needs to be created and assigned with a width to CSS menu navigation. If this rule is not assigned, menu items on the right may be pushed below the others if users resize their screens. The new CSS command is as follows:y

#nav-menu {
    width: 30em
}

That was pretty lucid.

Follow it to give a new dimension to your CSS menus.

Of course there a lot complex ways to create CSS menus, you can even create CSS navigation with sub menus, and sub sub menus, but this is a good start for beginner.

CSS Inspiration of the Day

untitled-5.jpg

Jan 11, 2008 Linkage – Free Fonts

Some of my favorite sites with FREE fonts. Check them out I’m sure you won’t be disappointed!

What’s my Font?

Have you had the problem to lose font files or not remember the name of a certain font. It happens a lot you pre-install your Windows or Photoshop, misplace or delete files. I had a similar problem, had a font that used for sIFR and have converted the font into a flash file with name (font.swf). Year later I needed to change some images that used the same font and didn’t have the font name. Here is a cool tool that can help you find and narrow your search by using an image with your font. It’s not 100% accurate but it will at least find a font that is very close to the one you’ve used. Check it out!

WhatTheFont

WhatTheFont supports most common image formats, for example GIF, JPEG, TIFF, BMP. The maximum image size is around 360 x 275 pixels. The ideal letter height for the best search result is about 100 pixels.

CSS Inspiration of the Day

untitled-6.jpg

Jan 10, 2008 Linkage – CSS Layouts

Using CSS for Creating Two-column Layout

A close research on web design patterns show that accessibility is an aspect that is most underutilized in a good web page layout. So making accessible forms in web page is the best way to treat this problem. And when you create accessible forms, use CSS layout to create two-column layout forms without using tables, to save space and time. Although majority use block-level floats and margins to position form elements on the page, but the best accessible form can be created using IE5.X Mac as well as Firefox 1.07 Win/Mac, Opera, Camino and Safari 1.07 Mac.

How to build a CSS-based Form?

One of the best ways to build CSS-based form is to decode XHTML to bare structural elements, and then use CSS to create as much style and layout as possible using few embedded classes or IDs. Semantic elements provided by W3C in (X)HTML specifications, namely FIELDSET and LABEL, help in imparting logical order to FORMs. While FIELDSET groups’ like-minded form input fields, LABEL for links field labels with input fields through the ID attribute to make them highly accessible and of style.

To understand the difference created between table-based contact forms and CSS-based forms.

Table-based Contact Forms

Since tables use columns and rows to align labels and input fields, the codes would format the following layout:

Table based layouts lowers the content to markup ratio and reduces SEO speed and rankings. So there is a fortunate way – CSS Layout.

<form action="http://www.example.com/submit.cgi" method="post" name="f">
    <fieldset>
        <legend>Personal Information</legend>>
            <label for="firstname" accesskey="f">First name: </label>
                <input type="text" id="firstname" name="firstname" value="" tabindex="1">
            <label for="lastname" accesskey="l">Last name: </label>
                <input type="text" id="lastname" name="lastname" tabindex="2">
            <label for="email" accesskey="e">Email: </label>
                <input type="text" id="email" name="email" tabindex="3">
    </fieldset>
    <fieldset>
        <legend>Comments</legend>
            <label for="comments" accesskey="c">Your comments: </label>
                <textarea id="comments" rows="3" cols="20" name="comments"></textarea>
                <input type="submit" value="Submit" tabindex="4"> <input type="Reset" tabindex="5">
    </fieldset>
</form>

Set Form Width

Now let us set a width for the forms and style of the field sets. Since field sets are not rendered identical by different browsers, so backgrounds can overlap, and tend to take up the entire space of the screen on Internet Explorer. It is feasible to set the width using the form element:

form { /* set width in form, not fieldset (still takes up more room w/fieldset width */
    font:100% verdana,arial,sans-serif;
    margin: 0;
    padding: 0;
    min-width: 500px;
    max-width: 600px;
    width: 560px;
}

form fieldset { / * clear: both; note that this clear causes inputs to break to left in ie5.x mac, commented out */
    border-color: #000;
    border-width: 1px;
    border-style: solid;
    padding: 10px;        /* padding in fieldset support spotty in IE */
    margin: 0;
}

Complement layout with CSS Float

The main key towards successful lying of two-column form is to float the label element.

For example,

form label {
    display: block;  /* block float the labels to left column, set a width */
    float: left;
    width: 150px;
    padding: 0;
    margin: 5px 0 0; /* set top margin same as form input - textarea etc. elements */
    text-align: right;
}

This code above will create a two-column layout using input elements and label.

Jan 8, 2008 Linkage – Accessible Forms

Here are some tutorials and articles that can help you to build your forms to be more accessible. You can get the basic ideas out of the the links below.

Form Layouts

Laying out a form can be highly interesting. Specially with CSS formula applied to it, these forms can create a difference to the design of the website. For each of the form element in a left-to-right reading system, it becomes logical to position the corresponding label in one of the three ways:

  • In a separate left column, left aligned
  • In a separate left column, right-aligned
  • Directly above the form element

Labels that are positioned directly above a form element have shown to be processed most swiftly by the users. The compact grouping between label and element decreases eye movement thereby allowing the user to observe both of it simultaneously. Labels that are positioned in a column to the left of the elements look far more organized and neat. However, the way in which the texts in those labels are aligned also affects the usability of the form.

Following screenshot will show how it looks when labels are positioned directly above a form element:

clip_image002.gif

A far stronger grouping can be possible between label and element by right-aligning the text. The ragged left edge of the labels can make the form look disturbed and decrease the ability of users to scan the labels by themselves. But in a left-aligned column, the labels become instantly easier to scan, but the grouping with associated form elements become weaker. But users have to spend some more time correlating the labels with elements, resulting in slower form completion method.

clip_image003.gif

The right aligned column layout allows swifter association between label and element, so it becomes highly appropriate for forms that will be visited repeatedly by the users. However, both the layouts have the benefits of occupying minimum amount of vertical space.

clip_image001.gif

sIFR – Make Your Headlines Prettier with Flash

sIFR (or Scalable Inman Flash Replacement) is a technology that allows you to replace text elements on screen with Flash equivalents. sIFR is the result of many hundreds of hours of designing, scripting, testing, and debugging by Mike Davidson and Mark Wubben. Mike, Mark and an invaluable stable of beta testers, supporters, and educators like Stephanie Sullivan and Danilo Celic of Community MX completely rebuilt a DOM replacement method originally conceived by Shaun Inman into a high quality cross-browser, cross-platform typography solution for the masses.

You can find the stable version of sIFR 2.0 on Mike Davidson’s Blog. Also there is sIFR 3.0 which still in beta but provides some better font rendering from the previous versions [sIFR 3.0 beta]

  Subscribe to our RSS Feed   Follow us on Twitter

You've arrived on the "Advanced CSS/HTML Explained" weblog. Here you will find how can you tackle the more difficult topics of Cascading Style Sheets: Floating theory, Forms, Tables, Navigation elements, CSS Positioning. Also you will find lots of Resources, Tutorials, Articles, and Tips, Tricks Tools, and Techniques on CSS.

Recent Posts

Categories

Twitter Updates

Bookmark and Share