【问题标题】:Responsive Menu style using CSS Display the dropdown on hover使用 CSS 的响应式菜单样式在悬停时显示下拉菜单
【发布时间】:2016-05-24 03:38:43
【问题描述】:

因此,我查看了许多其他示例,但仍然无法弄清楚我缺少什么。菜单效果很好,除非我在电话模式下查看它时菜单不会在悬停时下降。你能帮忙吗?

CSS 代码

/*Strip the ul of padding and list styling*/
#menu ul {
    list-style: none;
    width: 100%;
    margin: 0;
    padding: 0;
    float: left;
    background: #645565;
    font-size: 1em;
}
/*Create a horizontal list with spacing*/
#menu li {
    float: left;
    position: relative;
    display: inline-block;
}
/*Style for menu link*/
#menu li a {
    display: block;
    line-height: 3em;
    font-family: Trebuchet MS, Verdana, Arial, sans-serif;
    font-size:  0.95em;
    color: #BFA877;
    text-decoration: none;
    padding: 0 0.9em;
}
/*Hover over text upper*/
#menu li:hover > a {
    color: #FFF6D6;
}
/*Displays dropdown*/
#menu ul li:hover > ul {
    display: block;
}
/*Hide dropdown links until they are needed*/
#menu li ul {
    display: none;
    position: absolute;
}
/*Display the dropdown on hover*/
.dropdown:hover .dropdown-content {
    display: block;
}

/*Style "show menu' label button and hide it by default*/
.dropdown{
    font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
    text-decoration: none;
    color: #FFF6D6;
    background: #645565;
    text-align: center;
    padding: 10px 0;
    display: none;
    z-index: 1;
}
/*Hide checkbox*/
input[type=checkbox] {
    display: none;
}
/*Show menu when invisible checkbox is checked*/
input[type=checkbox]:checked ~ #menu {
    display: block;
}

/*==========MOBILE===========*/ 
    /*Responsive Styles*/
@media screen and (max-width: 768px){

/*Make dropdown links appear inline*/
    #menu ul {
        position: static;
        display: none;
    }
    /*Create vertical spacing*/
    #menu li {
        margin-bottom: 1px;
    }
    /*Make all menu links full width*/
    #menu ul li, li a {
        width: 100%;
    }
    /*Display "show menu" link*/
    .dropdown {
        display: block;
    }

}

HTML 代码

<div id="container">
<label for="dropdown" class="dropdown">Show Menu</label>
    <input type="checkbox" id="dropdown" role="button">
    <div id="menu">
            <ul>
                <li><a href="#">Home</a></li>
                <li>
                    <a href="#">Massage & Spa</a>
                    <ul class="dropdown-content">
                        <li><a href="#">Massage Treatment</a></li>
                        <li><a href="#">Balancing Energies</a></li>
                        <li><a href="#">Signature Massage Treatment</a></li>
                        <li><a href="#">Thai Massage</a></li>
                        <li><a href="#">Signature Spa Treatment</a></li>
                        <li><a href="#">List of Treatments & Rates</a></li>
                    </ul>
               </li>

                <li><a href="#">Well Being</a></li>
                <li>
                    <a href="#">About Us</a>
                    <ul class="dropdown-content">
                        <li><a href="#">Richard Davenport</a></li>
                        <li><a href="#">Katrine Dannieu</a></li>
                        <li><a href="#">Beth Drake</a></li>
                        <li><a href="#">Daniel</a></li>
                        <li><a href="#">Ciciely</a></li>
                        <li><a href="#">Ish</a></li>
                        <li><a href="#">Elizabeth</a></li>
                        <li><a href="#">Tyler</a></li>
                        <li><a href="#">Julia</a></li>
                        <li><a href="#">Asley</a></li>
                        <li><a href="#">Sandra</a></li>
                    </ul>
                </li>

                <li>
                    <a href="#">To Know</a>
                    <ul class="dropdown-content">
                        <li><a href="#">How to prepare for your massage</a></li>
                        <li><a href="#">The right pressure during your Massage</a></li>
                        <li><a href="#">How often should you get a massage?</a></li>
                        <li><a href="#">Here is why you should book your next appointment ASAP</a></li>
                        <li><a href="#">What is Rieki Who can learn</a></li>
                        <li><a href="#">Dr. Oz and the healing power of Reiki</a></li>
                    </ul>
                </li>
                <li><a href="#">Location</a></li><li>
                    <a href="#">Contact</a></li><li>
                    <a href="#">Calendar</a></li><li>
                    <a href="#">Events</a></li><li>
                    <a href="#">Links</a></li>
            </ul>
        </div> 
</div><!-----End of container----->

【问题讨论】:

    标签: css menu hover dropdown


    【解决方案1】:

    手机不支持悬停动作!

    【讨论】:

    • 如果手机不支持悬停动作,我可以使用 css 样式吗?
    • 尝试添加 :focus 或/和 :active 以及 :hover 动作,这样它就像 .item:hover, .item:focus, .item:active {....}跨度>
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-02-09
    • 2015-10-21
    • 2018-08-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-01-19
    相关资源
    最近更新 更多