【问题标题】:how to fix a responsive navigation如何修复响应式导航
【发布时间】:2013-11-15 11:42:35
【问题描述】:

我有一个基于我之前工作的问题。

我正在构建一个响应式导航。

问题发生的时候,

按灰色块打开导航 - 工作正常。 按灰色块隐藏导航 - 工作正常

但是,一旦您隐藏导航并将屏幕尺寸增加到超过 800 像素,主导航仍然隐藏,它不会再次出现。

任何机构都可以帮助解决这个问题吗?

http://jsfiddle.net/9jPe9/

 body {
    font-family:"Helvetica Neue", Helvetica, Arial, sans-serif;
    color: #444;
    font-size: 62.5%;
    text-rendering: optimizeLegibility;
}
#wrap {
    margin: 0 auto;
    text-align: center;
    overflow: hidden;
}
#wrap-inner {
    padding: 20px;
    padding-top:80px;
    border: 1px solid blue;
}
#wrap-inner-profile {
    padding: 10px 20px 20px 20px;
}
#content {
    position: relative;
    max-width: 970px;
    margin: 0 auto;
    padding: 0;
    font-size: 1.2em;
    border: 1px solid green;
}
li {
    list-style: none;
}
a:link, a:visited {
    color: #4083a9;
    outline: none;
    text-decoration: none;
    font-size: 13px;
}
a:hover {
    text-decoration: none;
    color: #205f82;
}
ul, ol, h1, h2, h3, h4, p {
    padding: 0px;
    margin: 0px;
    ;
}
p {
    line-height: 22px;
    font-size: 13px;
}
.clearfix {
    clear: both;
}
img:hover {
    opacity: .7;
}
/* =============================================================================
   HEADER
   ========================================================================== */
 #header {
    width: 100%;
    height: 67px;
    background: white;
    z-index: 9997;
    position: fixed;
    top: 0px;
    -webkit-box-shadow: rgba(6, 8, 8, 0.0980392) 0px 3px 3px;
    box-shadow: rgba(6, 8, 8, 0.0980392) 0px 3px 3px;
}
#header-inner {
    position: relative;
    margin: 0 auto;
    padding: 0 12px;
    max-width: 970px;
}
#logo {
    float: left;
    padding: 0px 20px 0 0;
}
#logo a {
    display: block;
    width: 107px;
    height: 50px;
    background-repeat: no-repeat;
    background-position: 0 50%;
    background-image: url(../img/home/oh-holla.png);
    -webkit-transition: opacity 0.2s ease;
    -moz-transition: opacity 0.2s ease;
    -o-transition: opacity 0.2s ease;
    transition: opacity 0.2s ease;
}
#logo img {
    height: 0;
}
#logo a:hover {
    opacity: .6;
}
#nav {
    margin: 1px 0px 0 0px;
    color: #777;
    padding:0px;
    float:right;
}
#nav>li {
    float: right;
    font-size: 1.25em;
    line-height: 1;
    margin-left: 30px;
}
#nav>li>a {
    display: block;
    height: 66px;
    line-height: 66px;
    text-decoration: none;
    color: #333;
    font-weight: bold;
}
#toggle-nav {
    display: none;
}
#right-nav {
    margin: 1px 0px 0 0px;
    color: #777;
    padding:0px;
    float:right;
    margin-top: 26px;
}
#right-nav li {
    float: right;
    font-size: 1.25em;
    line-height: 1;
    margin-left: 30px;
}
#right-nav li a {
    display: block;
    height: 66px;
    line-height: 66px;
    text-decoration: none;
    color: #333;
    font-weight: bold;
}
#signin {
    border:1px solid #ddd;
    padding: 10px 20px;
    color: #333;
    font-weight: bold;
    -webkit-border-radius: 6px;
    -moz-border-radius: 6px;
    border-radius: 6px;
}
#login {
    padding: 10px 20px;
    color: #333;
    font-weight: bold;
    -webkit-border-radius: 6px;
    -moz-border-radius: 6px;
    border-radius: 6px;
    margin-left: 100px;
}
/* =============================================================================
  NAVIGATION MEDIA MAX 800PX
   ========================================================================== */
 @media screen and (max-width: 800px) {
    #header {
        position: fixed;
        height: 57px;
        -webkit-box-shadow: rgba(6, 8, 8, 0.0980392) 0px 3px 3px;
        box-shadow: rgba(6, 8, 8, 0.0980392) 0px 3px 3px;
        background: green;
    }
    #toggle-nav {
        position: absolute;
        top: 0px;
        left: 0px;
        display: block;
        width: 48px;
        height: 40px;
        text-indent: -9999px;
        background: url('../img/home/burger-menu.png') 20px 20px no-repeat;
        opacity: .5;
        background:black;
    }
    #logo a {
        display: block;
        height: 40px;
        margin: 0 auto 0 auto;
    }
    #logo {
        float: none;
        padding-right: 0;
        text-align: left;
    }
    #nav {
        width: 100%;
        margin: 0 0 10px 0;
        text-align: left;
        position: absolute;
        top: 57px;
        display: none;
    }
    #nav li {
        position: relative;
        float: none;
        margin-right: 0;
        text-align: left;
        font-size: 12px;
        background: #323232;
        margin-left: 0px;
    }
    #nav li:hover {
        background: #2e2e2e;
    }
    #header-inner {
        width: auto;
        padding: 0;
        height: 57px;
        background: pink;
    }
    #nav li a {
        height: auto;
        padding: 15px;
        font-size: 14px;
        font-weight: bold;
        line-height: 1;
        border-bottom: 1px solid black;
        background: white;
    }
    #wrap-inner {
        padding-top: 60px;
    }
    #right-nav {
        display: block;
        float: none;
        position: absolute;
        top: -10px;
        right: 20px;
        background: none;
    }
    #livefeed {
        -webkit-box-shadow: rgba(6, 8, 8, 0.0980392) 0px 3px 3px;
        box-shadow: rgba(6, 8, 8, 0.0980392) 0px 3px 3px;
    }
} 

【问题讨论】:

  • 你的 css 的问题.. 小于 800px 的媒体的 css 很好.. 但 css 不少于不好.. 你把#toggle-nav { display: none; } 这就是为什么它不工作.. 只是检查下面的小提琴.. http://jsfiddle.net/9jPe9/3/
  • 嗨,这不起作用?
  • 我只应用了toggle-nav的样式..从媒体css添加所有必要的样式后尝试..
  • 你的小提琴..http://jsfiddle.net/9jPe9/4/..

标签: jquery html css navigation responsive-design


【解决方案1】:

很简单,改一下:

/* =============================================================================
  NAVIGATION MEDIA MAX 800PX
   ========================================================================== */
 @media screen and (max-width: 800px) { 

进入

/* =============================================================================
  NAVIGATION MEDIA MAX 800PX
   ========================================================================== */
 @media screen { 

停止这个问题。我真的不知道你为什么想要 max-width 为 800px,但如果你真的需要它,试着把它放在 #header 的正文中

【讨论】:

    【解决方案2】:

    这很简单。我已经更新了 JS fiddle,请检查一下。

    http://jsfiddle.net/surjithctly/9jPe9/2/

    在 CSS 中添加此媒体查询

     @media screen and (min-width: 800px) {
         #nav {
             display:block!important;
    }
     }
    

    【讨论】:

    • 隐藏下拉菜单后增加屏幕尺寸会隐藏其他导航链接
    • 你检查过 JS 小提琴吗,我在这里没有看到任何问题。有的话可以发个截图吗?这样我才能理解你的想法。
    【解决方案3】:

    在您拥有的 CSS 中:

    ...
    /* =============================================================================
      NAVIGATION MEDIA MAX 800PX
       ========================================================================== */
     @media screen and (max-width: 800px) {
    ...
    

    这个参数 max-width:800px 给你带来了麻烦。更改或删除它。

    【讨论】:

    • 嗨,你建议把它改成什么?
    • 嗨,不知道你为什么把它放在首位。这些限制通常在您使用移动 CSS 并且想要覆盖多种屏幕尺寸时设置。但在您的情况下,您只需删除“and (max-width: 800px)”部分即可。
    【解决方案4】:
    /* Smartphones (portrait and landscape) ----------- */
    @media only screen 
    and (min-device-width : 320px) 
    and (max-device-width : 480px) {
    /* Styles */
    }
    
    /* Smartphones (landscape) ----------- */
    @media only screen 
    and (min-width : 321px) {
    /* Styles */
    }
    
    /* Smartphones (portrait) ----------- */
    @media only screen 
    and (max-width : 320px) {
    /* Styles */
    }
    
    /* iPads (portrait and landscape) ----------- */
    @media only screen 
    and (min-device-width : 768px) 
    and (max-device-width : 1024px) {
    /* Styles */
    }
    
    /* iPads (landscape) ----------- */
    @media only screen 
    and (min-device-width : 768px) 
    and (max-device-width : 1024px) 
    and (orientation : landscape) {
    /* Styles */
    }
    

    仅使用媒体查询屏幕

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多