我正在尝试为杂志网站构建一个元素,其中第一个元素由宽度和高度不同的后期宣传框组成,如下图所示:
这是我的方法:
<div class="row collapse">
<div class="column medium-6"><!-- Left Pic 50% width --></div>
<div class="column medium-6">
<div class="row collapse">
<div class="column medium-12"><!-- Right Top Pic 50% width, 50% height --></div>
<div class="column medium-6"><!-- Right Bottom Left Pic 25% width, 50% height --></div>
<div class="column medium-6"><!-- Right Bottom Right Pic 25% width, 50% height --></div>
</div>
</div>
</div>
答案 0 :(得分:0)
基本思想是使用父容器上的grid-template
属性创建所需网格的模板,然后使用grid-area
属性将每个区域分配给子元素。
标记
<section class="grid">
<div class="item first">
<img src="https://placekitten.com/g/600/500" />
</div>
<div class="item second">
<img src="https://placekitten.com/g/300/150" />
</div>
<div class="item third">
<img src="https://placekitten.com/g/149/100" />
</div>
<div class="item fourth">
<img src="https://placekitten.com/g/149/100" />
</div>
</section>
CSS
.grid {
width: 600px;
height: 250px;
display: grid;
grid-column-gap: 3px;
grid-row-gap: 3px;
grid-template:
"first first second second" 1fr
"first first second second" 1fr
"first first second second" 1fr
"first first third fourth" 1fr
"first first third fourth" 1fr / 1fr 1fr 1fr 1fr;
}
.grid .first { grid-area: first; }
.grid .second { grid-area: second; }
.grid .third { grid-area: third; }
.grid .fourth { grid-area: fourth; }
您可以根据需要将图像添加为常规img
元素或背景。
结果