难以到达<p>并<ul>处于同一高度

  • 本文关键字:高度 ul 于同一 html css
  • 更新时间 :
  • 英文 :


我最近刚开始进行web开发,但我遇到了这个问题:我无法在标题中获得相同高度的h1和ul。我试着在ul上加边距,然后在li上加边距或在上面加填充。h1也是如此。我知道这可能是一个简单的问题,但我不知道如何解决它

body {
font-family: arial;
background: #333;
margin: 0px;
padding: 0px;
height: 100%;
width: 100%;
}
body header {
font-size: 20px;
background: black;
color: white;
padding: 5px 0px 3px 10px; 
margin: 0px;
}
body header h1 {
display: inline;
font-weight: normal;
margin: 40px 5px 0px 0px; 
padding: 20px;
font-size: 40px;
margin-top: 50px;
}
body header ul {
display: inline;
}
body header ul li {
list-style-type: none;
display: inline-block;
margin: 0px 5px 10px 10px;
}
body header ul li a {
color: white;
text-decoration: none;
border: 1px solid white;
border-radius: 3px;
padding: 5px 15px 5px 15px; 
background: #222;
}
body header ul li a:hover {
color: green;
}
<!DOCTYPE html>
<html>
<link rel="stylesheet" type="text/css" href="styles/Skulldozer%201.1.css">
<head>
<title>Example</title>
</head>
<body>
<header> 
<h1>Example</h1>
<ul>
<li><a href="">Posts</a></li>
<li><a href="">Stories</a></li>
<li><a href="">Contact</a></li>
</ul>
</header> 
<div>

</div>

<script src="scripts/Skulldozer%201.1.js"></script>
</body>
</html>

我添加了vertical-align: bottom;,我相信它可以解决您的问题。

body {
font-family: arial;
background: #333;
margin: 0px;
padding: 0px;
height: 100%;
width: 100%;
}
header {
font-size: 20px;
background: black;
color: white;
padding: 5px 0px 3px 10px; 
margin: 0px;
}
header h1 {
display: inline;
font-weight: normal;
margin: 40px 5px 0px 0px; 
padding: 20px;
font-size: 40px;
margin-top: 50px;
vertical-align: bottom;
}
header ul {
display: inline;
}
header ul li {
list-style-type: none;
display: inline-block;
margin: 0px 5px 10px 10px;
}
header ul li a {
color: white;
text-decoration: none;
border: 1px solid white;
border-radius: 3px;
padding: 5px 15px 5px 15px; 
background: #222;
}
header ul li a:hover {
color: green;
}
<!DOCTYPE html>
<html>
<link rel="stylesheet" type="text/css" href="styles/Skulldozer%201.1.css">
<head>
<title>Example</title>
</head>
<body>
<header> 
<h1>Example</h1>
<ul>
<li><a href="">Posts</a></li>
<li><a href="">Stories</a></li>
<li><a href="">Contact</a></li>
</ul>
</header> 
<div>

</div>

<script src="scripts/Skulldozer%201.1.js"></script>
</body>
</html>

最新更新