问题描述
我是CSS网格的新手,所以我在Codepen中玩CSS,我想知道应该写些什么才能将div向上移动以填充其他div留下的位置。 This is my codepen
awk -v range="4-5" ' ##Starting awk program from here creating range variable which has range value of positions which we do not want to print in lines.
BEGIN{ ##Starting BEGIN section of this program from here.
split(range,array,"-") ##Splitting range variable into array with delimiter of - here.
start=array[1] ##Assigning 1st element of array to start variable here.
end=array[2] ##Assigning 2nd element of array to end variable here.
}
{
print substr($0,1,start-1) substr($0,end+1) ##Printing sub-string of current line from 1 to till value of start-1 and then printing from end+1 which basically means will skip that range of characters which OP does not want to print.
}
' Input_file ##Mentioning Input_file name here.
<div class="wrapper">
<div class="box a">A</div>
<div class="box b">B</div>
<div class="box c">C</div>
<div class="box d">D</div>
<div class="box e">E</div>
<div class="box f">F</div>
</div>
如何使框f浮动到其他两个框所在的位置?另外,当框c较大并且我想使框f与框c底部对齐时会发生什么?
解决方法
添加grid-auto-flow: dense;align-items: end;
body {
margin: 40px;
}
.wrapper {
display: grid;
grid-template-columns: 1fr 1fr;
grid-gap: 10px;
background-color: #fff;
color: #444;
grid-auto-flow: dense;
align-items: end;
}
.box {
background-color: #444;
color: #fff;
border-radius: 5px;
padding: 20px;
font-size: 150%;
}
.d,.e {
grid-column: 1;
}
.c {
height: 200px;
}
.f {
grid-column: 2;
}
<div class="wrapper">
<div class="box a">A</div>
<div class="box b">B</div>
<div class="box c">C</div>
<div class="box d">D</div>
<div class="box e">E</div>
<div class="box f">F</div>
</div>
,
它是硬编码的,但是您可以使用grid-row-start
和grid-row-end
来确定元素应该从哪一行开始/结束。
因此,如果将其添加到.f
元素,则它应从第二行扩展到第五行。
.f {
grid-column: 2;
grid-row-start: 2;
grid-row-end: 5;
}
,
您可以使用grid-row设置元素的行。在这种情况下, .f 元素就像 grid-row:2/5