如果将fieldset
元素设置为display: grid
,则grid-gap
将不起作用。
fieldset#grid {
display: grid;
grid-gap: 10px;
box-sizing: border-box;
border: solid red 1px;
}
.child {
padding: 15px;
background: blue;
}
<fieldset id='grid'>
<div class='child'>
<div>gc1</div>
<div>gc2</div>
</div>
<div class='child'>c2</div>
<div class='child'>c3</div>
<div class='child'>c4</div>
<div class='child'>c5</div>
</fieldset>
div#grid {
display: grid;
grid-gap: 10px;
box-sizing: border-box;
border: solid red 1px;
}
.child {
padding: 15px;
background: blue;
}
<div id='grid'>
<div class='child'>
<div>gc1</div>
<div>gc2</div>
</div>
<div class='child'>c2</div>
<div class='child'>c3</div>
<div class='child'>c4</div>
<div class='child'>c5</div>
</div>
您可以将fieldset
更改为div
,一切正常。完全相同的代码。唯一的区别是元素。
为什么会这样?
我该如何解决?