我是一个CSS启动器,我的纯CSS下拉列表无效。
此jsfiddle中的示例:https://jsfiddle.net/uevewfsy/
我一直在互联网上四处寻找并尝试自己解决这个问题,但我尝试了无数的东西,但仍然没有修复。浮动:左;在初级ul似乎修复它,但然后我的导航不再居中。
希望有人可以帮助我,以便我可以再次进行编程;)
* {
padding: 0;
margin: 0;
border: 0;
}
html, body {
height: 100%;
width: 100%;
font-family: 'Open Sans', sans-serif;
}
h1 {
font-weight: 100;
}
.nav {
width: 100%;
height: 10%;
background-color: #333;
text-align: center;
position: fixed;
z-index: 150;
}
.nav ul {
height: 100%;
width: 100%;
}
.nav > ul > li {
display: inline-block;
list-style: none;
margin: 0 20px 0 20px;
}
.nav > ul > li:first-child > a:after {
width: 6px;
height: 6px;
border-bottom: 1px solid white;
border-right: 1px solid white;
position: absolute;
margin-top: calc(5vh - 5px);
margin-left: 8px;
content: "";
transform: rotate(45deg);
}
.nav > ul > li > ul {
display: none;
}
.nav > ul > li > ul > li {
list-style: none;
background-color: #333;
padding: 0 15px 0 15px;
}
.nav li:hover > ul {
display: block;
}
.nav ul a {
color: #A3ABA3;
text-decoration: none;
line-height: 10vh;
}
.nav a:hover {
color: #FFF;
}
@media only screen and (max-device-width: 480px){
}
<body>
<div class="nav">
<ul>
<li>
<a href="#">PAGE</a>
<ul>
<li><a href="#">DROPDOWN</a></li>
<li><a href="#">DROPDOWN</a></li>
</ul>
</li>
<li><a href="#">PAGE</a></li>
<li><a href="#">PAGE</a></li>
<li><a href="#">PAGE</a></li>
</ul>
</div>
</body>
答案 0 :(得分:0)
您在vertical-align:top
,
nav > ul > li
您也可以position:relative/top
添加li/ul
。
* {
padding: 0;
margin: 0;
border: 0;
}
html,
body {
height: 100%;
width: 100%;
font-family: 'Open Sans', sans-serif;
}
h1 {
font-weight: 100;
}
.nav {
width: 100%;
height: 10%;
background-color: #333;
text-align: center;
position: fixed;
z-index: 150;
}
.nav ul {
height: 100%;
width: 100%;
}
.nav > ul > li {
display: inline-block;
list-style: none;
padding: 0 20px;
vertical-align: top
}
.nav > ul > li:first-child > a:after {
width: 6px;
height: 6px;
border-bottom: 1px solid white;
border-right: 1px solid white;
position: absolute;
margin-top: calc(5vh - 5px);
margin-left: 8px;
content: "";
transform: rotate(45deg);
}
.nav > ul > li > ul {
display: none;
}
.nav > ul > li > ul > li {
list-style: none;
background-color: #333;
padding: 0 15px;
position:relative
}
.nav li:hover > ul {
display: block;
position:absolute;
top:100%;
width:30%
}
.nav ul a {
color: #A3ABA3;
text-decoration: none;
line-height: 10vh;
}
.nav a:hover {
color: #FFF;
}
@media only screen and (max-device-width: 480px) {}
<body>
<div class="nav">
<ul>
<li>
<a href="#">PAGE</a>
<ul>
<li><a href="#">DROPDOWN</a>
</li>
<li><a href="#">DROPDOWN</a>
</li>
</ul>
</li>
<li><a href="#">PAGE</a>
</li>
<li><a href="#">PAGE</a>
</li>
<li><a href="#">PAGE</a>
</li>
</ul>
</div>
</body>