Foundation of css dropdown menu
Whether you're a seasoned veteran or a struggling beginner, Web Radiance is the web development and web design forum for you. You'll find answers to all your HTML, CSS, SEO, and Programming needs. Pull up a chair and stay awhile.
Foundation of css dropdown menu
#1
Posted 15 February 2007 - 07:10 PM
#2
Posted 15 February 2007 - 09:00 PM
(example code used from the suckerfish menu)
<li><a href="#">Percoidei</a> <ul> <li><a href="#">Remoras</a></li> <li><a href="#">Tilefishes</a></li> <li><a href="#">Bluefishes</a></li> <li><a href="#">Tigerfishes</a></li> </ul> </li>
Giving something like this if the list was used without css:
- Percoidei
- Remoras
- Tilefishes
- Bluefishes
- Tigerfishes
- Remoras
javascript menus are diverse per application as to how they work. but generally, they are constructed in a similar fashion. often, they use arrays to store the menu items, which are lists for a language, displaying the correct sub menu item when needed. usually, these are build in javascript files (*.js) and are included into the page, so they're not generally good with SEO, as the menu is built by the users browser and its not static html. (if you need more clarification on this ask..)
some javascript menus do use lists, and only use javascript for fancy moving effects that css couldn't ever achieve.
#3
Posted 15 February 2007 - 09:24 PM
http://meyerweb.com/...menus/demo.html
Thank you.
#4
Posted 16 February 2007 - 12:36 AM
ul#topmenu > li:hover > ul {
width: 10em;
top: 1.5em;
left: -3px;
}
starting from the top, ul is the tag <ul> (unordered list), and # means id (as in <div id=name" etc). so, the first line means apply the style (which is about to follow) to any unordered list with the id topmenu.
the > means in, so moving along the line.. li (obv, <li> - list item) and :hover. which is a link state (there are :hover, :active, and :visited, pretty self explanatory). so it means, that this list item must have a link, and this action is applied on the hover, of that link.
a further > means that it holds an <ul> again. so the html will most likely look something like..
<ul id="topmenu"> <li><a href="#"> link name</a> <ul> <li>i reckon a menu link will go here</li> </ul> </li> </ul>
so, recapping, thi segment of css means, apply this style to an <ul> which has an id of topmenu, and has in it a list, with a link (on hover) with another <ul> inside it.
work systematically, remember the > means "it holds"
hope that helps =)
#5
Posted 16 February 2007 - 08:48 AM
Sam, you asked what the ">" does as a CSS selector, and here is a brief explanation:
div#leftColumn p {color: red;}
The above CSS will turn every paragraph element inside "leftColumn" into red text.
div#leftColumn > p {color: red;}
The above CSS will turn only child paragraph elements inside "leftColumn" into red text.
So, for example, if you had this xhtml...
<div id="leftColumn"> <p>This is paragraph number one</p> <p>This is paragraph number two</p> <div class="highlightBox"> <p>This is paragraph number three</p> </div> </div>
...the first two paragraphs are considered "children", because they are directly within the div#leftColumn. The third paragraph is even deeper in the hierarchy, so it isn't considered a child. If you chose to use the first instance of CSS at the top of this reply, then all paragraph elements would have red text. Otherwise, if you chose to use the second instance of CSS at the top of this reply, only the first two paragraphs would have red text.
When an element is directly within another, it is called a "child". Much like you are the child of your parents. But when an element is deeper than that, it is referred to as a descendant, much like your own children will not be children of your parents, but descendents of them instead.
#6
Posted 16 February 2007 - 09:59 AM
<div id="leftColumn"> <p>This is paragraph number one</p> <p>This is paragraph number two</p> <div class="highlightBox"> <p>This is paragraph number three</p> </div> </div>
Example 1 --------------------------------------------------
If you use
div#leftColumn p {color: red;}
then your output would look like this:This is paragraph number one
This is paragraph number two
This is paragraph number three
---------------------------------------------------------------
Example 2 --------------------------------------------------
Where as if you use
div#leftColumn > p {color: red;}
then your output would look like this:This is paragraph number one
This is paragraph number two
This is paragraph number three
---------------------------------------------------------------
Hopefully that helps a little bit.
#7
Posted 16 February 2007 - 11:47 AM
#9
Posted 17 February 2007 - 08:32 PM
#10
Posted 19 February 2007 - 02:45 AM
#11
Posted 19 February 2007 - 08:38 AM
#12
Posted 19 February 2007 - 01:34 PM
You will find if you utilize a browser specific style sheet (one aimed at IE7 only), you can adjust some of the spacing and margins for that particular browser.
My guess is that some of the numeric values need to be adjusted in the CSS for IE7 only, most likely reducing the amount of space between the horizontal navigation bar, and the drop-down list that appears. If you can find, in the CSS, the particular number that determines the distance (probably something like "top:20px:", or "margin-top:20px;", etc.), you would just reduce the numberic value within a style sheet aimed at IE7 only.
If you stick this code at the top of your web pages, directly underneath your current CSS code, it allows you to use a new stylesheet for IE7 adjustments, and whatever you put inside of it will be applied only to IE7:
<!--[if IE 7]> <link rel="stylesheet" type="text/css" href="styles/ie7-only.css" media="screen, print" /> <![endif]-->
#13
Posted 19 February 2007 - 01:52 PM
The best piece of code I know to do this if from YUI: http://developer.yahoo.com/yui/reset/
#14
Posted 19 February 2007 - 03:57 PM
TJSingleton, on Feb 19 2007, 01:52 PM, said:
The best piece of code I know to do this if from YUI: http://developer.yahoo.com/yui/reset/
The one I wrote is good too
#15
Posted 19 February 2007 - 04:53 PM
Edit : never mind. I was able to stop that by making a border. I am not sure this is the right approach but I was able to achieve what I wanted. I was cartwheeling having constructed a dropdown menu only to see my excitement come crashing down when I loaded up the page in IE6. It does not show anything more that the first level. I hate IE
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>dropdown model</title>
<style type="text/css">
<!--
* {
text-decoration: none;
margin: 0px;
padding: 0px;
border-style: none;
}
#topnav {
width: 400px;
list-style: none;
text-align: center;
}
#topnav > li {
width: 98px;
margin: 1px;
float: left;
background: #FFCCFF;
}
#topnav li ul {
display: none;
}
#topnav li:hover ul {
display: block;
}
#subnav {
width: 400px;
list-style: none;
margin-left: -201px;
margin-top: 2px;
background: none;
}
#subnav li {
width: 98px;
float: left;
margin: 1px;
background:#00FFFF;
}
-->
</style>
</head>
<body>
<ul id="topnav">
<li>Main1</li>
<li>Main2</li>
<li>Main3
<ul id="subnav">
<li>Sub1</li>
<li>Sub2</li>
<li>Sub3</li>
<li>Sub4</li>
</ul>
</li>
<li>Main4</li>
</ul>
</body>
</html>
This post has been edited by sam: 19 February 2007 - 07:39 PM
#16
Posted 19 February 2007 - 08:44 PM
#17
Posted 19 February 2007 - 09:52 PM
herkalees, on Feb 19 2007, 03:57 PM, said:
Yours is nice, but it doesn't effectively neutralize the default browsers styles. YUI is a bit more comprehensive. Check it out. Create a basic html doc, with and compare the your stylesheet with YUI's.
#18
Posted 24 September 2011 - 01:22 PM
#19
Posted 19 December 2011 - 10:54 AM
James Mitchell, on 16 February 2007 - 09:59 AM, said:
<div id="leftColumn"> <p>This is paragraph number one</p> <p>This is paragraph number two</p> <div class="highlightBox"> <p>This is paragraph number three</p> </div> </div>
Example 1 --------------------------------------------------
If you use
div#leftColumn p {color: red;}
then your output would look like this:This is paragraph number one
This is paragraph number two
This is paragraph number three
---------------------------------------------------------------
Example 2 --------------------------------------------------
Where as if you use
div#leftColumn > p {color: red;}
then your output would look like this:This is paragraph number one
This is paragraph number two
This is paragraph number three
---------------------------------------------------------------
Hopefully that helps a little bit.
yup, this part made me understood what was being talked about here..


Help
MultiQuote










