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

  • SEARCH
  • Home
  • 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 7640481
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T08:40:54+00:00 2026-05-31T08:40:54+00:00

I have a drop down menu using CSS only. I want the drop down

  • 0

I have a drop down menu using CSS only. I want the drop down to have automatic width but it takes on the width of its parent (as expected).

What is the best method to get it to have automatic width? (i.e ignore its parents width) without defining a set width.

Here it is on jsfiddle

nav{ background: #000 ; clear: both ; height: 40px ; padding: 0 10px ; }
nav ul{ list-style: none ; }
nav li{ float: left ; position: relative ; }
nav a{ display: block ; float: left ; color: #fff ; text-decoration: none ; padding-right: 30px ; font-size: 120% ; line-height: 40px ; }
nav div{ display: none ; position: absolute ; background: red ; left: 0 ; top: 40px ; }
nav li:hover div{display: block ; }
<nav>
    <ul>
        <li><a href="#">Home</a>
            <div>
                <p>example of width not working</p>
            </div>
        </li>
        <li><a href="#">next</a>
            <div>example</div>
        </li>        
        <li><a href="#">again</a>
            <div>example</div>
        </li>
    </ul>
</nav>    

If it’s not possible with CSS, a Javascript/Jquery solution would suffice.

  • 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-05-31T08:40:55+00:00Added an answer on May 31, 2026 at 8:40 am

    Try using white-space: nowrap; on the element that shouldn’t go to the next line.
    It will keep all the words on the same line and not break into a new line so that it takes automatic width.

    In your jsfiddle: http://jsfiddle.net/8BV2N/4/

    Also; it is considered best practise to use another ul for your submenu instead of a div. this way search engines can understand the structure of your website better.

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

Sidebar

Related Questions

I have got a drop down menu which works fine but i want to
im using a joomla 1.6.4 install and have a custom css/javascript drop-down menu in
Stack, I'm having difficulty creating a good drop down navigation menu using only css.
I have created a drop down menu using JQuery but when I test it
Hi, I'm doing a drop down menu in HTML/CSS the normal way; i.e., using
I am using the css/javascript drop-down menu from this page: http://javascript-array.com/scripts/simple_drop_down_menu/ Though I would
I am using the following well-known CSS code to get a drop down menu
I have a drop down menu created purely with CSS. I would like to
I have a drop-down/multi-level CSS menu on a page. The menu however doesn't appear
I have a drop down menu and it works perfectly on everything except IE6

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.