我刚刚受伤如何让导航菜单覆盖整个div的宽度,因为我似乎无法做到这一点帮助会非常感激
以下是jsfiddle示例:http://jsfiddle.net/PJ6FR/
由于
<html>
<style>
* {
margin: 0px;
padding: 0px;
}
ul#navmenu, ul.sub1, ul.sub2 {
list-style-type: none;
font-size: 9pt;
}
ul#navmenu li {
width: 125px;
text-align: center;
position: relative;
margin-right: 0px;
float: left;
}
#navmenu ul {
display: inline-block;
list-style-type: none;
}
#page1 {text-align: center;}
ul#navmenu a {
text-decoration: none;
display: block;
width: 125px;
height: 30px;
line-height: 25px;
background-color: #2E2E2E;
border: 1px solid #777777;
border-top: 2px solid #777777;
color: white;
font-family: Arial, sans-serif;
font-weight: bold;
font-face: Arial;
float: left;
text-align: center;
}
ul#navmenu .sub1 a {
margin-top: 0px;
}
ul#navmenu .sub2 a {
margin-left: 0px;
}
ul#navmenu li:hover > a {
background-color: grey;
}
ul#navmenu li:hover a:hover {
background-color: red;
}
ul#navmenu ul.sub1 {
display: none;
position: absolute;
top: 30px;
left: 0px;
}
ul#navmenu ul.sub2 {
display: none;
position: absolute;
top: 0px;
left: 126px;
}
ul#navmenu li:hover .sub1 {
display: block;
}
ul#navmenu .sub1 li:hover .sub2 {
display: block;
}
.darrow {
font-size: 8pt;
position: absolute;
top: 8px;
right: 1px;
}
#navmenu {
display: inline-block;
text-align: center;
list-style-type: none;
margin: 0px auto;
padding: 0px;
position: relative;
border: 2px solid green;
}
.rarrow {
font-size: 8pt;
position: absolute;
top: 6px;
right: 0px;
}
#page1 .link1{
color: grey;
border-top: 2px solid red;
}
#page2 .link2{
color: grey;
border-top: 2px solid red;
}
#page3 .link3{
color: grey;
border-top: 2px solid red;
}
.container{
width: 100%;
min-width: 1024px;
max-width: 1440px;
height: 1000px;
margin: 0px auto;
}
#box2{
height: 1000px;
width: 100%;
background-color: yellow;
float: left;
margin: 0px auto;
}
#boxinbox1 {
width: 100%;
height: 200px;
background-color: red;
}
</style>
</head>
<body>
<div class="container">
<div id="box2">
<div id="page1"><div id="boxinbox1">weiuhgqiogq</div>
<ul id="navmenu">
<li><a href="dropdown1.html" class="link1">Home</a></li>
<li><a href="dropdown2.html" class="link2">hyperlink 2</a><font color="white">
<span class="darrow">▼</font></span>
<ul class="sub1">
<li><a href="#">hyperlink 2.1</a></li>
<li><a href="#">hyperlink 2.2</a></li>
<li><a href="#">hyperlink 2.3</a></li>
</ul>
</li>
<li><a href="#">hyperlink 3</a></li>
<li><a href="#">hyperlink 4</a><span class="darrow"><font color="white">▼
</font></span>
<ul class="sub1">
<li><a href="#">hyperlink 4.1</a></li>
<li><a href="#">hyperlink 4.2</a></li>
<li><a href="#">hyperlink 4.3</a><span class="rarrow">
<font color="white">▶</font></span>
<ul class="sub2">
<li><a href="#">hyperlink 4.3.1</a></li>
<li><a href="#">hyperlink 4.3.2</a></li>
<li>
<a href="dropdown3.html" class="link3">hyperlink 4.3.3</a></li>
</ul>
</li>
</ul>
</li>
<li><a href="#">hyperlink 5</a></li>
</ul></div></div>
</div>
</body>
</html>
答案 0 :(得分:0)
答案 1 :(得分:0)
添加:
#navmenu {
width:100%;
display:inline-block;
}
#navmenu li {
width:20%!important;
}
#navmenu a {
width:100%!important;
display:inline-block;
}
答案 2 :(得分:0)
<强> DEMO 强>
其他解决方案可行,但每次添加或删除项目时都必须调整宽度...
这是我添加的CSS:
#navmenu{
width: 100%;
display:table;
}
ul#navmenu > li{
display:table-cell;
float: none;
}
ul#navmenu > li li{
width: 100%;
}
#navmenu li .navmenu__wrap{
position:relative;
width: 100%;
}
#navmenu li a{
width: 100%;
}
还添加了一个额外的div来将li
宽度内的所有元素包裹在此类navmenu__wrap
中以保持位置相对。