我今晚开始潜入html / css,偶然发现了路障。我正在尝试为我的GitHub页面创建一个导航栏,它在桌面视图上显示得很好。导航栏将固定在桌面视图上,但在移动视图中,我希望将其保留在页面顶部。
我想删除导航栏上方的间隙,但无法弄清楚如何。
html, body {
height: 100%; margin: 0; padding: 0; padding-top: 40px;
}
body {
font-family: sans-serif;
background: #daf2ea
}
a {
text-decoration: none;
}
.navbar {
height: 40px;
background: #333;
color: #eee;
padding-top: 7px;
padding-bottom: 7px;
box-shadow: 0 0 5px #777;
position: fixed;
top: 0;
width: 100%;
}
.navbar h1 {
font-weight: 300;
font-size: 26px;
margin-top: 4px;
margin-left: 20px;
padding-top: 0;
text-shadow: 0 1px 2px #000;
float: left;
}
.navbar a {color:white;}
.navbar a:hover {text-decoration: underline;}
.navbar ul {
list-style-type: none;
margin: 0;
padding: 0;
overflow: hidden;
background-color: #333;
}
.navbar li {float: left;}
.navbar li a {
display: block;
color: white;
text-align: center;
padding: 14px 16px;
text-decoration: none;
}
@media screen and (max-width: 600px) {
.navbar {
position: static;
top: auto;
width: auto;
padding-bottom: 14px;
}
.navbar h1 {
float: none;
text-align: center;
margin-left: 0px;
}
.navbar li {float: none;}
.navbar li a:hover {
background-color: #1384c1;
}
}
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8"/>
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Lukasz Salitra - Home</title>
<link rel="stylesheet" type="text/css" href="css/style.css">
</head>
<body>
<div class="navbar">
<h1><a href="index.html">Lukasz Salitra</a></h1>
<ul>
<li>
<a href="index.html">Home</a>
</li>
<li>
<a href="about.html">About</a>
</li>
<li>
<a href="contact.html">Contact</a>
</li>
</ul>
</div>
</body>
<html>
答案 0 :(得分:1)
只需从padding-top: 40px;
选择器中移除html
行。
html, body {
height: 100%; margin: 0; padding: 0;
}