gpt4 book ai didi

html - 为什么父无序列表项内的子无序列表不占用其父元素的整个可用空间?

转载 作者:太空宇宙 更新时间:2023-11-04 11:56:40 26 4
gpt4 key购买 nike

ul 没有占用它可用的总宽度(与其父 ul 元素容器相同)。此外,悬停似乎根本不会影响其背景颜色,尽管背景颜色属性已在悬停时设置。如果有人能指出我在这里遗漏的基本概念并帮助我修复它们,我将不胜感激。这是我的 HTML 代码片段(这里是 jsfiddle ):

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<style>
*{
margin:0px;
padding:0px;
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
box-sizing: border-box; <!--Specifies an element should have padding and border included in element's total width and height-->
<!--Content Box is the default value for the height and width properties-->
}
<!--Resetter rules for browsers-->
#bodyContainer {
}
body {
border:black 2px solid;
background-color : grey;
padding:5px;
}
div#header {
margin:10px auto;
background-color : red;
width:70%;
-webkit-border-radius:15px;
-moz-border-radius:15px;
border-radius:15px;
}
div#header1 {
display:inline-block;
width:50%;
text-align:center;
line-height:80px;
}
div#header2 {
display:inline-block;
width:50%;
text-align:center;
line-height:80px;
}
ul#navmenu , ul.sub1{
list-style-type:none;
background-color:#444;
margin-bottom:20px;
border-radius:5px;
}
ul#navmenu li {
border:black 1px solid;
background:yellow;
border-radius:5px;
height:30px;
text-align:center;
line-height:30px;
width:33.33%;
float:left;
position:relative;
}
ul#navmenu a {
text-decoration:none;
width:100%;
display:block;
}
ul#navmenu li ul.sub1 li {
border:black 1px solid;
background:yellow;
border-radius:5px;
height:30px;
text-align:center;
line-height:30px;
width:100%;
}
ul#navmenu li ul {
position:absolute;
display:none;
}
ul#navmenu li:hover ul{
background-color:#FC6;
display:block;
}


</style>
<title>Untitled Document</title>
</head>

<body>
<div id="bodyContainer">
<div id="header">
<div id="header1"><h1>Welcome</h1></div><div id="header2"><h1>You Get to choose better !! </h1></div>
</div>
<div id="content">
<div id="contentHeader">
<p>You Select ... We Serve </p>
</div>
<div id="nav">
<ul id="navmenu">
<li><a href="#">Home</a>
<ul class="sub1">
<li><a href="#">Home1</a></li>
<li><a href="#">Home2</a></li>
<li><a href="#">Home3</a></li>
</ul>
</li>
<li><a href="#">Electronics</a></li>
<li><a href="#">Fashions</a></li>
</ul>
</div>
</div>
<div id="sidebar">
</div>
<div id="footer">
<p>WebApp Version Numbered v1.0. All rights Reserved. </p>
</div>
</div>
</body>
</html>

最佳答案

参见 updated jsfiddle :

ul#navmenu li ul.sub1 {
width: 100%;
}

只需将整个 ul 设置为 100%,而不仅仅是 li

之前:

before

之后:

after

关于html - 为什么父无序列表项内的子无序列表不占用其父元素的整个可用空间?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30153711/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com