2014-03-06 68 views
0

我正在嘗試設計一個響應式導航欄。我對css3不太瞭解。除了平板電腦,導航欄工作正常。請幫我看看我缺少的平板電腦大小。我是否需要爲平板電腦大小添加媒體查詢?或任何改變需要導航標籤做響應式導航菜單無法正常工作

<nav class="clearfix"> 
    <ul class="clearfix"> 
     <li><a href="#">Home</a></li> 
     <li><a href="#">Menu1</a></li> 
     <li><a href="#">Menu1</a></li> 
     <li><a href="#">Menu1</a></li> 
     <li><a href="#">Menu1</a></li> 
     <li><a href="#">Menu1</a></li> 
     <li><a href="#">Menu1</a></li> 
     <li><a href="#">Menu1</a></li> 
    </ul> 
    <a href="#" id="pull">Menu</a> 
</nav> 

以下是一個導航的CSS

nav { 
    height: 40px; 
    width: 100%; 
    background: #455868; 
    font-size: 11pt; 
    font-family: 'PT Sans', Arial, sans-serif; 
    font-weight: bold; 
    position: relative; 
    border-bottom: 2px solid #283744; 
} 
nav ul { 
    padding: 0; 
    margin: 0 auto; 
    width: 80%; 
    height: 40px; 
} 
nav li { 
    display: inline; 
    float: left; 
} 
nav a { 
    color: #fff; 
    display: inline-block; 
    width: 100px; 
    text-align: center; 
    text-decoration: none; 
    line-height: 40px; 
    text-shadow: 1px 1px 0px #283744; 
} 
nav li a { 
    border-right: 1px solid #576979; 
    box-sizing:border-box; 
    -moz-box-sizing:border-box; 
    -webkit-box-sizing:border-box; 
} 
nav li:last-child a { 
    border-right: 0; 
} 
nav a:hover, nav a:active { 
    background-color: #8c99a4; 
} 
nav a#pull { 
    display: none; 
} 

/*Styles for screen 600px and lower*/ 
@media screen and (max-width: 600px) { 
    nav { 
     height: auto; 
    } 
    nav ul { 
     width: 100%; 
     display: block; 
     height: auto; 
    } 
    nav li { 
     width: 50%; 
     float: left; 
     position: relative; 
    } 
    nav li a { 
     border-bottom: 1px solid #576979; 
     border-right: 1px solid #576979; 
    } 
    nav a { 
     text-align: left; 
     width: 100%; 
     text-indent: 25px; 
    } 
} 

/*Styles for screen 515px and lower*/ 
@media only screen and (max-width : 480px) { 
    nav { 
     border-bottom: 0; 
    } 
    nav ul { 
     display: none; 
     height: auto; 
    } 
    nav a#pull { 
     display: block; 
     background-color: #283744; 
     width: 100%; 
     position: relative; 
    } 
    nav a#pull:after { 
     content:""; 
     background: url('nav-icon.png') no-repeat; 
     width: 30px; 
     height: 30px; 
     display: inline-block; 
     position: absolute; 
     right: 15px; 
     top: 10px; 
    } 
} 

/*Smartphone*/ 
@media only screen and (max-width : 320px) { 
    nav li { 
     display: block; 
     float: none; 
     width: 100%; 
    } 
    nav li a { 
     border-bottom: 1px solid #576979; 
    } 
} 
.clearfix:before, 
.clearfix:after { 
    content: " "; 
    display: table; 
} 
.clearfix:after { 
    clear: both; 
} 
.clearfix { 
    *zoom: 1; 
+0

你是什麼意思不工作?這個對我有用? – Siyah

+0

當你說「不工作」時,你是指菜單分成兩行,低於1000px寬度? http://jsfiddle.net/98jxL/ – Mathias

+1

是的,菜單分成2行。根據屏幕大小,我可以做些什麼來使其正確對齊? @Mathias –

回答

1

你可以試試這個:http://jsfiddle.net/98jxL/2/

我添加了一個新的媒體查詢最多到1000px。它會將您的菜單項均勻分佈在屏幕寬度上。此解決方案基於您擁有8個菜單項。

/*Styles for screen 1000px and lower*/ 
@media screen and (max-width: 1000px) { 
    nav ul { 
     width: 100%; 
    } 

    nav li { 
     width: 12.5%; 
    } 

    nav a { 
     width: 100%; 
    } 
} 
+0

謝謝@Mathias它的工作。所以根據屏幕尺寸我們給出它們的百分比值。根據它適應的大小。 –