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 7866313
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T00:21:27+00:00 2026-06-03T00:21:27+00:00

I am learning to create CSS menus WITHOUT floats. I got a partially working

  • 0

I am learning to create CSS menus WITHOUT floats. I got a partially “working” menu so far. However, the main menu’s borders are separated. Also the submenu’s borders are sized in half and the hover’s background color is not working. At the same time, the sub-sub menu is not working

I am also trying to simplify the CSS code with a .menu .submenu .sub-submenu classes.

jsFiddle:
http://jsfiddle.net/vn64H/1/

HTML

<!DOCTYPE html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>Title: Navigation menu</title>

    <link rel="stylesheet" type="text/css" href="menu.css">
</head>
<body>

<!-- START: menu -->
<ul id="nav">
    <li class="menu"><a href="#">Home</a></li>
    <li class="menu"><a href="#">Main Menu 2</a>
        <ul class="submenu">
            <li><a href="#">Sub Menu 2.1</a></li>
            <li><a href="#">Sub Menu 2.2</a></li>
            <li><a href="#">Sub Menu 2.3</a>
                <ul>
                <li><a href="#">Sub-Sub Menu 2.3.1</a></li>
                <li><a href="#">Sub Menu 2.3.2</a></li>
                <li><a href="#">Sub Menu 2.3.</a></li>
                </ul>
            </li>
            <li><a href="#">Sub Menu 2.4</a></li>
            <li><a href="#">Sub Menu 2.5</a></li>
            <li><a href="#">Sub Menu, Some Sample Text  2.6</a></li>
            <li><a href="#">Sub Menu, Sample Text  2.7</a></li>
        </ul>
    </li>
    <li class="menu"><a href="#">Main Menu 3</a>
        <ul class="submenu">
            <li><a href="#">Sub Menu 3.1</a></li>
            <li><a href="#">Sub Menu 3.2</a></li>
            <li><a href="#">Sub Menu 3.3</a></li>
            <li><a href="#">Sub Menu 3.5</a></li>
            <li><a href="#">Sub Menu 3.6</a></li>
            <li><a href="#">Sub Menu 3.7</a></li>
        </ul>
    </li>
    <li class="menu"><a href="#">Main Menu 4</a>
        <ul class="submenu">
            <li><a href="#">Sub Menu 4.1</a></li>
            <li><a href="#">Sub Menu 4.2</a></li>
            <li><a href="#">Sub Menu Sample Text 4.3</a></li>
            <li><a href="#">Sub Menu 4.4</a></li>
            <li><a href="#">Sub Menu 4.5</a></li>
            <li><a href="#">Sub Menu 4.6</a></li>
            <li><a href="#">Sub Menu 4.7</a></li>
            <li><a href="#">Sub Menu 4.8</a></li>
        </ul>       
    </li>
    <li class="menu"><a href="#">Menu 5</a></li>
    <li class="menu"><a href="#">Menu 6</a></li>
    <li class="menu"><a href="#">Contact</a></li>
</ul> <!-- /#menu -->
<!-- END: menu -->


</body>
</html>

CSS

@charset "utf-8";
#nav {
    background-color: #000;
    position: relative;

    font-family: Arial, Helvetica, sans-serif; 
    font-size: 0.975em;
    text-align: left;
    display: block;
    border: 1px dotted #cccccc;
    padding: 0;
    margin: 0;
}
#nav a {
    color: #fff;
    text-decoration: none;
}
#nav li {
    color: #fff;
    text-align: left;

    width: 110px;
    border: 1px solid #CCCCCC;
    list-style-type: none;
    padding: 0;
    margin: 0;
    display: inline-block;
}

/*Sub menu */
#nav li ul {
    color: navy;
    text-align: left;
    list-style-type: none;

    width: 200px;
    border: 1px solid #000;
    padding: 0;
    margin: 0;

    display: none;
    position: absolute;
    background-color: #990000;
}
#nav li ul a {
    display: inline-block;
}
#nav li:hover ul {
    visibility: visible;
    display: block;
    background-color: #E6B800;
}
#nav li:hover ul li {
    background-color: #E6B800;
}

/*Sub-sub menu */
#nav li ul li ul li a {
    display: none;
}
#nav li ul li ul li:hover {
    visibility: visible;
    display: block;
    background-color: #E6B800;
}
#nav li ul li ul li:hover ul li {
    background-color: #E6B800;
}
  • 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-03T00:21:28+00:00Added an answer on June 3, 2026 at 12:21 am

    The main-menu borders are separated because the <li>s are inline-blocks with white-space in between them. Inline-blocks work like words in a text stream, so any white space, such as the line breaks you have in there, will be interpreted as text-space characters. The only way around that while keeping them inline-blocks is to put all the <li>‘s on one line with zero white-space in between. Why do you want to avoid floats? That would be your best option.

    The sub-menu items are half-spaced because the container has width of 200px, but each item is an inline-block with no width specified. Make them display:block isntead and they will expand out to the edges of the container.

    Do apply your sub- and sub-sub-menu classes, that will be easier to see and work with than so many nested selectors.

    Also: use teh the child selector syntax, e.g.: ul#nav > li it will apply the relevant styles only to the child items, and not to the grand-children, etc.

    UPDATE
    In asnwer to mcknz’ question, I would place float:left on #nav li instead of display:inline-block. This solves 2 problems:

  2. The unintended spacing between the menu items will disappear, regardless of white-space in the HTML. You can now control their spacing precisely with margins.
  3. IE7 will not apply inline-block to list-items — or any elements that are not natively inline (see: http://fourwhitefeet.com/2009/02/css-display-inline-block-in-ie7/)
  4. Important note: You will need to specify the height of the #nav explicitly now, because non-floating parents of floating elements collapse (see: Why do non-floating parents of floating elements collapse?).

    …also: you can safely remove subsequent text-align: left; declarations once you’ve applied it to #nav, this property inherits down to all nested elements, unless, of course, you have an intervening layer with text aligned left or center. Properties that inherit are listed here: http://www.communitymx.com/content/article.cfm?cid=2795d

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

Sidebar

Related Questions

I have been learning C++ in school to create small command-line programs. However, I
I'm using Joomla to create websites, but am learning php and css as I
I am learning to create RESTful services using WCF. There are a myriad of
How does Udacity.com (new learning website) create presentation where the text is in front
I've been learning how to create WP plugins and I can for the most
Just wondering if anyone has some good resources for learning how to create new
I learning Perl and I want to create a simple application that gets all
I am learning Cocoa and trying to create an application for Mac that displays
I am learning PyQt and wonder if one can create custom/owner draw control like
I'm trying to create my own template for a List class as a learning

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.