horizontal navigation bar using realitve position <li>

This is a discussion on "horizontal navigation bar using realitve position <li>" within the Web Page Design section. This forum, and the thread "horizontal navigation bar using realitve position <li> are both part of the Design Your Website category.



Go Back   Webforumz.com > Main Forums > Design Your Website > Web Page Design

Notices


Reply
 
LinkBack Thread Tools
  #1 (permalink)  
Old Nov 18th, 2007, 12:45
New Member
Join Date: Nov 2007
Location: fe
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Unhappy horizontal navigation bar using realitve position <li>

Hi everyone...
I am trying to follow this tutorial on list apart:
http://www.alistapart.com/articles/hybrid/
in order to create a very simple navigation with a horizontal main bar
containing categories, and a sub-categories list that is displayed when a category is hovered on.

Really straight forward so far. The problem is I cant get the sub-categories to float under the main ones, and instead they shift the main categories to the left when they are shown.
here is my css code:
Code: Select all
#nav li {
  /*float the main list items*/ 
  float: left;
  display: block;
  padding-right: 5px;
}

#nav li.off ul, #nav li.on ul {
  /*put the subnavs below and hide them all*/
  display: none;
   height: 60px;
}

#nav li.on ul {
  /*display active subnav list*/
  display: block;

}

#nav li.on ul a, #nav li.off ul a {
 
  /*ie doesn't inherit the float*/
  border: 0;
  width: auto;

}

#nav li.off:hover ul {
  /*  display the other topics when
      their parent is hovered */
  display: block;
  z-index: 6000;
}
and here is my html:
HTML: Select all
 <span style="float: left">Categories:&nbsp;&nbsp;  </span>
            <ul id="nav">
                        <li class="off">
                                 "Music"
                                <ul>
                                       
                                        <li>all</li>
                                        <li>"Electronic"</li>
                                </ul>
                        </li>
   
                       <li class="off">
                                "PC Games"
                             </li>
                             <li class="off">
                                "Xbox 360"
                             </li>
                  </ul>
      
This is not how it's really stylized at my end, but the problem is the same and this is the most basic css involoved. I have tried using position: relative on the elements but it doesn't work - only absolute positioning gets over the problem and I can't use it for various reasons.
Any ideas would be much appreciated!

Ehud
Reply With Quote

  #2 (permalink)  
Old Nov 18th, 2007, 14:34
SuperMember

SuperMember
Join Date: Sep 2006
Location: Pink House
Posts: 3,946
Thanks: 0
Thanked 0 Times in 0 Posts
Re: horizontal navigation bar using realitve position <li>

You are correct, the only way to get the sublinks to align below is to use absolute positioning.
If you set that entire navigation in a div that is aligned without any type of relative or absolute positioning, the rest of the design should be fine.

Here is your css:

Code: Select all
#container {
 /*set this to whatever you need*/
 width: 700 px;
 margin: 0 auto;
 }
 
#nav li {
  /*float the main list items*/ 
  margin: 0;
  float: left;
  display: block;
  padding-right: 5px;
}
#nav li.off ul, #nav li.on ul {
  /*put the subnavs below and hide them all*/
  display: none;
   height: 60px;
}
#nav li.on ul {
  /*display active subnav list*/
  display: block;
}
#nav li.off ul, #nav li.on ul  {
 
  /*ie doesn't inherit the float*/
  display: none;
  position: absolute;
  top:65px;
  height: 15px;
  left: 0;
  padding-top: 10px;
  
  
}
html

Code: Select all
<div id="container>
<h1>Categories</h1>
            <ul id="nav">
                        <li class="off">Music"
               <ul>
                <li>all</li>
               <li>"Electronic"</li>
                                </ul>
                        </li>
   
                       <li class="off">
                                "PC Games"
                             </li>
                             <li class="off">
                                "Xbox 360"
                             </li>
                  </ul></div>
Reply With Quote
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
horizontal list navigation breaks when load times are slow sch3dana Web Page Design 14 Mar 19th, 2008 12:56
[SOLVED] Horizontal Navigation Bar cshanks Web Page Design 5 Oct 3rd, 2007 15:31
CSS - Horizontal Scroll Bar Start Position???? jez Web Page Design 0 Jul 14th, 2007 09:05
IFrame left horizontal scrollbar and top horizontal scroll bar jadeite100 Web Page Design 6 May 29th, 2007 09:45
Horizontal CSS Navigation Lchad Web Page Design 7 Dec 5th, 2006 19:04


All times are GMT. The time now is 09:03.


Powered by vBulletin®
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC8
© 2003-2008 Webforumz.com : All Rights Reserved

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43