为什么在此实现中未应用 100% 宽度(该类uk-width-1-1
应用于网格容器的子对象的嵌套 div):
<div uk-grid>
<!-- column 01 -->
<div>
<!-- this will be a row, stacked -->
<div class="uk-width-1-1 mine">Row 01</div>
<!-- this will be a row, stacked -->
<div class="mine">Row 02</div>
</div>
</div>
但是,它在像这样实现时应用(类uk-width-1-1
应用于网格容器的子级):
<div uk-grid>
<!-- column 01 -->
<div class="uk-width-1-1">
<!-- this will be a row, stacked -->
<div class="mine">Row 01</div>
<!-- this will be a row, stacked -->
<div class="mine">Row 02</div>
</div>
</div>
我可以看到如何达到我想要的效果,但想知道它背后的逻辑是什么,以便我更好地理解它。
显示这两种实现的 jsFiddle 在这里。
编辑:
我可以仅使用 flex 样式复制行为 - 所以我需要弄清楚为什么子 div 可以是 100% 而嵌套 div 不能?
<!-- nested div is only the width of the content -->
<div style="display:flex; flex-wrap: wrap">
<div>
<div style="width:100%; background: red">Item 1</div>
<div style="width:100%; background: red">Item 2</div>
</div>
</div>
<!-- if applied to child div, is 100% width of parent -->
<div style="display:flex; flex-wrap: wrap">
<div style="width:100%">
<div style="background: red">Item 1</div>
<div style="background: red">Item 2</div>
</div>
</div>
<!-- if not using flex at all, nested divs are 100% width of parent -->
<div>
<div>
<div style="width:100%; background: red">Item 1</div>
<div style="width:100%; background: red">Item 2</div>
</div>
</div>
也许 a flex item
,它是 a 中的任何直接子 div flex container
,默认情况下是其内容的宽度,因此嵌套 div,如果给定width: 100%
,忠实地表示其直接父容器宽度的 100%,而不是定义的顶级容器display: flex
?