【发布时间】:2017-04-06 06:56:06
【问题描述】:
我是 HTML 和 CSS 的新手,现在我正在关注 this 教程。我的问题see picture 是我的下拉列表中的项目不在一条垂直线上,而是全部杂乱无章。
我确定这是一个简单解决方案的简单问题,但我在寻找解决方案方面没有任何进展......
如果有一些建议,我将不胜感激! :)
* {
margin: 0;
}
h1, h2, h3, h4, h5, h6, p {
margin-bottom: 10px;
}
/* ----- NAVIGATION BAR ----- */
#nav {
width:500px;
margin-left: auto;
margin-right: auto;
margin-top: 20px;
margin-bottom: 20px;
text-align: center;
background-color: none;
}
#nav ul {
padding: 0;
list-style: none;
position: relative;
display: inline-table;
}
#nav ul:after{
content: "";
clear: both;
display: block;
}
#nav ul li {
float: left;
}
#nav ul li a {
display: block;
padding: 10px 20px;
color: black;
text-decoration: none;
font-family: "Trocchi", serif;
}
#nav ul li:hover {
background: #76C5CF;
}
#nav ul li:hover a {
color: white;
}
#nav ul ul {
display: none;
background: none;
position: absolute;
top: 100%;
}
#nav ul li:hover > ul {
display: block;
}
/* ----- HEADER ----- */
#header {
width: 340px
margin: auto;
margin-top: 10px;
text-align: center;
}
#header h1 {
height: 50px;
font-family: "Trocchi", serif;
background-color:
}
#header h2 {
font-family: "Trocchi", serif;
position: relative;
display: inline;
}
/* ----- BACKGROUND ----- */
body {
background-color: #A6D7F3;
}
<!DOCTYPE html>
<html lang="en">
<head>
<title> Harley's Haunts </title>
<link rel="stylesheet" type="text/css" href="harleysHaunts.css">
<style>
@import url('https://fonts.googleapis.com/css?family=Trocchi');
</style>
</head>
<body>
<div id="header">
<h1> HARLEY'S HAUNTS </h1>
<h2> It's a dog's world after all </h2>
</div>
<div id="nav">
<ul>
<li><a href="#"> About </a></li>
<li><a href="#"> Pet-Friendly Venues </a>
<ul>
<li><a href="#"> Cafes </a> </li>
<li><a href="#"> Restaurants </a> </li>
<li><a href="#"> Pubs/Bars </a> </li>
<li><a href="#"> Shops </a> </li>
</ul>
</li>
<li><a href="#"> Contact </a></li>
</ul>
</div>
</body>
</html>
【问题讨论】:
-
尝试使用
inline-block而不是inline-table。 -
不幸的是,这并不能解决问题。不过谢谢你的建议!原来我需要在我的“#nav ul li {”下添加“位置:相对”
标签: css hover html-lists block unordered