我想创建一个Flex Box Grid
,当超出最大尺寸时,会在row
和wraps
中显示元素。我可以在不覆盖grid
的情况下创建flex box items
。
https://jsfiddle.net/2ykn7jLs/1/
但是,我希望小矩形覆盖大的矩形。它们应放在大矩形的左上角。每当我使用诸如positioning
或absolute
之类的relative
时,它就会破坏grid
。我如何覆盖flex box grid
?
答案 0 :(得分:1)
将position:relative
提交至.input-color
并在此课程position:absolute
中添加.input-color .color-box-small
。
.grid {
display: flex;
flex-Direction: row;
flex-wrap: wrap;
justify-content: space-evenly;
}
.input-color .color-box-small {
width: 10px;
height: 10px;
display: inline-block;
background-color: #ccc;
position: absolute;
}
.input-color .color-box-large {
width: 290px;
height: 40px;
display: inline-block;
background-color: #ccc;
}
.input-color {
position: relative;
}

<div class="grid">
<div class="input-color">
<div class="color-box-small" style="background-color: orange;"></div>
<div class="color-box-large" style="background-color: green;"></div>
</div>
<div class="input-color">
<div class="color-box-small" style="background-color: white;"></div>
<div class="color-box-large" style="background-color: black;"></div>
</div>
<div class="input-color">
<div class="color-box-small" style="background-color: navy;"></div>
<div class="color-box-large" style="background-color: steelblue;"></div>
</div>
<div class="input-color">
<div class="color-box-small" style="background-color: orange;"></div>
<div class="color-box-large" style="background-color: green;"></div>
</div>
</div>
&#13;
答案 1 :(得分:0)
你需要我在这里的位置:
更新CSS以应用:
.input-color {
position: relative;
}
.input-color .color-box-small {
position: absolute;
top: 0;
left: 0;
}
https://jsfiddle.net/2ykn7jLs/3/
.grid {
display: flex;
flex-Direction: row;
flex-wrap: wrap;
justify-content: space-evenly;
}
.input-color {
position: relative;
}
.input-color .color-box-small {
position: absolute;
top: 0;
left: 0;
width: 10px;
height: 10px;
display: inline-block;
background-color: #ccc;
}
.input-color .color-box-large {
width: 290px;
height: 40px;
display: inline-block;
background-color: #ccc;
}
<div class="grid">
<div class="input-color">
<div class="color-box-small" style="background-color: orange;"></div>
<div class="color-box-large" style="background-color: green;"></div>
</div>
<div class="input-color">
<div class="color-box-small" style="background-color: white;"></div>
<div class="color-box-large" style="background-color: black;"></div>
</div>
<div class="input-color">
<div class="color-box-small" style="background-color: navy;"></div>
<div class="color-box-large" style="background-color: steelblue;"></div>
</div>
<div class="input-color">
<div class="color-box-small" style="background-color: orange;"></div>
<div class="color-box-large" style="background-color: green;"></div>
</div>
</div>