调整我的菜单到响应式菜单

时间:2014-03-18 05:14:08

标签: jquery html css mobile menu

我已经制作了一个我喜欢的网站菜单,但我无法进行编辑以使其垂直移动浏览/响应。

我正在使用boiler5plate,请检查JSFIDDLE

您还可以看到我尝试编码的网页的实时版本:TEST PAGE

请帮忙!

HTML

<div id="home">

        <div id="nav">
            <div class="container clearfix">

                    <ul id="menu">
                        <li><a href="#home">Home</a></li>
                        <li><a href="#services">Serviços</a></li>
                        <li><a href="#team">Equipa</a></li>
                        <a href="#" id="logo" alt="Style Euclides"><img src="http://styleeuclides.site50.net/img/logo.png" alt="Logo Style Euclides" width="90px" height="40px"></a> 
                        <li><a href="#space">Espaço</a></li>
                        <li><a href="#gallery">Galeria</a></li>
                        <li><a href="#contact">Contatos</a></li>
                    </ul>
            </div>
        </div>


<div class="mobi">
                <ul class="egmenu">
                        <li><a href="#home">Home</a></li>
                        <li><a href="#services">Serviços</a></li>
                        <li><a href="#team">Equipa</a></li>
                        <li><a href="#space">Espaço</a></li>
                        <li><a href="#gallery">Galeria</a></li>
                        <li><a href="#contact">Contatos</a></li>
                </ul></div>
    </div>

CSS

   #home{
        width: 100%;
        background-color: #27ae60;
        float: left;
    }

    #home .mobi ul.egmenu{
        display: none;
    }

    @media only screen and (max-width : 500px) {

    #nav { display: none;}
    #home .conteudo .social {display: none;}

.mobi ul.egmenu {  
    background: #131313; 
    height: 30px;
    width: 100%; 
}

.mobi ul.egmenu > li { 
    float: left; 
    position: relative;  
}

.mobi ul.egmenu ul {
    background: #444; 
    display: none; 
    position: absolute;
    left: 0; top: 100%;
}

.mobi ul.egmenu a { 
    cursor: pointer; 
    display: block; 
    color: white; 
    line-height: 30px; 
    padding: 0 10px; 
}

.mobi ul.egmenu li { list-style: none; }
.mobi ul.egmenu li:hover { background: #555;  }
.mobi ul.egmenu li:hover ul { display: block;  }
}

@media only screen and (min-width: 501px) {

   /* TOP MENU */

        #nav{
            float: left;
            background-color: #43c862;
            height: 100px;
            width: 100%;          
            text-transform:uppercase; 
            text-align:center;
            font-size: 0.875em;
            font-weight: bold;
            letter-spacing: -1px;
            position: fixed;
            z-index: 9999; 
            clear: both;
            }

        #nav ul {
            list-style: none;
            margin: 0 auto;
            padding: 0;
            display: block;
            width: 100%;
            text-align:center;
        }

        #nav li {
            display: inline-block;
            margin-top: 30px;
        }

        #nav li a {
            /*width: 100px;*/
            display: block;
            padding: 10px 10px 10px 10px;
            text-decoration: none;
            font-weight: bold;
            color: white;
            text-shadow:0px 1px 0px #27ae60;
        }

        #nav li a:hover {
            color: white;
            background-color: #131313;
            padding: 10px 10px 10px 10px;
            -moz-border-radius: 5px;
            -webkit-border-radius: 5px;
            text-shadow:0px -1px 0px #2b2b2b;
        }

        #nav li a:active {
            color: white;
            opacity: 0.8;
            padding: 10px 10px 10px 10px;
        }

        #nav img{
            margin-right: 8px;
            margin-left: 4px;
        }

        #nav #logo{
            color: none;
            background-color: none;            
        }

        #nav #logo:hover{
            color: none;
            background-color: none;          
        }

        #nav #logo:active{
            opacity: 0.7;          
        }
}

@media all and (max-width: 480px) {
    ul.egmenu {  height: auto; }
    ul.egmenu > li {  float: none; width: 100%; }
    ul.egmenu a { line-height: 40px; }
    ul.egmenu ul { position: relative; }
}

@media all and (min-width: 481px) {
    ul.egmenu li:hover { background: #555;  }
    ul.egmenu li:hover ul { display: block;  }
}

1 个答案:

答案 0 :(得分:0)

使用以下链接下载tinyNav插件。

http://tinynav.viljamis.com/

    <div id="nav">
        <div class="container clearfix">

                <ul id="menu">
                    <li><a href="#home">Home</a></li>
                    <li><a href="#services">Serviços</a></li>
                    <li><a href="#team">Equipa</a></li>  
                    <li><a href="#space">Espaço</a></li>
                    <li><a href="#gallery">Galeria</a></li>
                    <li><a href="#contact">Contatos</a></li>
                </ul>
        </div>
    </div>

的JQuery:

$(&#39;#菜单&#39;)tinyNav();

演示:

http://jsfiddle.net/8UefQ/2/

当导航菜单进入移动视图时,导航菜单将更改为下拉列表。