为什么背景颜色不显示?
我正在尝试制作一个占据 100% 高度的页面,分为红、蓝、绿。我用 css 网格做到了这一点,但背景颜色没有显示。
有人可以向我解释为什么它不显示以及如何修复它吗?
body, html {
margin: 0;
padding: 0;
font-family: 'lato', sans-serif;
}
.container {
display: grid;
grid-template-columns: repeat(12, 1fr);
grid-template-rows: 100%;
grid-template-areas:
"l l l c c c c c c c r r";
}
.left-area {
grid-area: l;
background-color: red;
}
.chat-area {
grid-area: c;
background-color: green;
}
.right-area {
grid-area: r;
background-color: blue;
}
I'm trying to make a page that takes up 100% of the height split into red, blue, green. I did that with css grid but the background colour isn't showing up.
Could someone explain to me why its not showing up and how to fix it?
body, html {
margin: 0;
padding: 0;
font-family: 'lato', sans-serif;
}
.container {
display: grid;
grid-template-columns: repeat(12, 1fr);
grid-template-rows: 100%;
grid-template-areas:
"l l l c c c c c c c r r";
}
.left-area {
grid-area: l;
background-color: red;
}
.chat-area {
grid-area: c;
background-color: green;
}
.right-area {
grid-area: r;
background-color: blue;
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
元素中没有内容,因此从技术上讲它们的高度为 0px,宽度为 0px。您可以使用
宽度
&height
CSS 属性来指定其大小,或者只是将内容放入其中 - 执行任一操作都会显示元素的background-color
There is no content in your
<div>
elements, so they are technically 0px height and 0px width. You can use thewidth
&height
CSS-properties to specify their size, or simply just put content into them - doing either will show the element'sbackground-color
我认为发生这种情况是因为
div
元素内部没有任何内容。您可以在其中放置一些东西或在您的区域中定义一个height: 100vh
。I think that's happening because the
div
elements don't have any content inside them. You can put somenthing inside them or define aheight: 100vh
into your areas.默认情况下,
.container
和body
的高度都不大于零。要解决此问题,请为body
元素添加宽度和高度,并为.container
元素添加高度。下面是一个应该按预期工作的示例。By default, neither your
.container
nor thebody
has a height greater than zero. To fix this, add a width and height to thebody
element as well as a height to the.container
element. Below is an example that should work as expected.