Question

I'm working at making a responsive site and on this site I have a drop down menu. When I bring the size down to 900px I keep the menu, but it gets pressed all the way to the left side of my browser. I gave it a little left padding just so it would be off the wall till it hits 600px at which point it goes into a list-block view and I hide drop down box. Basically I need to find a way to keep the drop down menu between 600px and 900px so that it will still show up under the respective places they're supposed to. Including a screen shot to show what's happening.

Edit: I made a fiddle

And now my code

HTML5

<nav>
    <nav class="nav-wrapper">
        <ul>
            <li><a href="index.html">Home</a>
            </li>
            <li><a href="appliances.html">Appliances</a>
            </li>
            <li><a href="Electronics/index.html">Electronics</a>

                <ul>
                    <li><a href="Electronics/computers.html">Computers</a></li>
                    <li><a href="Electronics/game_systems.html">Game Systems</a></li>
                    <li><a href="Electronics/televisions.html">Televisions</a></li>
                </ul>
            </li>
            <li><a href="Furniture/index.html">Furniture</a>

                <ul>
                    <li><a href="Furniture/bedroom.html">Bedroom</a></li>
                    <li><a href="Furniture/dining_room.html">Dining Room</a></li>
                    <li><a href="Furniture/living_room.html">Living Room</a></li>
                </ul>
            </li>
            <li><a href="location.html">Location</a>
            </li>
        </ul>
    </nav>
</nav>

CSS3

/*Default CSS*/
.main-header nav ul ul {
    display: none;
}

.main-header nav ul li:hover > ul {
    display: block;
}

.main-header nav ul {
    background: #efefef;
    background: linear-gradient(top, #efefef 0%, #bbbbbb 100%);
    background: -moz-linear-gradient(top, #efefef 0%, #bbbbbb 100%);
    background: -webkit-linear-gradient(top, #efefef 0%, #bbbbbb 100%);
    box-shadow: 0px 0px 9px rgba(0, 0, 0, 0.15);
    padding: 0 20px;
    border-radius: 10px;
    list-style: none;
    position: relative;
    display: inline-table;
}

.main-header nav ul:after {
    content:"";
    clear: both;
    display: block;
}

.main-header nav ul li {
    float: left;
}

.main-header nav ul li:hover {
    background: #4b545f;
    background: linear-gradient(top, #4f5964 0%, #5f6975 40%);
    background: -moz-linear-gradient(top, #4f5964 0%, #5f6975 40%);
    background: -webkit-linear-gradient(top, #4f5964 0%, #5f6975 40%);
}

.main-header nav ul li:hover a {
    color: #fff;
}

.main-header nav ul li a {
    display: block;
    padding: 25px 40px;
    color: #757575;
    text-decoration: none;
}

.main-header nav ul ul {
    background: #5f6975;
    border-radius: 0px;
    padding: 0;
    position: absolute;
    top: 100%;
}

.main-header nav ul ul li {
    float: none;
    border-top: 1px solid #6b727c;
    border-bottom: 1px solid #575f6a;
    position: relative;
}

.main-header nav ul ul li a {
    padding: 15px 40px;
    color: #fff;
}

.main-header nav ul ul li a:hover {
    background: #4b545f;
}

    /*Between 600px and 900px*/

.main-header nav ul {
    position: relative;
    margin: 0 auto;
    left: 10%;
}

.main-header nav ul ul {
    position: absolute;
    top: 100%;
}

As you can see I haven't messed with a lot of it, I think the work I need should be with just these two lines. If anyone can help me it would be much appreciated.

Was it helpful?

Solution

The absolute positioned dropdown needs to be inside of a relative positioned container

.main-header nav ul li {
    float: left;
    position: relative;
}

http://jsfiddle.net/UhEk4/2/

Obviously there are more work to be done to adjust the positions but you should be able to take it from here

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top