在CSS中设置网格?
我是CSS和HTML的新手,并且在CSS中设置了DIVS,类似的是:
#topBar {
margin-top: 0;
height: 100px;
width: 100%
}
#sideBar {
width: 50px;
margin-left: 0;
margin-top: 100px;
height: 100%;
}
#main {
margin-left: 50px;
margin-top: 100px;
margin-bottom: 50px;
}
#footer {
margin-bottom: 0;
width: 100%;
}
<div id="container">
<div id="topbar" />
<div id="sidebar" />
<div id="main" />
<div id="footer" />
</div>
但这看起来不像我想要的。即使它们的空间仅限于x宽度和x高度,它也会为每个div留出空间。
我该如何设置Divs以应有的需求?即CSS中有一个页脚,主,侧边栏和Topbar?
I am new to CSS and HTML and have a setup of divs in CSS, something like this:
#topBar {
margin-top: 0;
height: 100px;
width: 100%
}
#sideBar {
width: 50px;
margin-left: 0;
margin-top: 100px;
height: 100%;
}
#main {
margin-left: 50px;
margin-top: 100px;
margin-bottom: 50px;
}
#footer {
margin-bottom: 0;
width: 100%;
}
<div id="container">
<div id="topbar" />
<div id="sidebar" />
<div id="main" />
<div id="footer" />
</div>
But that does not look anything like how I want it. It leaves space for every div, even though their space is restricted to x width and x height.
How could I set up divs to look as desired? Ie have a footer, main, sidebar, and topbar in CSS?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
CSS实际上具有您可以使用的网格“构建器”内置。我不久前就在做类似的事情,最终这样做了:
CSS actually has built in grid "builder" that you can use. I was doing something similar not long ago and ended up doing it like this:
您应该使用语义标签,例如
header
,nav
,旁边
,footer
and code> mainmain < /代码>。
然后将网格直接应用于身体元件,而不是将它们包裹在额外的容器中:
You should use the semantic tags such as the
header
,nav
,aside
,footer
andmain
.Then apply the grid directly to the body element instead of wrapping them in an extra container: