如何去除导航条和头标之间的白色间隙



我只想知道如何去除页眉前后的白色间隙。如果可能的话,你能编辑我的代码吗顺便说一句,我只是一个初学者,还没有写过这段代码。我抄袭了W3Schools的spome。

这是我的代码

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
<style>
body {
font-family: Arial, Helvetica, sans-serif;
}

.navbar {
overflow: hidden;
background-color: #333;
}

.navbar a {
float: left;
font-size: 16px;
color: white;
text-align: center;
padding: 14px 16px;
text-decoration: none;
}

.dropdown {
float: left;
overflow: hidden;
}

.dropdown .dropbtn {
font-size: 16px;
border: none;
outline: none;
color: white;
padding: 14px 16px;
background-color: inherit;
font-family: inherit;
margin: 0;
}

.navbar a:hover,
.dropdown:hover .dropbtn {
background-color: MediumSeaGreen;
}

.dropdown-content {
display: none;
position: absolute;
background-color: #f9f9f9;
min-width: 160px;
box-shadow: 0px 8px 16px 0px rgba(0, 0, 0, 0.2);
z-index: 1;
}

.dropdown-content a {
float: none;
color: black;
padding: 12px 16px;
text-decoration: none;
display: block;
text-align: left;
}

.dropdown-content a:hover {
background-color: #ddd;
}

.dropdown:hover .dropdown-content {
display: block;
}

.auto-style2 {
text-align: center;
}
</style>
<meta content="en-us" http-equiv="Content-Language" />
<meta content="text/html; charset=utf-8" http-equiv="Content-Type" />
</head>
<body>
<h1 style="background-color:MediumSeaGreen;" class="auto-style2">The Logic Store</h1>
<margin: 0px;>
</body>
<margin: 0px;>
</html>
<!DOCTYPE html>
<div class="navbar" style="height: 45px">
<a href="#home">Home</a>
<div class="dropdown" style="height: 45px">
<button class="dropbtn">Phones
</button>
<div class="dropdown-content">
<a href="#">Apple</a>
<a href="#">Samsung</a>
<a href="#">Google</a>
</div>
</div>
<div class="dropdown" style="height: 45px">
<button class="dropbtn">Laptops
</button>
<div class="dropdown-content">
<a href="#">Apple</a>
<a href="#">HP</a>
<a href="#">Dell</a>
</div>
</div>
<a href="#about">About</a>
</div>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<style>
body {
margin: 0;
font-family: Arial, Helvetica, sans-serif;
}

.topnav {
overflow: hidden;
background-color: #333;
}

.topnav a {
float: left;
color: #f2f2f2;
text-align: center;
padding: 14px 16px;
text-decoration: none;
font-size: 17px;
}

.topnav a:hover {
background-color: #ddd;
color: black;
}

.topnav a.active {
background-color: #04AA6D;
color: white;
}
</style>
</head>
<body>
</body>
</html>
<html>
<body>
</body>
</html>

正如您所看到的,在页眉之前和页眉和导航栏之间有一个间隙。

对于您提供的这个示例,您必须将css分配给h1标记。否则,用户代理样式将优先。

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
<style>
body {
font-family: Arial, Helvetica, sans-serif;
}
h1 {
margin: 0px;
}

.navbar {
overflow: hidden;
background-color: #333;
}

.navbar a {
float: left;
font-size: 16px;
color: white;
text-align: center;
padding: 14px 16px;
text-decoration: none;
}

.dropdown {
float: left;
overflow: hidden;
}

.dropdown .dropbtn {
font-size: 16px;
border: none;
outline: none;
color: white;
padding: 14px 16px;
background-color: inherit;
font-family: inherit;
margin: 0;
}

.navbar a:hover,
.dropdown:hover .dropbtn {
background-color: MediumSeaGreen;
}

.dropdown-content {
display: none;
position: absolute;
background-color: #f9f9f9;
min-width: 160px;
box-shadow: 0px 8px 16px 0px rgba(0, 0, 0, 0.2);
z-index: 1;
}

.dropdown-content a {
float: none;
color: black;
padding: 12px 16px;
text-decoration: none;
display: block;
text-align: left;
}

.dropdown-content a:hover {
background-color: #ddd;
}

.dropdown:hover .dropdown-content {
display: block;
}

.auto-style2 {
text-align: center;
}
</style>
<meta content="en-us" http-equiv="Content-Language" />
<meta content="text/html; charset=utf-8" http-equiv="Content-Type" />
</head>
<body>
<h1 style="background-color:MediumSeaGreen;" class="auto-style2">The Logic Store</h1>
<margin: 0px;>
</body>
<margin: 0px;>
</html>
<!DOCTYPE html>
<div class="navbar" style="height: 45px">
<a href="#home">Home</a>
<div class="dropdown" style="height: 45px">
<button class="dropbtn">Phones
</button>
<div class="dropdown-content">
<a href="#">Apple</a>
<a href="#">Samsung</a>
<a href="#">Google</a>
</div>
</div>
<div class="dropdown" style="height: 45px">
<button class="dropbtn">Laptops
</button>
<div class="dropdown-content">
<a href="#">Apple</a>
<a href="#">HP</a>
<a href="#">Dell</a>
</div>
</div>
<a href="#about">About</a>
</div>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<style>
body {
margin: 0;
font-family: Arial, Helvetica, sans-serif;
}

.topnav {
overflow: hidden;
background-color: #333;
}

.topnav a {
float: left;
color: #f2f2f2;
text-align: center;
padding: 14px 16px;
text-decoration: none;
font-size: 17px;
}

.topnav a:hover {
background-color: #ddd;
color: black;
}

.topnav a.active {
background-color: #04AA6D;
color: white;
}
</style>
</head>
<body>
</body>
</html>
<html>
<body>
</body>
</html>

最新更新