Mohammad Areeb Siddiqui
Mohammad Areeb Siddiqui

Reputation: 10179

Css - submenus not aligning properly

I have a simple nav with some ULs and LIs. But in some LIs I have another UL to create a sub menu but the submenu is just going towards the right side.

See this fiddle.

HTML:

<header>
        <h1 style="float: left; margin-top: 2%;">&nbsp;&nbsp;&nbsp;Naughty Mama.</h1>

    <nav>
        <ul>
            <li><a href="profile.php">My Profile</a>
            </li>
            <li><a href="inbox.php">Inbox</a>
            </li>
            <li>    <a href="notifications.php">Notifications</a>

                <ul>
                    <li>Notification 1</li>
                    <li>Notification 2</li>
                    <li>Notification 3</li>
                </ul>
            </li>
        </ul>
    </nav>
</header>

CSS:

header {
    background-color: #ddd;
}
nav {
    float: right;
    margin-right: 5%;
    margin-top: 2%;
}
nav ul li {
    display: inline-block;
    background-color: #eee;
    vertical-align: top;
}
nav ul li a {
    color: #fff;
    text-decoration: none;
    display: block;
    padding: 15px;
}
nav ul li a:hover {
    color: #000;
    background: #aaa;
}
nav ul li ul li {
    display: block;
}

How can I align those double nested LIs to left side of the main menu?

Hope I am clear.

Thanks in advance.

Upvotes: 0

Views: 268

Answers (3)

Abdul Malik
Abdul Malik

Reputation: 2642

Here you go

nav ul li ul{
    padding-left:0px;}

Upvotes: 1

aljordan82
aljordan82

Reputation: 1720

Reset your CSS

ul {  padding:0;}

Upvotes: 1

Ian Clark
Ian Clark

Reputation: 9347

Are you talking about doing something like this?

Changes:

nav {
    float: right;
    margin-right: 5%;
    margin-top: 2%;
}
nav ul {
    padding-left:0;
    margin-left:0;
}
nav > ul { position:relative; }
nav ul li ul {
    display: block;
    position:absolute; 
    left:0;
}

Upvotes: 0

Related Questions