1

Newbie to CSS and can only find single level menus. Here's the Menu and the list items:

<ul>
    <li>
        <a href="#">Home</a>
    </li>
    <li>
        <a href="#">Forums</a>
        <ul>
            <a href="#">Basketball</a>
            <ul>
                <li>
                    <a href="#">Trading</a>
                </li>
                <li>
                    <a href="#">Personal Collections</a>
                </li>
                <li>
                    <a href="#">Box Breaks</a>
                </li>
            </ul>
        </ul>
    </li>
</ul>

As you can see, it would be multi-tiered. Now, with the CSS I have, only Home and Forums are displayed first, and when I hover over Forums, Basketball is displayed...but so are the subsequent menu items. I want those to stay hidden until I hover over basketball. Anyone know how to do this with just CSS or as little JavaScript as possible? Thanks. Here's the CSS code I have:

ul
{
    margin: 0;
    padding: 0;
    list-style: none;
    width: 150px;
    border-bottom: 1px solid #ccc;
}

ul li
{
    position: relative;
}

li ul
{
    position: absolute;
    left: 149px;
    top: 0;
    display: none;
}

ul li a
{
    display: block;
    text-decoration: none;
    color: #777;
    background: #bad8f8;
    padding: 2px 0 2px 10px;
    border: 1px solid #ccc;
    border-bottom: 0;
}

li:hover ul
{
    display: block;
}

/* Styles for validation helpers
-----------------------------------------------------------*/
.field-validation-error
{
    color: #ff0000;
}

.field-validation-valid
{
    display: none;
}

.input-validation-error
{
    border: 1px solid #ff0000;
    background-color: #ffeeee;
}

.validation-summary-errors
{
    font-weight: bold;
    color: #ff0000;
}

.validation-summary-valid
{
    display: none;
}

3 Answers 3

2

Here is a working demo:

http://jsfiddle.net/rcravens/aqz8q/

Two things I did.

  1. A bit of restructuring the ul/li list. There were some elements not in the li.

  2. Used 'li:hover > ul' to select the direct children only.

Hope that helps.

Bob

Sign up to request clarification or add additional context in comments.

Comments

0

Try to add

ul li ul{position: absolute; top: 0; left: 0; width: 250px; height: 250px; background-color: #EEE;}

And go from there :)

Comments

0

The way you have structured your css causes all of "Basketball"'s descendants to inherit its css. You should be using a child(">") or :first-child selector instead. Look at sections 5.5 and 5.6 here to know what I am talking about: http://www.w3.org/TR/CSS2/selector.html

If you are looking to do dynamic menus I'd strongly recommend using javascript over relying purely on css, unless you are certain a lot of people viewing your website are going to have their javascript turned off.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.