Nov 21, 2009

Creating A Css Rollover Menu (with Table Cells) - for those bandwidthed challenged

free web hosting
Open Discussion & Free Web Hosting > Computers & Tech > How-To's and Tutorials > Websites and Web Designing

Creating A Css Rollover Menu (with Table Cells) - for those bandwidthed challenged

Mahzian
Ive found this code very usefull when it comes to clients who cant afford Flash (and I hate JavaScript rollovers as they only work half the time and when you hold the mouse over the button for 5 seconds) When your done here you should be able to create a menu that looks like the following:

click here to see what it looks like

Step 1: setting up the framework

Get the framework in there for the script to work , I generally link to my stylesheets externally so I will show you how. Now open a simple text editor such as Notepad.

set up your page with the following basic html

CODE
<html>
<head>
</head>
<body>
</body>
</html>



Now save the file somewhere as a html file , for example test.html




Step 2: linking the stylesheet

Now the following string must be put in between the <head> and </head> tags

CODE
<LINK href="rollovers.css" type="text/css" rel="stylesheet">


Now remember the section after the href , because this name (rollovers.css) is what your external stylesheet will be named. (You can call it whatever you want but remember to save the file later to that name.)



Step 3: creating the stylesheet

Now you have the html file pointing to a stylesheet but it doesnt exist , we need to create it. This is simply done by (for example in notepad) going to File>New and then saving the file as rollovers.css (remember if you changed this name in step 2 change it here also)

Save this file in the same directory as the html file

Step 4: creating the table

Now we need to create a table in that html file we had before , so if your still on the css file , close it and open test.html or whatever you named it.

Between the <body> and </body> tags type the following:

CODE
<table width="20%" cellpadding="0" cellspacing="0" border="0" summary="">
<tr>
<td width="100%" id="LHS">
</td>
</tr>
</table>


What you have done is created a table with 1 cell which is 20% the width of the page and has a css id of LHS



Step 5: creating the links

Now this will vary on how many links you need/want but in this example we need 5 links. This is simply done by inserting links into the td cell of the table. For example:

CODE
<table width="20%" cellpadding="0" cellspacing="0" border="0" summary="">
<tr>
<td width="100%" id="LHS">
<a href="hello.html">hello</a>
<a href="this_is.html">this is</a>
<a href="a_rollover.html">a rollover</a>
<a href="menu_made.html">menu , made</a>
<a href="with_css.html">with css</a>
</td>
</tr>
</table>


Each link is part of the same ID so each will look the same.



Step 6: creating the css

This can be abit confusing if you are not used to dealing with css but I will try and go through it as simple as I can.

Its time to close the html file and open the css file again. This should be blank with no text yet on it whatsoever.

Now in my example I applied a style to the <body> tag of my html file which makes the background black , I did this with the following code:

CODE
body {
 background-color: #000000;
 }


Its up to you if you want to put this in and what color you want.


Now we have to create normal CSS links (like text links). This is done with the following code:

CODE
a:link, a:active {
[tab][/tab]/*color: #92A92D;*/
[tab][/tab]/*color: #002A6C;*/
[tab][/tab]font-family: Verdana, Arial, Helvetica, sans-serif;
[tab][/tab]font-size: 11px;
[tab][/tab]color: #C41427;
[tab][/tab]text-decoration: none;
}

a:visited {
[tab][/tab]/*color: #92A92D;*/
[tab][/tab]/*color: #002A6C;*/
[tab][/tab]font-family: Verdana, Arial, Helvetica, sans-serif;
[tab][/tab]font-size: 11px;
[tab][/tab]color: #C41427;
[tab][/tab]text-decoration: none;
}

a:hover {
[tab][/tab]/*color: #CD689D;*/
[tab][/tab]color: #C41427;
[tab][/tab]/*font-weight: bold;*/
[tab][/tab]text-decoration: underline;
[tab][/tab]font-family: Verdana, Arial, Helvetica, sans-serif;
[tab][/tab]font-size: 11px;
}


Now the options in that code should be pretty obvious , you can change the fonts/colors etc to what you want. These styles are for the text that will be inside the boxes. Please Note: remember to keep the visited tag above the hover tag or the hover tag wont work


Step 7: creating the ID links

Keep that CSS file open because we arnt done with it yet. Now what we need to do is create some ID's so we can asign different colors etc to the links. This is what the ID was for in the table we created before. Put the following code into your CSS file:

CODE
#LHS a {
[tab][/tab]margin-left: 12px;
[tab][/tab]margin-bottom: 2px;
[tab][/tab]border: solid 2px #C41427;
[tab][/tab]background-color: #FFFFFF;
[tab][/tab]color: #000000;
[tab][/tab]font-variant: small-caps;
[tab][/tab]font-weight: normal;
[tab][/tab]width: 170px;
[tab][/tab]padding: 5px;
[tab][/tab]padding-top: 3px;
[tab][/tab]padding-bottom: 3px;
[tab][/tab]display: block;
}


#LHS a:hover {
[tab][/tab]background-color: #C41427;
[tab][/tab]color: #FFFFFF;
[tab][/tab]text-decoration: none;
}


The # denotes that this style is an ID (which can be applied to our table). Using this method you can get more than one set of link styles onto a page , this is handy because sometimes your menu is a different color to your body etc.

Now you can play around with all the options there , if you change padding and the width you can make it smaller/bigger as needed. Hover tag will retain whatever options are missing from the a tag and only change the options which are there (like background-color for example)


Save the css file , and open the html file in your browser , and voila , you have a very bandwidth friendly menu. Try changing the colors around and some of the size options and switch between refreshing the browser and the text css file , but remember the changes wont take effect till the css file is saved!

Let me know if you have any problems/issues! smile.gif

 

 

 


Comment/Reply (w/o sign-up)

roger4
Good turtorials thank you ~.I think it's will be good for the newbie webdisigner.~

Comment/Reply (w/o sign-up)

m3ch4
Newb question here, please don't kill me =S

when you refer to css links you mention this within the code section...

*
font-family: Verdana, Arial, Helvetica, sans-serif;
font-size: 11px;
*

just curious, but what exactely does font-family refer to? what other options are available and what is the font is used in the final display?

also, for font-size, how does that relate to the font sizes that are regularly used in html code? is the pixel reference simply something that is left out in the html or does this font-size use a different scale/size then regular html code?

Comment/Reply (w/o sign-up)

chiiyo
Okay, by font-family, that is basically listing down the font of your text, whatever text that is being listed. As for options, you can put in any font you like, only that you must know if you put a font that is not common, many people will be seeing your site in a font you didn't design for. Previously, in html, you could only specify one font, so if the end-user didn't have that font, he would be stuck seeing your website in his computer's default font, which more often than not is Times New Roman (yuck). So CSS counteracts that, creates a situation where your website degrades gracefully, by allowing you to list other fonts. In this case, you're telling the end-user's computer to display the text first and foremost in Verdana, but if the computer doesn't have Verdana, to display the text in Arial, and if the computer doesn't have Arial, to display it in Helvetica (which is, by the way, a gorgeous font), and if the computer doesn't have any of those three, in any sans-serif font. This way you cover all bases. So yes, the first font is the top-priority font.

About font-size, the ones used in html code are different from the one you define in font-size. The numbers in html point to a particular size, set in html, and I'm actually not too sure what that size is, but there are usually only 6 numbers? 1 to 6? (haven't used the font tag for so long...) What happens in CSS is that you can fine-tune that size of your font. Instead of relying on arbitrary values, you can define the font in pixels (px), ems, points(pt) and other measurements.

BTW, the font tag is deprecated as of XHTML 1.0 Strict, so you should use CSS to do your font-styling. Read more about it at HTMLDog.

Hope this helps!

 

 

 


Comment/Reply (w/o sign-up)

m3ch4
*glances at clock and decides to turn in for the night*

*bookmarks www.htmldog.com (hi5 Chiiyo, thanks!)*

one more quick question, from the looks of the css code I'm curious as to how complex it gets and what kind of stuff it can do.

for example, I want to create a table...

________________
| cell1 | cell2 | cell3 |
-----------------------
| cell 4 ...................|
-----------------------

...like so, where cell 1,2,3 will be selectable (say, clicked/unclicked) and the selections there will change the output in cell 4.

can something like that be programmed in css?

I'm curious because css looks super light weight, and if it's possible to do something like that through css as opposed to javascript I'd be really interested. Witht this amount, or more, of complexity like this will css remain lightweight and be preferable to javascript?

...or if looking for an alternate to javascript seems ridiculus and css isn't as lightweight as it appears from this tuturial please feel free to poke me a sharp stick.

Comment/Reply (w/o sign-up)

chiiyo
Hmm. You can use CSS for the basic layout of that table (because technically using tables to layout non-tabular data violates the whole separation of content and presentation idea).

One way to do the whole click 1 or 2 or 3 and 4 will change, the easy but less advanced way, would be to make three html pages, where clicking 1 would lead to page 1, where your 1 would be "selected" and your 4 will reflect the content required, and then creating similar pages for 2 and 3.

Another way to do it, would probably involve either javascript or PHP. The javascript method I'm not too sure, not a big fan of javascript, but basically you have to program the links in 1,2, and 3 to be able to affect the behaviour in 4. (Not too sure what I'm saying.... anyone want to clarify this?)

And the third method, by using PHP includes, whereby you program the links in 1, 2 and 3 to trigger another page to be included using PHP into 4. That way you have one page. Kinda works like a frame.

Ah, and of course, you could use frames. But wouldn't recommend it.

I would probably recommend a combination of the CSS and PHP method, it's probably the most lightweight method around...

Don't mention it! Glad to help!

Comment/Reply (w/o sign-up)

m3ch4
QUOTE (chiiyo @ May 2 2005, 08:15 AM)
Ah, and of course, you could use frames. But wouldn't recommend it.

I would probably recommend a combination of the CSS and PHP method, it's probably the most lightweight method around...

Don't mention it! Glad to help!
*


Yeah, frames I'm gonna leave alone right now...might end up going back to it, but I hope not =S

The reason I'm curious about css is that I plan to have a table like that on my site, and a friend of mine was going to program in in javascript for me. He's picking up as many programming languages as he can and said he'd be interested in any type of projects that I could give like this so he could have some non-generic stuff to program to help keep his interested. The thing is he does't know for sure whether he's going to pick up js, that being my concern and my source of questions =/

thanks again for your advice! much appreciated =)

Comment/Reply (w/o sign-up)

finaldesign
Very nice tutorial man! I'll give ya some reputation, I made some similar menu on My Webpage but anyway this is a good start point for anyone who want's to make a page with fast loading menus...

Comment/Reply (w/o sign-up)

johnny
QUOTE (finaldesign @ May 3 2005, 08:11 AM)
Very nice tutorial man! I'll give ya some reputation, I made some similar menu on My Webpage but anyway this is a good start point for anyone who want's to make a page with fast loading menus...
*

I like your menu its pretty good it's just a little different from the one he was showing us up there in the tutorial. I mean, if it was me i thnk i would do it in flash but doing it in scripting would be good too

Comment/Reply (w/o sign-up)

vujsa
Nice tutorial.

I wanted to mention that you can use images for the menu item backgrounds as well.
  1. Create an image that is twice the height of the menu item.
  2. Design the top half of the image as the default background of the menu item.
  3. Design the bottom half of the image to be the background of the menu item during rollover.
  4. Now for you CSS link attribute, set the background image to the new image.
  5. In the CSS for the hover (rollover) set it to the new image but specify the position to show only the bottom half of the image.

This is the technique used for the menus on the default Mambo template (SolarFlareII).

Hope this helps. cool.gif

vujsa

Comment/Reply (w/o sign-up)


Got an Opinion! Express your Views! (no registration):-
Add your Reply/ Opinion/ Views/ Comments/ Suggestion/ Questions/ Queries etc.
Posts with decent grammar & English will be accepted and please refrain from profanities.
For asking a Question, We recommend you to sign-up (for free) so that you can track the topic easily.

Nature of your Post*: Opinion/ Reply/ Comments
Question/Query
Feedback to us.
       
Name   Email
Title/Question*

This textarea will convert to Rich-Text automatically (IE, Firefox, Chrome)

Similar Topics

Keywords : creating, css, rollover, menu, table, cells, bandwidthed, challenged

  1. How To Build A Pure Css Using Online Tools Tutorial (part 4)
    Step 4 Vertical Nav Menu (1)
  2. Creating Your Own Simple But Effective Site
    To be resumed soon (26)
    Creating your own UKISS site from beginning to end Contents So that you know
    what is happening and when I’ve compiled this contents section. It will also help you got to
    the parts that you need without scrawling through everything. Introduction Design Step 1
    – Starting Fireworks and creating your canvas Step 2 – Making a base on which to work
    on Step 3 – Head’s up; start with the logo Step 4 – Finding your way;
    creating a menu Step 5 – Eyes to the centre; work on the main column Step 6....
  3. Ssi
    Combine a navigation menu with content.. (0)
    -------------------------------------------- INTRO --------------------------------------------
    QUOTE(http://www.xantansnest.com/pw/ssi_syntax.shtml) Do you have a website, and you would like
    add a menu / navigation bar on every page? Well, there are a few options, you can use ugly frames
    (which many people don't like) or you can add a navigation bar on every page. But if you would
    like to change it, you have to edit ALL the pages. Which is OK if you have a 5 page website, but
    once it starts to grow and you get 15 or more pages, it can prove to be quite the hass....
  4. Creating A Simple But Effective Website
    Part 1 - Design (10)
    WARNING: This is a VERY image heavy tutorial and will take time to complete Topic closed
    until I can find the time to complete it, and I am getting mad with the large scale plagrism of
    other articles. Also, the images will no longer work, as I have changed domain name and also
    removed the images to make space. Creating a basic but effective website For beginners
    Introduction: Ok, so maybe you want to make a website that is “worthy” of the web. That is to say,
    you have made small taster sites before in FrontPage or something basic like it. And realised t....
  5. Creating Rollover Images With Css
    Eliminate the need for Javascript (12)
    I have seen it reported that 10% of Internet users have Javascript disabled. Whether for security
    concerns or to curtail annoyances like pop-up windows, it seriously limits your ability, as a web
    designer, to mold your website into something creative and novel. This is where CSS rollovers come
    in. You know that effect you get when you roll the cursor over an image, and then the image changes?
    Traditionally, that effect has been accomplished by using Javascript to swap out images. I present
    here my own index page which has been made only with CSS and html. If you are u....
  6. Creating Tooltips
    DHTML, HTML, CSS, Javascript... (7)
    Here is a little tutorial to make those small yellow-background boxes (tootltips) that pop-up for
    some links that describe them when you hover the mouse over them, it uses DHTML, CSS, HTML, and
    Javascript, so it gives us a much more wide range than my previous tutorials that just where on
    HTML. OK, so here we go... Put this right under CODE var offsetxpoint=-60 //Customize x
    offset of tooltip var offsetypoint=20 //Customize y offset of tooltip var ie=document.all var
    ns6=document.getElementById && !document.all var enabletip=false if (ie||ns6) var tipobj=doc....
  7. Css Rollover Menu (with Background)
    bandwidth friendly rollover (0)
    Ive found this code very usefull when it comes to clients who cant afford Flash (and I hate
    JavaScript rollovers as they only work half the time and when you hold the mouse over the button for
    5 seconds) When your done here you should be able to create a menu that looks like the following:
    click here to see what it looks like Step 1: setting up the framework Get the framework in
    there for the script to work , I generally link to my stylesheets externally so I will show you how.
    Now open a simple text editor such as Notepad. set up your page with the following bas....
  8. Creating A Webpage Using Photoshop
    (4)
    I've read that this can be done with greater ease by using Ready Image, but since I'm more
    familiar with PS, I shall use PS as the guide. This guide does make a few assumptions :: 1) You
    already knew how to use Photoshop. 2) You already knew how to write HTML codes 3) You knew both of
    the above but did not ralise that it can be done .. Thus, I shall not touch on those 2 topics, as
    books a thousand pages thick have been written on them. So, I would wanna waste my time and yours
    and all the disksapce that could be used to host some useful stuff. 01:. Open the....
  9. Creating A Color Combination
    Guide to color combinations (18)
    Ever been to a website that is barely readable because of the bad color design? Well here's some
    tips to make sure that you don't fall into the same trap. * Black text on a white background,
    while not exciting, is the most practical color combination. * Try and not use more then four
    colors on your website, too many can be disorientating for the user. * Find out what each color
    represents to the users mind. For example green represents wealth while red represents daring. *
    Don't use yellow for web page backgrounds. * Take a look at Visibone or get a....
  10. Creating A Roll-over Effect With Text
    Save time and bandwidth-simple scripting (11)
    This short, but consise tutorial presents how to create a dynamic navigation bar using simple
    scripting verses using an image roll-over script. Using text instead of images offers 3 benefits
    while sacrificing only a little in design. The end resault is a navigation bar that looks great,
    dosen't bog the server down with images, loads fast, and is search engine friendly. In addition,
    you save time by not having to design two images for every link required. Using simple combination
    of Html, CSS, and Javascript we are able to create links in which both the color of th....
  11. Add Favicon To Your Site
    Creating, Converting to icon, Setup (39)
    Have you ever wondered how to get those icons displayed in your address bar for your own site? If
    you do not know what I mean, you could possibly have a browser that does not support favicon.ico or
    you just have not noticed. If you visit Google they should have a favicon in their address bar,
    if it's not displaying just goto this place to get the idea of what it would look like, but in
    your address bar, it should show just before the http part but sometimes it does not show so what I
    want to do is show you how you can force it to be shown on browsers that sup....

    1. Looking for creating, css, rollover, menu, table, cells, bandwidthed, challenged

See Also,

*SIMILAR VIDEOS*
Searching Video's for creating, css, rollover, menu, table, cells, bandwidthed, challenged
advertisement



Creating A Css Rollover Menu (with Table Cells) - for those bandwidthed challenged

Affordable Web Hosting, Low cost Web Hosting - ComputingHost.com