首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >边距增加了其他div的大小

边距增加了其他div的大小
EN

Stack Overflow用户
提问于 2021-10-03 14:08:14
回答 1查看 33关注 0票数 0

因此,我一直在学习网格系统,并遇到了一些让我非常困惑的事情。当我出于某种原因想要给其中一个div设置下边距时,它会增加它旁边的div的高度。你知道我错过了什么吗?所以我给了.box-2一个100px的底部边距,同时在底部创建了100px的空间,而它旁边的.box-1会增加高度。

代码语言:javascript
复制
.container
{
display:grid;
grid-template-columns:1fr 1fr
}

.item
{
  border:2px solid;
  text-align:center;
}

.box-1
{
  background-color:blue;
}

.box-2
{
  background-color:purple;
  margin-bottom:100px
}

.box-3
{
  background-color:orange;
}

.box-4
{
  background-color:red;
}
代码语言:javascript
复制
<div class = "container">
<div class = "item box-1">
  <h1>One</h1>
</div>

<div class = "item box-2">
   <h1>Two</h1>
</div>
  

<div class = "item box-3">
   <h1>Three</h1>
</div>

<div class = "item box-4">
   <h1>Four</h1>
</div>
</div>

EN

回答 1

Stack Overflow用户

发布于 2021-10-03 14:35:17

我想这就是你想要实现的。

代码语言:javascript
复制
.container
{
display:grid;
grid-template-columns:1fr 1fr;
}

.item
{
  border:2px solid;
  text-align:center;
}

.box-1
{
  background-color:blue;
  
}

.box-2
{
  background-color:purple;
  
 
}

.box-3
{
  background-color:orange;
  margin-bottom:100px;
}

.box-4
{
  background-color:red;
}
代码语言:javascript
复制
<div class = "container">
  <div>
<div class = "item box-1">
  <h1>One</h1>
</div>

<div class = "item box-2">
   <h1>Two</h1>
</div>
   </div>
  
<div>
<div class = "item box-3">
   <h1>Three</h1>
</div>

<div class = "item box-4">
   <h1>Four</h1>
</div>
</div>
</div>

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/69425605

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档