我试图创建一个可悬停的导航栏,当你悬停相关链接时,它似乎没有在下面对齐,当位置不是绝对时,它会在悬停后将其他链接推到一边
HTML
<html>
<head>
<link rel="stylesheet" type="text/css" href="testsitestyle.css">
</head>
<body>
<div id="nav">
<ul>
<li id="drop2">Home<li/>
<ul>
<li>Number</li>
<li>One</li>
</ul>
</li>
<li>Knowledge</li>
<li>Qoutes</li>
<li>Contact</li>
</ul>
</div>
</body>
</html>
Css
html, body{
height:100%;
width:100%;
padding:0;
margin:0;
}
#nav {
width:100%;
max-height:100%;
text-align:center;
}
#nav ul {
padding:0;
margin:0;
}
#nav li {
text-align:center;
text-decoration:none;
display:inline-block;
text-transform:uppercase;
font-family:Arial;
font-size:18px;
margin-top:0px;
margin-left:40px;
margin-right:40px;
padding:30px;
vertical-align:top;
border:2px solid red;
position:relative;
}
#drop2 ul {
padding:0;
margin:0px;
display:none;
position:absolute;
border:2px solid red;
}
#drop2 ul li {
text-align:center;
text-decoration:none;
text-transform:uppercase;
font-family:Arial;
font-size:18px;
``padding:30px;
margin:0px;
margin-top:25px;
}
#drop2:hover>ul{
display:block;
}
答案 0 :(得分:0)
我已经在他们周围放置了红色寄宿生,以向您展示我正在努力创造的东西。 example
答案 1 :(得分:0)
这部分基于Thoughtbot的Refills / Empties(http://empties.bourbon.io/),应该让你开始。如果您关注创建响应式导航菜单(在移动设备和桌面设备上运行良好),我建议您查看他们的代码示例,以便自己排序。
body {
font-family: Arial, sans-serif;
}
nav ul {
clear: both;
margin: 0;
overflow: visible;
padding: 0;
}
nav ul li.nav-link {
display: inline-block;
text-align: center;
}
nav li.nav-link a {
display: inline-block;
font-size: 18px;
padding: 30px;
text-decoration: none;
text-transform: uppercase;
}
.hover-menu {
overflow: visible;
position: relative;
}
.hover-menu .hover-menu-item {
left: 0;
position: relative;
}
.hover-menu .submenu {
display: none;
left: 0;
position: absolute;
}
.hover-menu .submenu li {
display: block;
}
.hover-menu .submenu li a {
text-align: left;
width: 12em;
}
.hover-menu .submenu .submenu {
left: 12em;
top: 0;
}
.hover-menu:focus > .submenu,
.hover-menu:hover > .submenu {
display: block;
}
<nav role="navigation">
<ul>
<li class="nav-link hover-menu">
<a href="javascript:void(0)" class="hover-menu-item">Home</a>
<ul class="submenu">
<li><a href="#">Number</a>
</li>
<li><a href="#">One</a>
</li>
</ul>
</li>
<li class="nav-link"><a href="javascript:void(0)">Knowledge</a>
</li>
<li class="nav-link"><a href="javascript:void(0)">Quotes</a>
</li>
<li class="nav-link"><a href="javascript:void(0)">Contract</a>
</li>
</ul>
</nav>