gpt4 book ai didi

css - 使用显示网格时,主要内容部分向下移动,留下很大的差距

转载 作者:行者123 更新时间:2023-11-27 22:59:04 25 4
gpt4 key购买 nike

这是我在这里发表的第一篇文章,因为我真的很困惑。在使用主容器集中所有内容后,我决定移动到网格布局以允许将来添加,如侧边栏。但是,当我这样做时,我的主要部分已经大大向下移动,留下了一个很大的差距,看起来甚至不是空白,只是空白。这是我第一次尝试自定义 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;
}

附言。请原谅糟糕的格式,我知道人们如何正确地将代码粘贴到这里

最佳答案

您需要从主体 CSS 中删除 height: 200vh; 以删除出现的新空间。

从您的设计来看,我假设您希望您的主要内容因框阴影而“ float ”。我在 .main-content CSS 中添加了 margin-bottom: 50px; 以保持这种效果。

@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;
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;
margin-bottom: 50px;
}

.nav-link {
line-height: 50px;
vertical-align: middle;
text-transform: uppercase;
font-weight: 700;
padding: 1rem 2rem;
float: left;
}

.right {
float: right;
}
<!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 - 使用显示网格时,主要内容部分向下移动,留下很大的差距,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53603134/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com