如何使网格容器完全符合页面的全尺寸?
学习网格显示,无法弄清楚如何使网格完整大小页面。例如:
.wrapper {
display: grid;
border-style: solid;
grid-template-columns: auto auto auto;
grid-template-rows: auto auto auto;
grid-template-areas:
'a a a'
'a a a'
'b b b';
}
.first {
background-color: grey;
grid-area: a;
}
.second {
grid-area: b;
background-color: red;
}
<!DOCTYPE html>
<html lang="en" dir="ltr">
<head>
<meta charset="utf-8">
<title>Oil Tycoon</title>
<link rel="stylesheet" href="./css/index.css">
</head>
<body>
<div class="wrapper">
<div class="first">
123
</div>
<div class="second">
123456
</div>
</div>
</body>
</html>
这是由两个元素挑选的三列,但它们的屏幕尺寸不像网格 - 板块区域一样。如何使网格全屏制作?
Learning grid display and can't figure out how to make grid full size of a page. for example:
.wrapper {
display: grid;
border-style: solid;
grid-template-columns: auto auto auto;
grid-template-rows: auto auto auto;
grid-template-areas:
'a a a'
'a a a'
'b b b';
}
.first {
background-color: grey;
grid-area: a;
}
.second {
grid-area: b;
background-color: red;
}
<!DOCTYPE html>
<html lang="en" dir="ltr">
<head>
<meta charset="utf-8">
<title>Oil Tycoon</title>
<link rel="stylesheet" href="./css/index.css">
</head>
<body>
<div class="wrapper">
<div class="first">
123
</div>
<div class="second">
123456
</div>
</div>
</body>
</html>
here's three columns that picked by two element but they are not in a full size of a screen as should grid-template-area do. how do i make grid fullscreen?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我认为这是由于浏览器内置边距或填充物所致。看看正常化重置浏览器默认样式行为。
我添加了
此删除的默认样式从身体重置的边距和填充。然后,您可以将自己的保证金添加到元素中。
I think this is due to browsers having built in margin or padding. Take a look at Normalize which resets browsers default styling behaviour.
I have added
This removes margin and padding from the body resetting its default styles., you can then add you own margin to your elements.
人体只会伸展到满足于填充空间的满足感。因此,您应该给网格和身体一个100VH的高度。 VH的意思是“视口高”。
您可以在CodePen上使用解决方案: https://codepen.io/jensgro/pen /bglyxvy?编辑= 1100
欢呼,詹斯
The body will only stretch as far as there will be content to fill the space. Therefor you should give both the grid and the body a min-height of 100vh. vh means "viewport height".
You can play with the solution on Codepen: https://codepen.io/jensgro/pen/bGLyXVy?editors=1100
Cheers, Jens