Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8762803
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T15:37:30+00:00 2026-06-13T15:37:30+00:00

I am creating a center, nested navigation menu, and am trying to use pure

  • 0

I am creating a center, nested navigation menu, and am trying to use pure CSS. See a working demo HERE: http://jsfiddle.net/jenstechs/MKtTN/2/

enter image description here

HTML:

<nav>
  <ul id="primary">
    <li><a href="#">Link One</a></li>
    <li><a href="#">Link Two</a></li>
    <li><a href="#">Link Threee</a>
        <ul class="secondary">
            <li><a href="#">Services One</a></li>
            <li><a href="#">Services Two</a></li>
        </ul>
    </li>
    <li><a href="#">Link Four</a></li>
    <li><a href="#">Link Fiiiiive</a></li>
  </ul>
</nav>

CSS:

nav {
  margin:15px auto 10px auto;
  width:100%;
}

nav ul#primary {
  width: 100%;
  padding: 10px 0;
  margin: 0;
  background-color: #FFF;
  text-align: center;
}

nav ul#primary>li {
  display: inline;
  padding:5px 0;
  margin-left:0;
}

nav ul#primary>li>a {
  padding: 0px 30px;
  margin-right:-6px;
  color: #000;
  text-decoration: none;
  border-right:2px solid #999;
}

nav ul#primary>li>a:hover,
nav ul#primary>li.active>a {
  background-color: #900;
  color:#FFF;
  padding-top:10px;
  padding-bottom:25px;
}

nav ul#primary>li:first-child a {
    border-left:2px solid #999;
}

ul.secondary { 
    padding-top:0;
    position:absolute;
    display:none;
}
ul.secondary li {
}

nav ul#primary li:hover ul.secondary {
    display:block;
}
nav ul#primary li:hover ul.secondary li {
}

ul.secondary li a {
    display:block;
    width:7em;
    color:#FFF;
    background-color:#900;
    font-size:0.8em;
    text-decoration:none;
    text-align:left;
    line-height:1.4em;
    border-bottom:1px solid #FFF;
}

ul.secondary li:last-child a {
    border-bottom:0;
}

ul.secondary li a:hover {
    color:#DDD;
}
​

I also have a minimal reset, the only styles it has on lists is a few default margins.

Since this is a centered navigation bar, the CSS I’m using is inline, not floated. So I have no idea what to put in the CSS to position the sub-menu actually underneath its parent element. Most examples I’ve seen have position:absolute but that seems to keep it at the left. I’ve tried various methods of hiding and showing (display:, left:) but can’t seem to find that magic combination.

Here I only have the one sub-list, actually, but what if I had sublists for all of them?

Thanks for any tips or links to examples…

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T15:37:31+00:00Added an answer on June 13, 2026 at 3:37 pm

    To make position: absolute elements position relative to their parent, make the parent position: relative.

    In your case:

    nav ul#primary>li {
      display: inline;
      padding:5px 0;
      margin-left:0;
    
      position: relative;
    }
    

    Demo: http://jsfiddle.net/MKtTN/3/

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Creating a server-side socket will fail if I'm trying to use the same port
Getting an error message Nested functions are disabled, use -fnested etc in XCode/ObjC. Here's
What is the best approach for creating a 3 section (left, right, center) report
Creating a simple RPG game, first time using XNA. Trying to get my character
I'm creating the perspective projection like this: function quickViewMatrix( pos, center, w, h )
I am creating an application using Griffon->SwingBuilder. I would like to able to center
I have a problem creating a decent header in CSS. What I want is
I'm creating a horizontal menu bar. There is an outer div that contains inner
I am creating these icons as an image wrapped with a CSS circle behind
I am creating a image view. but my image is displaying in center and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.