473,411 Members | 1,997 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,411 software developers and data experts.

Lining up navigation menu

TheServant
1,168 Expert 1GB
Hi guys,
While starting my layout from scratch, I have come up against something that is taking me a long time to figure out and I can't find exactly what I want on google. Here is the html layout:
Expand|Select|Wrap|Line Numbers
  1.     <div id="top_menu">
  2.         <div id="nav">
  3.             <ul>
  4.                 <li><a href="#">Home</a>
  5.                     <ul>
  6.                         <li><a href="#"><span>Home</span></a></li>
  7.                         <li><a href="#"><span>Forums</span></a></li>
  8.                     </ul>
  9.                 </li>
  10. ...
  11.             </ul>
  12.         </div>
  13.     </div>
Here is my CSS:
Expand|Select|Wrap|Line Numbers
  1.     #top_menu {
  2.         height: 60px;
  3.         width: 100%;
  4.         overflow: hidden;
  5.         margin: 0 auto;
  6.         background: gray url(top_menu_bg.png) repeat-x;
  7.         display: block;
  8.         text-align: center;
  9.         border: 2px gray ridge;
  10.         border-left: none;
  11.         border-right: none;
  12.         font-size: 16px;
  13.     }
  14.         #nav {
  15.             width: 100%;
  16.         }
  17.         #nav ul {
  18.             width: 800px;
  19.             margin: 0 auto;
  20.             display: block;
  21.         }
  22.         #nav ul ul {
  23.             font-size: 14px;
  24.             margin-top: 10px;
  25.         }
  26.         #nav ul ul li {
  27.             display: none;
  28.             height: 20px;
  29.             float: left;
  30.             width: 100px;
  31.             padding-top: 5px;
  32.         }
  33.         #nav ul li {
  34.             height: 30px;
  35.             width: 150px;
  36.             padding-top: 5px;
  37.             float: left;
  38.             list-style: none;
  39.         }
  40.         #nav ul li:hover ul li {
  41.             display: block;
  42.         }
  43.  
Quite simple, the list is horizontal and once the top list is hovered upon, the bottom list is displayed (which changes for each top list item selected). I am trying to line the bottom list to be under the top list to the left most. If I use position:absolute left:0 it will align to the left of the screen, not the div (800px in the center). I cannot use a negative margin because it will vary in magnitude, and I would prefer not giving id's to every item.
If that doesn't make sense, here is my site and if you just hover on the links you will see what I mean.

Thanks for your help.
Feb 22 '09 #1
10 2064
hsriat
1,654 Expert 1GB
Try this:

HTML:
Expand|Select|Wrap|Line Numbers
  1. <div id="nav">
  2. <div id="nav_wrapper">
  3.     <ul id="rootul">
  4.         <li>
  5.             <!------>
  6.         </li>
  7.     </ul>
  8. </div>
CSS:
Expand|Select|Wrap|Line Numbers
  1. #nav_wrapper {
  2.     width: 800px;
  3.     margin: 0 auto;
  4. }
  5. #nav ul {
  6.     margin: 0;
  7.     display: block;
  8.     text-align: left;
  9.     padding-left: 75px;
  10. }
  11. #nav ul ul {
  12.     width: 1024px;
  13.     font-size: 14px;
  14.     margin-top: 10px;
  15.     padding-left: 0px;
  16. }
  17. #nav ul ul li {
  18.     display: none;
  19.     height: 20px;
  20.     float: left;
  21.     width: 100px;
  22.     padding-top: 5px;
  23. }
  24. #nav ul li {
  25.     height: 30px;
  26.     width: 145px;
  27.     padding-top: 5px;
  28.     float: left;
  29.     list-style: none;
  30. }
  31. #nav ul li:hover ul li {
  32.     display: block;
  33. }
This won't look good if you have to give background colour to the menu items.
Feb 22 '09 #2
David Laakso
397 Expert 256MB
This [1] will give you a base to work from. Just use one drop-down-- eliminate the fly-out, drop down...
[1]http://sperling.com/examples/menuh/
Feb 22 '09 #3
TheServant
1,168 Expert 1GB
Thanks for your suggestions, I will try it out when I get home and keep at it. Unfortunately I will have to give backgrounds to the menu items eventually, so might have to teak hsriat's code. David, the problem with that base to work from is that it suffers from the same issue mine has (with the lists forming directly underneath their parents).

Is it possible to use css to change a property of an item, if that item is not a child?
As in can I have two divs (same level) and have something like:
Expand|Select|Wrap|Line Numbers
  1. #div1 {
  2. display: block;
  3. }
  4. #div2 {
  5. display: none;
  6. }
  7. #div1:hover #div2{
  8. display: block;
  9. }
With the html:
Expand|Select|Wrap|Line Numbers
  1. <div id="div1">
  2. <p>Div 1 Content</p>
  3. </div>
  4. <div id="div2">
  5. <p>Div 2 Content</p>
  6. </div>
I know it can be done with javascript, but is there a way to do it in only CSS?
Feb 22 '09 #4
hsriat
1,654 Expert 1GB
@TheServant
Just try to use a combination of negative margin and positive padding (same value) for ul ul li.
Feb 22 '09 #5
David Laakso
397 Expert 256MB
Maybe this will work for you [1]? As for myself I could care less whose code you use. Name of the game is resolve a problem. Easiest way to do that is to keep it simple. Sometimes that means changing the game plan-- hence the simple solution sent earlier...
[1] http://www.tjkdesign.com/articles/ne...wn/default.asp
Feb 22 '09 #6
TheServant
1,168 Expert 1GB
Awesome link David, that's what I was after, will be going through that as soon as I have time. Thanks heaps. So is that a no on my previous qeustion?
Feb 23 '09 #7
David Laakso
397 Expert 256MB
Good luck. It ain't gonna be easy to pull that off even with TJK's code.

Aside: I don't know what previous question you are referring to and since I am of simple mind and have a little difficulty understanding all your questions, I will defer to someone else to answer them...
Feb 23 '09 #8
TheServant
1,168 Expert 1GB
I agree, after looking through TJK's code its still going to require a bit of work, but I am sure there's a workable solution. I apologise for not being clear, but to re-state my question:

@TheServant
Feb 23 '09 #9
David Laakso
397 Expert 256MB
CSS copes with appearance (the way things look) rather than the way they behave. You'll need scripting to create the behavior you seek...
Feb 23 '09 #10
TheServant
1,168 Expert 1GB
Thanks for your help again.
Feb 23 '09 #11

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: Dave Patton | last post by:
Using my About page as an example: http://members.shaw.ca/davepatton/about.html What is the best/proper way to markup a page such as this that has "the main body" and "a navigation menu"? It...
22
by: Marek Mand | last post by:
How to create a functional *flexible* UL-menu list <div> <ul> <li><a href=""></li> <li><a href=""></li> <li><a href=""></li> </ul> </div> (working in IE, Mozilla1.6, Opera7 (or maybe even...
3
by: eternalD3 | last post by:
Hi, I have a problem to get this working on Opera 7.x+. This does not need to work on older Opera browsers There are problems on rendering the sub-level navigation. It aligns right on Firefox...
0
by: Veli-Pekka Tätilä | last post by:
Hi, My first post here. I've found some serious accessibility flaws in the Python 2.4 docs and wish they could be rectified over time. I'm very new to Python and initially contacted docs at python...
2
by: Sisnaz | last post by:
I'm working with 2005 Beta 2 and I'm sure this is a trivial question but for the life of me I can't figure out. I placed a menu navigation componet on my master page and defined the navigation...
10
by: EA | last post by:
I am sure I must be missing something about building navigation bars with CSS. Yes it is a very clever and efficient way to format navigation structures on simple one navigation level webs, i.e....
4
by: tburger | last post by:
Hey everyone- This is my first post at The Scripts, but I've used the forums before for other programming issues. Hopefully, someone has some solid styling advice for me. I've now been dealing...
1
by: Fabx | last post by:
Hallo, sorry for my english. I want to build a navigation menu with the repeat control, the items of menu are in a table of database. All items of the menu have class="MenuLink", but the...
2
tharden3
by: tharden3 | last post by:
I have a question for you guys, I'm designing a website. Before I go any further, I'd like to get my navigation bars on the left side up and running. The site is themed to a bumblebee 'black and...
7
by: milestogofromhere | last post by:
It is late so this is probably something really obvious but I am not seeing it. Can someone please help? Here is the page in question: html - http://www.itsyourplate.com/index2.php css -...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.