我想创建一个带有下拉菜单的导航栏,但是我的下拉菜单与主菜单重叠。我想将下拉菜单放在主菜单下。我如何将带有div标签的下拉菜单稍微向下移动以与主菜单的结尾匹配。 稍后,我将其隐藏起来,并且仅在将鼠标悬停在主菜单选项上时才可用。
<!DOCTYPE html>
<html>
<head>
<title>GTU Students-Care</title>
<meta name="viewport" content="width= device-width, initial-scale=1.0">
<link href="https://fonts.googleapis.com/css?
family=Assistant|Barlow|Dosis|Gothic+A1|Monoton|Open+Sans|Roboto" rel="stylesheet">
<style type="text/css">
header {
background-color: #5495ff;
color: white;
padding: 35px;
}
#gtu-header-home {
text-align: center;
font-weight: lighter;
font-size: 3.5em;
font-family:'Barlow', sans-serif;
text-shadow: -1px 0px blue, 0px 1px blue, 1px 0px blue, 0px -1px blue;
}
#gtu-header-detail {
text-align: center;
font-family: 'Roboto', sans-serif;
font-size: 25px;
}
#footer-copyright {
text-align: center;
font-size: 20px;
font-family: 'Barlow', sans-serif;
}
footer {
background-color: #9baac4;
padding: 25px;
}
ul.navbar {
list-style-type: none;
margin: 0px;
padding: 0px;
background-color: gray;
}
.navbar a{
text-decoration: none;
display: block;
color: white;
padding: 10px;
}
.navbar li{
font-size: 26px;
font-family: 'Barlow', sans-serif;
display: inline-block;
padding: 10px;
}
#innerlist-1, #innerlist-2 {
background-color: white;
position: absolute;
min-width: 3cm;
}
.innerlist a{
color: gray;
padding: 0px;
}
</style>
</head>
<body>
<header>
<h1 id="gtu-header-home">GTU Students Care</h1>
<p id="gtu-header-detail">Tutorials | Question papers | Solution</p>
</header>
<ul class="navbar">
<li><a href="#">Semester</a>
<div id="innerlist-1" class="innerlist">
<a href="#">First</a>
<a href="#">Second</a>
<a href="#">Third</a>
</div>
</li>
<li><a href="#">Branch</a>
<div id="innerlist-2" class="innerlist">
<a href="#">Computer</a>
<a href="#">Electronics</a>
<a href="#">Civil</a>
</div>
</li>
</ul>
<footer>
<div>
<p id="footer-copyright">Copyright@ GTU Students Care</p>
</div>
</footer>
</body>
</html>
答案 0 :(得分:0)
我修复了您的代码,并在悬停时显示了下拉列表。我认为这会对您有所帮助
rev = (rev * 10) +temp
header {
background-color: #5495ff;
color: white;
padding: 35px;
}
#gtu-header-home {
text-align: center;
font-weight: lighter;
font-size: 3.5em;
font-family:'Barlow', sans-serif;
text-shadow: -1px 0px blue, 0px 1px blue, 1px 0px blue, 0px -1px blue;
}
#gtu-header-detail {
text-align: center;
font-family: 'Roboto', sans-serif;
font-size: 25px;
}
#footer-copyright {
text-align: center;
font-size: 20px;
font-family: 'Barlow', sans-serif;
}
footer {
background-color: #9baac4;
padding: 25px;
}
ul.navbar {
list-style-type: none;
margin: 0px;
padding: 0px;
background-color: gray;
}
.navbar a{
text-decoration: none;
display: block;
color: white;
padding: 20px;
}
.navbar li{
font-size: 26px;
font-family: 'Barlow', sans-serif;
display: inline-block;
}
#innerlist-1, #innerlist-2 {
background-color: white;
position: absolute;
min-width: 3cm;
}
.innerlist{
display:none;
}
.navbar > li:hover .innerlist{
display:block;
}
.innerlist a{
color: gray;
padding: 0px;
}