我正在创建一个网站,当我尝试将其放置在页面中间时,我的导航栏下拉列表与父导航栏没有对齐。当我使用相对定位时,它不会排列。这是我的代码:
nav ul ul {
display: none;
margin: 0;
padding: 10px;
list-style-type: none;
text-align: center;
background-color: #A7C5A5;
}
nav ul li:hover > ul {
display: block;
}
nav ul {
text-decoration: none;
padding: 0em;
color: #030;
background-color: #A7C5A5;
font-family: Georgia, "Times New Roman", Times, serif;
list-style: none;
position: relative;
display: inline-table;
top: 60px;
left: 300px;
float: inherit;
}
nav ul:after {
content: "";
clear: both;
display: block;
}
nav ul li {
float: left;
display: inline;
}
nav ul li:hover {
background: #4b545f;
}
nav ul li:hover a {
color: #000;
background-color: #CCC;
}
nav ul li a {
display: block;
padding: 25px 40px;
color: #757575;
text-decoration: none;
}
nav ul ul {
background-color: #A7C5A5;
border-radius: 0px;
padding: 0;
position: relative;
top: 60px;
left: 300px;
}
nav ul ul li {
float: none;
border-top: 1px solid #6b727c;
border-bottom: 1px solid #575f6a;
position: relative;
}
nav ul ul li a {
padding: 15px 40px;
color: #fff;
}
nav ul ul li a:hover {
color: #000;
background-color: #CCC;
}

<body>
<div id="bg-right"></div>
<div id="bg-left"></div>
<div class="img">
<img src="greenlogo.jpg" width="504" height="160">
</div>
<nav>
<ul>
<li><a href="#"> Home</a></li>
<li><a href="#">Animals</a>
<ul>
<li><a href="#">Disney</a></li>
<li><a href="#">Farm</a></li>
<li><a href="#">Nickolodean</a>
</ul>
</li>
<li><a href="#">About</a></li>
<li><a href="#">Contact</a></li>
</ul>
</nav>
</body>
&#13;
答案 0 :(得分:0)
我试图为私人做一个小提琴,我在Chrome-Devconsole中看到一些样式被双重使用或用于你不会被使用的地方。我建议使用不同ul的类
Devlen