每当我尝试为ul元素使用id元素选择器时,我遇到了问题。当我使用当前注释掉的代码时
/*#wrapper h1, h2, ul {
text-align: center;
font-weight: bold;
padding: 10px 0;
}*/
我的嵌套下拉菜单变得不合适,但它不应该这样做,因为我的导航栏甚至没有包含在包装器中。
* {
margin: 0;
padding: 0;
}
html,
body {
margin: 0;
padding: 0;
height: 100%;
width: 100%;
}
body {
padding: 0;
margin: 0;
font-family: 'Lato', Arial, sans-serif;
}
header {
background-color: #595959;
color: #fff;
padding-top: 30px;
min-height: 90px;
border-bottom: 3px solid #FFD700;
}
header .banner {
float: left;
}
header .banner h1 {
margin: 0;
}
header nav {
float: right;
margin-top: 10px;
}
header ul {
float: left;
}
header li {
float: left;
position: relative;
width: 150px;
list-style: none;
}
header a {
display: block;
text-decoration: none;
font-size: 16px;
padding: 5px 15px;
color: #fff;
border: 2px solid black;
background: #595959;
font-weight: bold;
}
header a:hover {
color: #FFD700;
}
header ul ul {
position: absolute;
left: 0;
top: 100%;
visibility: hidden;
opacity: 0;
}
header ul ul ul {
left: 100%;
top: 0;
}
header li:hover,
header li:hover li,
header li li:hover,
header li li:hover li,
header li li li:hover {
background: rgba(89, 89, 89, 0.9);
transition-duration: 0.5s;
}
header li:hover>ul {
visibility: visible;
opacity: 1;
}
/*#wrapper h1, h2, ul {
text-align: center;
font-weight: bold;
padding: 10px 0;
}*/
<!DOCTYPE html>
</head>
<body>
<header>
<div id="banner-container">
<div class="banner">
<h1>A-Level</h1>
<nav>
<ul>
<li><a href="home.php">Home</a></li>
<li><a href="#">A-level</a>
<ul>
<li><a href="#">Maths</a>
<ul>
<li><a href="mathsPLC.php">PLC</a></li>
<li><a href="revisionMaths.php">Revision</a></li>
<li><a href="mathsPapers.php">Exam Papers</a></li>
</ul>
</li>
<li><a href="#">Physics</a>
<ul>
<li><a href="physicsPLC.php">PLC</a></li>
<li><a href="revisionPhysics.php">Revision</a></li>
<li><a href="physicsPapers.php">Exam Papers</a></li>
</ul>
</li>
<li><a href="#">Computer Science</a>
<ul>
<li><a href="computingPLC.php">PLC</a></li>
<li><a href="revisionComputing.php">Revision</a></li>
<li><a href="computingPapers.php">Exam Papers</a></li>
</ul>
</li>
</ul>
</li>
<li><a href="index.php">TimeTable</a></li>
<li><a href="logout.php">Logout</a></li>
</ul>
</nav>
</header>
</body>
答案 0 :(得分:0)
通过定义&#39; h1,h2&amp; UL&#39;在#wrapper中,#wrapper中的那些元素将获得您正在定义的CSS。要在#wrapper中使用它们,请使用#wrapper h1,#wrapper h2等。