我正在尝试重新创建网站模板,但是菜单和子菜单存在一些问题。当我想将鼠标悬停在子菜单上时,它消失了,并且我知道它可能是从该空白处开始的,但是我不必删除边距怎么办?
这是我的完整代码:http://dontpad.com/claustack
这是我要复制的模板:https://www.templatemonster.com/demo/69211.html
<body>
<div class="nav center">
<img src="logo.png"/ id="logo">
<ul>
<li><a href="#">Home</a></li>
<li><a href="#">About Us</a></li>
<li><a href="#">Departments <span style="font-size:12px">∨ </span></a>
<div class="subMenuBox1">
<ul class="subMenu1">
<li><a href="#">Dental</a></li>
<li><a href="#">Cardiology</a></li>
<li><a href="#">Neurology</a></li>
<li><a href="#">Pediatric</a></li>
</ul>
<ul class="subMenu2">
<li><a href="#">Pulmonary</a></li>
<li><a href="#">Ophtalmology</a></li>
<li><a href="#">Traumatology</a></li>
<li><a href="#">Diagnostics</a></li>
</ul>
</div>
</li>
<li><a href="#">Timetable</a></li>
<li><a href="#">Pages <span style="font-size:12px">∨ </span></a></li>
<li><a href="#">Contacts</a></li>
</ul>
</div>
</body>
CSS:
html,body {
margin:0;
width:100%;
height:100%;
padding:0;
}
.center {
margin:0 auto;
display:table;
}
li {
list-style: none;
}
#logo {
float:left;
position:absolute;
left:-350px;
top:50px;
}
.nav {
position:relative;
padding-top:90px;
padding-bottom:90px;
}
.nav ul li {
float:left;
font-size:16px;
padding:0 30px;
}
.nav ul li a {
color:black;
}
.nav ul li a:hover {
color:#00bb6d;
text-decoration: none;
}
.subMenuBox1 {
width:330px;
height:150px;
border-bottom:2px solid green;
display:none;
box-shadow:0 0 5px 0 gray;
margin-top:30px;
z-index:999;
background-color:white;
}
.subMenu1 {
position:absolute;
z-index:999;
margin-top:20px;
}
.subMenu1 li {
float:left;
clear:left;
margin-bottom:10px;
}
.subMenu1 li a {
font-size:12.5px;
}
.nav li:hover .subMenu1{
display:block;
}
.nav li:hover .subMenuBox1{
display:block;
position:absolute;
}
答案 0 :(得分:2)
您的代码的边距为20px margin-top:20px;
。如果将此值设置为零并与padding-top:20px;
一起使用,它将起作用。
它仍然有些混乱,但是那部分:)
html,
body {
margin: 0;
width: 100%;
height: 100%;
padding: 0;
}
.center {
margin: 0 auto;
display: table;
}
li {
list-style: none;
}
#logo {
float: left;
position: absolute;
left: -350px;
top: 50px;
}
.nav {
position: relative;
padding-top: 90px;
padding-bottom: 90px;
}
.nav ul li {
float: left;
font-size: 16px;
padding: 0 30px;
}
.nav ul li a {
color: black;
}
.nav ul li a:hover {
color: #00bb6d;
text-decoration: none;
}
.subMenuBox1 {
width: 250px;
height: 150px;
border-bottom: 2px solid green;
display: none;
box-shadow: 0 0 5px 0 gray;
margin-top: 30px;
z-index: 999;
background-color: white;
}
.subMenu1,
.subMenu2 {
position: absolute;
z-index: 999;
margin-top: 20px;
padding: 0;
}
.subMenu1 li,
.subMenu2 li {
float: left;
clear: left;
margin-bottom: 10px;
}
.subMenu1 li a,
.subMenu2 li a {
font-size: 12.5px;
}
.subMenu2 {
left: 100px;
/*border-left: 1px solid #333;*/
}
.nav li:hover .subMenuBox1 {
display: block;
position: absolute;
margin-top: 0;
}
<div class="nav center">
<img src="logo.png" / id="logo">
<ul>
<li><a href="#">Home</a></li>
<li><a href="#">About Us</a></li>
<li><a href="#">Departments <span style="font-size:12px">∨ </span></a>
<div class="subMenuBox1">
<ul class="subMenu1">
<li><a href="#">Dental</a></li>
<li><a href="#">Cardiology</a></li>
<li><a href="#">Neurology</a></li>
<li><a href="#">Pediatric</a></li>
</ul>
<ul class="subMenu2">
<li><a href="#">Pulmonary</a></li>
<li><a href="#">Ophtalmology</a></li>
<li><a href="#">Traumatology</a></li>
<li><a href="#">Diagnostics</a></li>
</ul>
</div>
</li>
<li><a href="#">Timetable</a></li>
<li><a href="#">Pages <span style="font-size:12px">∨ </span></a></li>
<li><a href="#">Contacts</a></li>
</ul>
</div>