2016-08-17 88 views
-3

下面的代碼有問題。 菜單欄的CSS代碼似乎與HTML一起工作。如何修復CSS代碼以使其適用於我的HTML?

<!DOCTYPE html> 
 
<html> 
 
<body class="news"> 
 
    <head> 
 
    <style type="text/css">body { 
 
    margin: 0; 
 
    padding: 0; 
 
    background: #ccc; 
 
} 
 
    
 
.nav ul { 
 
    list-style: none; 
 
    background-color: #444; 
 
    text-align: center; 
 
    padding: 0; 
 
    margin: 0; 
 
} 
 
.nav li { 
 
    font-family: 'Oswald', sans-serif; 
 
    font-size: 1.2em; 
 
    line-height: 40px; 
 
    height: 40px; 
 
    border-bottom: 1px solid #888; 
 
} 
 
    
 
.nav a { 
 
    text-decoration: none; 
 
    color: #fff; 
 
    display: block; 
 
    transition: .3s background-color; 
 
} 
 
    
 
.nav a:hover { 
 
    background-color: #005f5f; 
 
} 
 
    
 
.nav a.active { 
 
    background-color: #fff; 
 
    color: #444; 
 
    cursor: default; 
 
} 
 
    
 
@media screen and (min-width: 600px) { 
 
    .nav li { 
 
    width: 120px; 
 
    border-bottom: none; 
 
    height: 50px; 
 
    line-height: 50px; 
 
    font-size: 1.4em; 
 
    } 
 
    
 
    /* Option 1 - Display Inline */ 
 
    .nav li { 
 
    display: inline-block; 
 
    margin-right: -4px; 
 
    } 
 
    
 
    /* Options 2 - Float 
 
    .nav li { 
 
    float: left; 
 
    } 
 
    .nav ul { 
 
    overflow: auto; 
 
    width: 600px; 
 
    margin: 0 auto; 
 
    } 
 
    .nav { 
 
    background-color: #444; 
 
    } 
 
    */ 
 
}</style> 
 
    </head> 
 
    <header> 
 
    <div class="nav"> 
 
     <ul> 
 
     <li class="home"><a href="#">Home</a></li> 
 
     <li class="tutorials"><a class="active" href="#">About</a></li> 
 
     <li class="about"><a href="#">Newsletter</a></li> 
 
     <li class="news"><a href="#">Media</a></li> 
 
     <li class="contact"><a href="#">Contact</a></li> 
 
     </ul> 
 
    </div> 
 
    </header> 
 
</body> 
 
</html>

我不明白爲什麼代碼不能正常工作。

+1

你想才達到什麼?請重新編寫您的問題並清楚說明您的問題。 –

+1

這肯定不能幫助你的''標籤在''標籤內。 *''之前應該有''到''的所有內容。 –

回答

0

這是正確的代碼,你需要...

body { 
 
    margin: 0; 
 
    padding: 0; 
 
    background: #ccc; 
 
} 
 
    
 
.nav ul { 
 
    list-style: none; 
 
    background-color: #444; 
 
    text-align: center; 
 
    padding: 0; 
 
    margin: 0; 
 
} 
 
.nav li { 
 
    font-family: 'Oswald', sans-serif; 
 
    font-size: 1.2em; 
 
    line-height: 40px; 
 
    height: 40px; 
 
    border-bottom: 1px solid #888; 
 
} 
 
    
 
.nav a { 
 
    text-decoration: none; 
 
    color: #fff; 
 
    display: block; 
 
    transition: .3s background-color; 
 
} 
 
    
 
.nav a:hover { 
 
    background-color: #005f5f; 
 
} 
 
    
 
.nav a.active { 
 
    background-color: #fff; 
 
    color: #444; 
 
    cursor: default; 
 
} 
 
    
 
@media screen and (min-width: 600px) { 
 
    .nav li { 
 
    width: 120px; 
 
    border-bottom: none; 
 
    height: 50px; 
 
    line-height: 50px; 
 
    font-size: 1.4em; 
 
    } 
 
    
 
    /* Option 1 - Display Inline */ 
 
    .nav li { 
 
    display: inline-block; 
 
    margin-right: -4px; 
 
    } 
 
    
 
    /* Options 2 - Float 
 
    .nav li { 
 
    float: left; 
 
    } 
 
    .nav ul { 
 
    overflow: auto; 
 
    width: 600px; 
 
    margin: 0 auto; 
 
    } 
 
    .nav { 
 
    background-color: #444; 
 
    } 
 
    */ 
 
}
<!DOCTYPE html> 
 
<html> 
 
<body class="news"> 
 
    <head> 
 
    </head> 
 
    <header> 
 
    <div class="nav"> 
 
     <ul> 
 
     <li class="home"><a href="#">Home</a></li> 
 
     <li class="tutorials"><a class="active" href="#">About</a></li> 
 
     <li class="about"><a href="#">Newsletter</a></li> 
 
     <li class="news"><a href="#">Media</a></li> 
 
     <li class="contact"><a href="#">Contact</a></li> 
 
     </ul> 
 
    </div> 
 
    </header> 
 
</body> 
 
</html>

相關問題