Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to open submenu on hover of main menu?

Hi I am making menu and submenu. I have made menu with all effect. I want to open submenu on hover of menu item, but it's not opening; it shows me already open.

My JSFiddle

#companymenu {
    background-color: #999;
    height:35px;
    width:100%;
    margin-top: -10px;
}
.companymenuul {
    list-style-type: none;
}
.companymenuli {
    float: left;
    display:block;
    line-height: 35px;
    padding: 0 15px;
}
.alisting {
    color:#000;
    text-decoration:none;
}
.aactive {
    color: #333;
    background-color: #fff;
    border-top: 2px solid #999;
    margin-top: -2px;
}
.companymenuli a:hover {
    color:#C63;
    text-decoration:none;
    cursor:pointer;
    padding-top:10px;
    padding-left:24px;
    padding-right: 23px;
    padding-bottom: 11px;
    background-color: #fff;
    border-top: 2px solid #999;
    margin-top: -2px;
}
.caret {
    display: inline-block;
    width: 0;
    height: 0;
    vertical-align: top;
    border-top: 4px solid #fff;
    border-right: 4px solid transparent;
    border-left: 4px solid transparent;
    content:"";
    margin-top: 15px;
    margin-left: 5px;
    border-bottom-color: #fff;
    filter: alpha(opacity=100);
    background-image:url(images/topnav-arrow-down-white-ie6.png)no-repeat 0 0 transparent;
    _display: inline;
    _zoom: 1;
    _width: 7px;
    _height: 4px;
    _margin-top: 8px;
    _margin-left: 5px;
    _line-height: 4px;
    _border: none;
    _vertical-align: baseline;
}
<div id="companymenu">
    <ul class="companymenuul">
        <li class="companymenuli aactive"><a class="alisting">Home</a></li>
        <li class="companymenuli"><a class="alisting">Product Categories<b class="caret"></b></a>
            <ul>
                <li>1</li>
                <li>2</li>
                <li>3</li>
            </ul>
        </li>
        <li class="companymenuli"><a class="alisting">Company Profile  <b class="caret"></b></a>
        </li>
        <li class="companymenuli"><a class="alisting">Contacts</a>
        </li>
    </ul>
</div>

I want to open <ul> on hover of Product Categories <li>


2 Answers

Are you looking for something like this? JSFiddle

Give your submenu a class and add display:none; to it. After you can give your hover display:block;

So you have something like this:

.submenu{
    display:none;
}

.companymenuli:hover > ul{
    display:block;
}
<li class="companymenuli"><a class="alisting">Product Categories  <b class="caret"></b></a>
    <ul class="submenu">
        <li>1</li>
        <li>2</li>
        <li>3</li>
    </ul>
</li>

For removing the bullets just add list-style-type:none; to your submenu li tag. Here your updated fiddle:

Updated JSFiddle

like image 193
roemel Avatar answered Oct 30 '25 13:10

roemel


add this css in your existing css:

.companymenuli ul {
    display:none;
}

.companymenuli:hover ul {
    display:block;
}

then it will work

like image 20
richa_pandey Avatar answered Oct 30 '25 11:10

richa_pandey



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!