【问题标题】:Created a nav specifically for mobile view but it still shows in desktop view专门为移动视图创建了一个导航,但它仍然显示在桌面视图中
【发布时间】:2014-09-11 09:26:23
【问题描述】:

我只为移动视图制作了一个导航,并注意到它仍然停留在桌面视图中,尽管它只与移动媒体查询 css 一起使用。导航是菜单 div 旁边的一个 div,它们都位于 html 中网站的主导航中。如何确保导航及其内容仅保留在移动视图中而不包括桌面视图?

jsfiddle - http://jsfiddle.net/LpbL6vj2/

<aside class="sidebar">
    <nav>
        <div class="menu"></div>
        <div class="mobile-header"><a href="index.html">Taffies Cupcakes</a></div>
        <ul class="main_nav">
            <li><a href="index.html">home</a></li>
            <li><a href="about.html">about us</a></li>
            <li><a href="orders.html">orders</a></li>
            <li><a href="gallery.html">gallery</a></li>
            <li><a href="contact.html">contact</a></li>
        </ul>
    </nav> <!-- end of nav -->

        <div class="company_info">
            <p>Taffies cupcakes</p>
            <p>111 x drive road</p>
            <p>milton keynes</p>
            <p>l0002</p><br>
            <p>telephone: 078 878-8888</p>
        </div> <!-- end of compnay info text -->

</aside> <!-- end of aside -->



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

    .container{
        width:100%;
    }

    .sidebar{
        width:100%;
        margin:0;

    }

    .main_nav{
        display:none;

    }

    .company_info{
        display:none;
    }

    .first_article{
        width:90%;
        margin-top:50px;
    }

    footer p{
        display:none;
    }

    .about_section{
        width:80%;
        margin-top:50px;
        margin-bottom:100px;
    }

    .orders_section{
        width:80%;
        margin-top:50px;
        margin-bottom:100px;
    }

    .contact_section{
        width:80%;
        margin-top:50px;
        margin-bottom:100px;
    }

    .gallery_section{
        width:80%;
        margin-top:50px;
        margin-bottom:100px;
    }

    .menu:before{
        content:"Menu";
    }

    .menu{
        font-family:myriad pro;
        font-size:20px;
        color:#3d2316;
        display:inline-block;
        padding-left:8px;
        padding-right:0px;
        padding-top:10px;
        padding-bottom:8px;
        background-color: #CBAFA2;
        cursor:pointer;
        width:30%;
        text-align:center;
        float:left;
    }

    header{
        display:none;
    }

    .mobile-header{
        width:62%;
        padding:10px;
        font-family:georgia;
        font-weight:bold;
        font-size:20px;
        background-color:#3d2316;
        float:left;
    }


}

【问题讨论】:

    标签: html css


    【解决方案1】:

    您需要添加一个非媒体查询规则来隐藏导航。比如:

    .sidebar nav {
        display: none;
    }
    
    @media (max-width: 640px) {
        .sidebar nav {
            display: block;
        }
    }
    

    因此,当窗口很窄时,媒体查询规则就会应用。当窗口较宽时,适用正常规则。

    【讨论】:

      猜你喜欢
      • 2021-12-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-08-03
      • 2020-11-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多