小编Yai*_*air的帖子

为什么填充扩展弹性项?

在下面的代码段中,第一行有两个div flex-grow: 1.正如预期的那样,每个div占据屏幕的50%.

向左侧div添加填充时,情况就不再如此.有人可以解释原因吗?

body > div {
  height: 50px;
  display: flex;
}
body > div > div {
  flex: 1;
  box-sizing: border-box;
}
#a {
  background-color: red;
}
#b {
  background-color: green;
}
#c {
  padding: 10px;
  background-color: blue;
}
#d {
  background-color: yellow;
}
Run Code Online (Sandbox Code Playgroud)
<div>
  <div id="a"></div>
  <div id="b"></div>
</div>
<div>
  <div id="c"></div>
  <div id="d"></div>
</div>
Run Code Online (Sandbox Code Playgroud)

html css css3 border-box flexbox

19
推荐指数
2
解决办法
9132
查看次数

标签 统计

border-box ×1

css ×1

css3 ×1

flexbox ×1

html ×1