OzzC
OzzC

Reputation: 821

How to get a vertical submenu instead a horizontal one?

I developed a submenu with CSS & jQuery and my intention was that it was vertical submenu but I´m getting a horizontal menu.

I already tried to "play" with display in CSS but its not working, like #menu ul li ul li a {display: inline-block;}.

Anyone there knows the trick to put this submenu vertical?

My jsfiddle with full example:

http://jsfiddle.net/jcak/9EcnL/7/

My html:

<section id="menu-container">

    <nav id="menu">
        <ul>    
            <li><a href="index.html">Home</a>
                <ul>
                    <li><a href="#">Link 1</a></li>
                    <li><a href="#">Link 2</a></li>
                    <li><a href="#">Link 3</a></li>
                    <li><a href="#">Link 4</a></li>
                </ul>
            </li>
            <li><a href="procuts.html">Procuts</a>
                <ul>
                    <li><a href="#">Link 1</a></li>
                    <li><a href="#">Link 2</a></li>
                    <li><a href="#">Link 3</a></li>
                    <li><a href="#">Link 4</a></li>
                </ul>
            </li>
            <li><a href="#">About</a></li>
            <li><a href="#">Contacts</a></li> 
       </ul>
    </nav>   
</section>

My css:

#menu ul li ul li {display: none;}

#menu-container
{

    background:green;
    width:100%; 
    height:46px; 
    float:left;  
    z-index:7;
}

#menu
{
    width:960px; 
    height:auto; 
    margin:0 auto 0 auto;
}

#menu ul
{
    list-style-type:none;
}

#menu ul li 
{
    display: inline-block;
    float:left; 
    height:46px;
    position: relative;
    line-height:46px; 
    font-weight:300;

}

#menu ul li a
{
    text-decoration:none;
    color:#ccc;  
    display:block; 
    margin-right:5px; 
    height:46px; 
    line-height:46px; 
    padding:0 5px 0 5px;
    font-size:20px; 

}

#menu ul li a:hover
{
    color:#fff;
}
#menu ul li ul {
    position: absolute;
    left: 0;
    -webkit-padding-start: 0;
    width: 300px;
}
#menu ul li ul li
{
    color:#fff;

}

Upvotes: 0

Views: 675

Answers (2)

Jatin
Jatin

Reputation: 3089

Working Fiddle

#menu ul li 
{
  display: inline-block;
  height:46px;
  position: relative;
  line-height:46px; 
  font-weight:300;
}

Upvotes: 1

Taryn East
Taryn East

Reputation: 27747

By default, a ul will be vertical. The float:left is what is making this whole menu be horizontal instead.

Have a go at removing that and seeing how the menu behaves.

Upvotes: 2

Related Questions