TheDetailer
TheDetailer

Reputation: 299

Dropdown menu border doesn't extend to full width

I am trying to create a bottom border for a dropdown menu tab. I know where to add the property to add the border but the problem I am having is that the border is not extending across from left to right all the way.

HTML:

<div id="navigation">
    <ul>
        <li><a href="#" id="home">Home</a></li>
        <li><a href="#" id="zeus">Zeus</a>
        <li><a href="#" id="poseidon">Poseidon</a>
        <li><a href="#" id="hercules">Hercules</a>
        <li><a href="#" id="athena">Athena</a>
        <li><a href="#" id="help">Help</a>
            <ul>
                <li><a href="#">Contact</a></li>
                <li><a href="#">FAQ's</a></li>
            </ul>
        </li>
        <li><a href="#" id="account">Account</a>
            <ul>
                <li><a href="#">Cart</a></li>
                <li><a href="#">Orders</a></li>
            </ul>
        </li>
    </ul>
</div>

CSS:

#navigation {
    background-color: #404040;
    display: block;
    text-align: center;
}

#navigation ul {
    display: block;
    list-style-type: none;
    margin: 0;
    padding: 0;
    position: relative;
}

#navigation ul a {
    color: white;
    display: block;
    font-size: 18px;
    font-weight: 500;
    line-height: 32px;
    padding: 0 30px;
    text-decoration: none;
}

#navigation ul li {
    display: inline-block;
    margin: 0;
    padding: 0;
    position: relative;
}

#navigation ul ul {
    display:none;
    position:absolute;
    top:100%;
    left:0;
    background:#fff;
    padding:0
}

#navigation ul ul a {
    line-height: 120%;
    padding: 10px 15px;
}

#home:hover {
    color: gray;
}

#zeus:hover {
    color: red;
}

#poseidon:hover {
    color: blue;
}

#hercules:hover {
    color: gold;
}

#athena:hover {
    color: #00ff00;
}

#help:hover {
    color: gray;
}

#account:hover {
    color: gray;
}

#navigation ul li ul a:hover {
    color: gray;
}

#navigation ul li:hover > ul {
    display: block;
    background-color: #404040; 
    text-align: left;
    z-index: 99;
}

Upvotes: 1

Views: 885

Answers (2)

Kristijan Iliev
Kristijan Iliev

Reputation: 4987

You can stretch the bottom border applying these rules:

#navigation a + ul li{ /* set width to dropdown menu */
  width: 100%;
}

#navigation a + ul li{ /* set width and border to dropdown items */
  width: 100%;
  border-bottom: 3px solid blue;
}

They will make sure your dropdown menu get 100% width

You can try it in this fiddle

Upvotes: 0

Stickers
Stickers

Reputation: 78676

You have li set to display:inline-block that makes it to "shrink-to-fit" depending on the content. You can add width:100 to the child li to make sure it to always stay full width of the parent.

#navigation li li {
  border-bottom: 1px solid lime;
  width: 100%;
}

jsFiddle

Upvotes: 1

Related Questions