简体   繁体   English

导航栏是否位于桌面标头中,如何使其响应?

[英]How to make nav responsive if it's inside a header on desktop?

On the desktop version of my site I have the nav inside the header. 在网站的桌面版本中,我的标题中包含导航。 How will I go about making the nav responsive for mobile if the nav is inside the header? 如果导航栏位于标头内,我将如何使导航栏响应移动设备?

js fiddle - https://jsfiddle.net/24pyfmn4/ js小提琴-https: //jsfiddle.net/24pyfmn4/

<header>
    <div class="header">
        <h1 class="logo"><a href="index.html">New York</a></h1>
        <nav class="main-navigation">
            <ul>
                <li class="active"><a href="#">Home</a></li>
                <li><a href="photos.html">Photos</a></li>
                <li><a href="videos.html">Videos</a></li>
                <li><a href="contact.html">Contact</a></li>
            </ul>
        </nav>
    </div>
</header>

Indeed. 确实。 Like Shebary pointed out, you have to use media queries , unless of course, you prefer using JavaScript (which I don't really recommend). 就像Shebary指出的那样,您必须使用媒体查询 ,当然,除非您更喜欢使用JavaScript (我并不建议这样做 )。

Quick tutorial on media queries . 媒体查询快速教程


///Making the mobile nav appear while the header disappears. ///使移动导航栏出现,而标题消失。

@media screen and (max-width:640px){
     .mobile-nav {
           display: block;
      }
     header {
           display: none;
      }
}

///Making the mobile nav disappear while the header appears. ///使移动导航消失,同时出现标题。

@media screen and (min-width:641px){
     .mobile-nav {
           display: none;
     }
     header {
           display: block;
     }
}

Also , it's important to note that the ".mobile-nav" class has to be defined. 同样 ,必须注意必须定义“ .mobile-nav”类。 Like so: 像这样:

.mobile-nav {
     ///Styling code
}

EDIT 编辑

You're also missing a bracket here: 您还在这里缺少括号:

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

.pic-vid{
    width:90%;
}

.nycimg{
    width:100%;
}

.video-title{
    width:100%;
}

.second-video{
    margin:0;
    width:100%;
}

.third-video{
    margin:0;
    width:100%;
}

.fourth-video{
    margin:0;
    width:100%;
}

} /// <- this one

Here's another example to help you responsive web nav 这是另一个帮助您响应式网络导航的示例

In your case, the header will be width:100% and just the nav will collapsed according with the screen size. 在您的情况下,标题将为width:100%,而导航栏将根据屏幕大小而折叠。 (using @media screen according to Edward) Hope it helps. (根据Edward的说法,使用@media屏幕)希望对您有所帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM