【发布时间】:2018-12-03 22:50:03
【问题描述】:
这是我在这里的第一篇文章,因为我真的很难过。在使用主容器集中所有内容后,我决定转向网格布局以允许将来添加诸如侧边栏之类的内容。然而,当我这样做时,我的主要部分已被大大向下移动,留下一个看起来甚至不是边缘的大间隙,只是空白空间。这是我第一次尝试自定义 css、html 网站,因此非常感谢任何帮助。 密码笔: https://codepen.io/weirdflex/pen/MzxqdY 再次感谢!
HTML:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>MayMays</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" type="text/css" media="screen" href="main.css" />
<script src="main.js"></script>
</head>
<body>
<nav class = "main-nav">
<a href = "#" class="nav-link"><img class="logo" src="/Images/logo.png" alt="Logo"></a>
<a href = "#" class="nav-link">Home</a>
<a href = "#" class="nav-link">Revision</a>
<a href = "#" class="nav-link">Quiz</a>
<a href = "#" class="nav-link right">Forums</a>
<a href = "#" class="nav-link right">Contact Us</a>
</nav>
<section class="main-content">
<div class="container">
<p>Lorem ipsum dolor sit amet consectetur adipisicing elit. Quis animi aliquam consequuntur et illum, nisi porro eaque sint alias accusantium voluptates fugit, rerum nihil voluptas consectetur molestiae accusamus excepturi cupiditate?</p>
</div>
</section>
</body>
</html>
CSS:
@import url('https://fonts.googleapis.com/css?family=Roboto:300,400,500,700');
body {
background-color: #583a7a;
background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='100%25' height='100%25' viewBox='0 0 2 1'%3E%3Cdefs%3E%3ClinearGradient id='a' gradientUnits='userSpaceOnUse' x1='0' x2='0' y1='0' y2='1' gradientTransform='rotate(178,0.5,0.5)'%3E%3Cstop offset='0' stop-color='%23583a7a'/%3E%3Cstop offset='1' stop-color='%230691b0'/%3E%3C/linearGradient%3E%3ClinearGradient id='b' gradientUnits='userSpaceOnUse' x1='0' y1='0' x2='0' y2='1' gradientTransform='rotate(166,0.5,0.5)'%3E%3Cstop offset='0' stop-color='%23fd9bff' stop-opacity='0'/%3E%3Cstop offset='1' stop-color='%23fd9bff' stop-opacity='1'/%3E%3C/linearGradient%3E%3ClinearGradient id='c' gradientUnits='userSpaceOnUse' x1='0' y1='0' x2='2' y2='2' gradientTransform='rotate(0,0.5,0.5)'%3E%3Cstop offset='0' stop-color='%23fd9bff' stop-opacity='0'/%3E%3Cstop offset='1' stop-color='%23fd9bff' stop-opacity='1'/%3E%3C/linearGradient%3E%3C/defs%3E%3Crect x='0' y='0' fill='url(%23a)' width='2' height='1'/%3E%3Cg fill-opacity='0'%3E%3Cpolygon fill='url(%23b)' points='0 1 0 0 2 0'/%3E%3Cpolygon fill='url(%23c)' points='2 1 2 0 0 0'/%3E%3C/g%3E%3C/svg%3E");
background-attachment: fixed;
background-size: cover;
font-family: 'Roboto', sans-serif;
height: 200vh;
margin: 0;
display: grid;
grid-template-columns: 1fr 960px 1fr;
}
body * {
text-decoration: none;
color: white;
}
.container {
width: 900px;
margin: 0 auto;
}
.logo {
height: 50px;
}
.main-nav {
height: 80px;
width: 100%;
grid-column: 2;
}
.main-content {
height: 100vh;
background: #ffffff57;
box-shadow: 0px 0px 100px #000000;
grid-column: 2;
}
.nav-link {
line-height: 50px;
vertical-align: middle;
text-transform: uppercase;
font-weight: 700;
padding: 1rem 2rem;
float: left;
}
.right {
float: right;
}
PS。请原谅糟糕的格式 idk 人们如何正确地将代码粘贴到这里
【问题讨论】:
-
欢迎来到 SO!我们一起建立知识。这一次你是来寻求帮助的,但未来你会帮助别人
-
@RodneySalcedo 谢谢,希望如此 :)
-
尝试将
height: 200vh;更改为 ccs 中 body 块内的height: 2vh; -
@RodneySalcedo 非常感谢,甚至不知道为什么我之前设置了高度:D