我想了解如何以最簡單和最乾淨的方式創建下拉導航欄。我遵循這個wiki how僅CSS的下拉菜單指南,但看起來我的代碼與建議的添加項不兼容。CSS - 有人可以幫我弄清楚我的下拉菜單導航出錯了嗎?
有人能告訴我代碼中的衝突發生在哪裏,或者是否有更簡單的方法來實現下拉菜單(如果更容易,熟悉jQuery/JavaScript)?
HTML:
<!DOCTYPE html>
<html>
<head>
<link type="text/css" rel="stylesheet" href="template_ss.css"/>
<title></title>
</div>
</head>
<body>
<!--------------------------header--------------------------->
<div id="headerDiv">
<div id="titleDiv">
<p id= "titleText"><span>Your</span>Uni<span>verse</span></p>
</div>
<div class="navDiv">
<ul class="navUL">
<li><a href="#!">Home</a></li>
<li>
<a href="#!">Universe</a>
<ul class="dropdown">
<li><a href="#!">1</a></li>
<li><a href="#!">2</a></li>
<li><a href="#!">3</a></li>
</ul>
</li>
<li>
<p><a href="#!">Browse</a></p>
<ul class="dropdown">
<li><a href="#!">Planets</a></li>
<li><a href="#!">Galaxies</a></li>
<li><a href="#!">Odities</a></li>
</ul>
</li>
<li>
<p><a href="#!">Random</a></p>
<ul class="dropdown">
<li><a href="#!">Quantum</a></li>
<li><a href="#!">Solar</a></li>
<li><a href="#!">Projectile</a></li>
</ul>
</li>
<li>
<p><a href="#!">Profile</a></p>
<ul class="dropdown">
<li><a href="#!">My profile</a></li>
<li><a href="#!">Edit profile</a></li>
</ul>
</li>
<li>
<p><a href="#!">How it works</a></p>
</li>
</ul>
</div>
<div class="searchDiv">
<form>
<input type="text" placeholder="explore..." required>
<input type="button" value="Search">
</form>
</div>
<!---------------------------body--------------------------->
<div class="bodyDiv"></div>
</body>
</html>
CSS:
/*-------------------header----------------------*/
body{
margin:0px;
}
#headerDiv{
position: fixed;
height:12%;
width:100%;
background-image:url("deepspace.png");
background-repeat:repeat-x;
text-align: center;
}
#titleDiv{
width: auto;
margin: auto 0;
}
#titleText{
color:white;
font-size:130%;
text-allign:center;
font-family:verdana,san serif;
}
span:first-child{
color:blue;
}
span{
color:purple;
}
.navDiv{
display:inline-block;
}
.navUL{
position:relative;
display:inline-block;
list-style-type:none;
margin: auto 0;
padding:0;
border-top:1 solid;
border-right:1 solid;
border-left:1 solid;
width:100%;
}
.navUL:after{
content:"";
display:table;
}
.navUL li{
padding: .2em 2em;
margin:2em,2em,2em,2em;
color: #fff;
background-color: #036;
display:inline-block;
text-align:center;
}
.dropdown{
position:absolute;
display:none;
background-color:white;
}
.navUL ul li:hover > ul{
display:inline;
}
.navUL>ul>li:after{
content:"\25BC";
font-size:.5em;
display:inline;
position:relative;
}
.searchDiv{
display:inline-block;
}
/*------------------body--------------------*/
.bodyDiv{
text-align:center;
float:left;
background-color:grey;
height:80%;
width:70%;
position:relative;
top:80%;
left:50%;
-ms-transform: translate(-50%, -50%);
-webkit-transform: translate(-50%,-50%);
transform: translate(-50%,-50%);
}
jsfiddle請..... –