簡體   English   中英

如何使導航菜單欄不遍及整個頁面

[英]How To Make The Nav MenuBar Not Go Across The Whole Page

我建立了一個導航菜單欄,但是背景色遍及整個頁面,這不是我想要的。 這是我的CSS:

body {
    padding: 0;
    margin: 0;
    font-family: Arial;
    font-size: 19px;
}
#nav {
    background-color: #222;
    }
#nav_wrapper {
    width: 960px;
    margin: 0 auto;
    text-align: left;
}
#nav ul {
    list-style-type: none;
    padding: 0;
    margin: 0;
    position: relative;
    min-width: 200px;
}
#nav ul li {
    display: inline-block;
    }
#nav ul li:hover {
    background-color: #333;
}
#nav ul li a, visited {
    color: #CCC;
    display: block;
    padding: 15px;
    text-decoration: none;
}
#nav ul li:hover ul {
    display: block;
}
#nav ul ul {
    display: none;
    position: absolute;
    background-color: #333;
    border: 5px solid #222;
    border-top: 0;
    margin-left: -5px;
}
#nav ul ul li {
    display: block;
}
#nav ul ul li a:hover {
    color: #699;
}
#nav {
background-color: #222;
}

在這里,您可以調整導航欄的寬度和高度,否則應發布HTML示例以查看您的結構

這應該工作。

#nav {
    width: 50%; /*basically how much you want it to span*/
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM