我試圖通過網格模板區域來實現元素排列,但它不起作用。我試圖用一個網格系統來垂直和水平地排列街區。在左邊使用圖片,在另一邊使用文字。為什么這段代碼不起作用?
.news__wrapper {
display: grid;
grid-template-areas: "a a c" "b b c";
}
.news__item {
display: flex;
align-items: center;
justify-content: center;
}
.news__item-image {
width: 349px;
height: 360px;
}
.news__item-image {
background: "url(https://place-hold.it/300x500) 50% 50% no-repeat";
}
<div class="news__wrapper">
<div class="news__item">
<div class="news__item-image"></div>
<div class="news__item-content">
<h4 class="news__item-title">
Lorem,
</h4>
<p class="news__item-text">
Lorem ipsum
</p>
</div>
</div>
<div class="news__item">
<div class="news__item-image" :style="imageNews1"></div>
<div class="news__item-content">
<h4 class="news__item-title">
Lorem,
</h4>
<p class="news__item-text">
Lorem
</p>
</div>
</div>
<div class="news__item">
<div class="news__item-image" :style="imageNews1"></div>
<div class="news__item-content">
<h4 class="news__item-title">
Lorem,
</h4>
<p class="news__item-text">
Lorem ips
</p>
</div>
</div>
</div>
當您使用網格模板區域時,您需要將網格區域值分配給網格內的元素。 簡而言之,添加以下css代碼將達到預期的結果:
.news__item:first-child {
grid-area: a;
}
.news__item:nth-child(2) {
grid-area: b;
}
.news__item:nth-child(3) {
grid-area: c;
}
上一篇delta json
下一篇shiro vue2