我创建了一个导航栏,您可以在https://jsfiddle.net/atgdLafa/
中查看其代码并有两个问题:
1-为什么<div>
容器的 id name 和<ul>
必须相同?如果我更改主容器的id名称,则列表的排列会更改。< / p>
2 - 我如何改变列表之间的差距(假设'家'和'音乐')
#navcontainer{
height: 35px;
width: 1000px;
background-color: #ffffff;
padding-right: 0px;
margin-top: 0px;
margin-right: auto;
margin-left: auto;
margin-bottom: 0px;
border:1px solid #f2f2f2;
}
/*styling navigation bar*/
#navcontainer ul {
height: 35px;
background: #ffffff;
list-style : none;
float: right;
width:990px;
background-color:#ffffff;
font-family: Tahoma;
margin: auto 0;
padding-right:0px;
}
#navcontainer ul li {
display: inline-block;
border-top-left-radius: 5px;
border-top-right-radius: 5px;
overflow:hidden;
}
#navcontainer ul li a {
text-decoration:none;
float:right;
text-align:center;
line-height:35px;
font:Tahoma;
}
#navcontainer ul li a:hover {
color:#ffffff;
}
li.home a {color: #ffffff;background-color: #0a0a5c; font-weight:bold; font: Tahoma ; font-size: 12px; height:35px; width:80px; }
li.musicarchive a {color:#ffffff; background-color: #0a0a5c; font-weight:bold; font-size: 12px; height:35px; width:120px; }
li.health a {color:#ffffff; background-color: #0a0a5c; font-weight:bold; font-size: 12px; height:35px; width:90px;}
li.artandculture a {color:#ffffff; background-color: #0a0a5c; font-weight:bold; font-size: 12px; height:35px;width:120px;}
li.tech a {color: #ffffff; background-color: #0a0a5c ; font-weight:bold; font-size: 12px; height:35px; width:110px;}
li.home a:hover {background: #bb0700;}
li.musicarchive a:hover {background: #dd423b ;}
li.health a:hover {background: #B3DE83;}
li.artandculture a:hover {background: #dd423b;}
li.tech a:hover {background:#646373 ;}
<div id="navcontainer">
<ul id="navcontainer" dir="rtl" >
<li class="home"><a href="./index.php" >home</a></li>
<li class="musicarchive"><a href="music/index.php" >music</a></li>
<li class="health"><a href="health/health.php">health</a></li>
<li class="artandculture"><a href="./artandculture/artandculture.php">art</a></li>
<li class="tech"><a href="./tech/tech.php">tech</a></li>
</ul>
</div><!-- end of nav -->
答案 0 :(得分:1)
从id
移除ul
- 您不需要使用CSS。
更改margin-left
规则的#navcontainer ul li
以更改标签之间的间距:
#navcontainer {
height: 35px;
width: 1000px;
background-color: #ffffff;
padding-right: 0px;
margin-top: 0px;
margin-right: auto;
margin-left: auto;
margin-bottom: 0px;
border: 1px solid #f2f2f2;
}
/*styling navigation bar*/
#navcontainer ul {
height: 35px;
background: #ffffff;
list-style: none;
float: right;
width: 990px;
background-color: #ffffff;
font-family: Tahoma;
margin: auto 0;
padding-right: 0px;
}
#navcontainer ul li {
display: inline-block;
border-top-left-radius: 5px;
border-top-right-radius: 5px;
overflow: hidden;
margin-left: 10px; /* Increase space between tabs */
}
#navcontainer ul li a {
text-decoration: none;
float: right;
text-align: center;
line-height: 35px;
font: Tahoma;
}
#navcontainer ul li a:hover {
color: #ffffff;
}
li.home a {
color: #ffffff;
background-color: #0a0a5c;
font-weight: bold;
font: Tahoma;
font-size: 12px;
height: 35px;
width: 80px;
}
li.musicarchive a {
color: #ffffff;
background-color: #0a0a5c;
font-weight: bold;
font-size: 12px;
height: 35px;
width: 120px;
}
li.health a {
color: #ffffff;
background-color: #0a0a5c;
font-weight: bold;
font-size: 12px;
height: 35px;
width: 90px;
}
li.artandculture a {
color: #ffffff;
background-color: #0a0a5c;
font-weight: bold;
font-size: 12px;
height: 35px;
width: 120px;
}
li.tech a {
color: #ffffff;
background-color: #0a0a5c;
font-weight: bold;
font-size: 12px;
height: 35px;
width: 110px;
}
li.home a:hover {
background: #bb0700;
}
li.musicarchive a:hover {
background: #dd423b;
}
li.health a:hover {
background: #B3DE83;
}
li.artandculture a:hover {
background: #dd423b;
}
li.tech a:hover {
background: #646373;
}
<div id="navcontainer">
<ul dir="rtl">
<li class="home"><a href="./index.php">home</a>
</li>
<li class="musicarchive"><a href="music/index.php">music</a>
</li>
<li class="health"><a href="health/health.php">health</a>
</li>
<li class="artandculture"><a href="./artandculture/artandculture.php">art</a>
</li>
<li class="tech"><a href="./tech/tech.php">tech</a>
</li>
</ul>
</div>
<!-- end of nav -->