【发布时间】:2018-02-15 20:41:24
【问题描述】:
我有一个带有一堆区域和一个照片容器的 CSS 网格布局。
我不知道该怎么做:
控制照片的大小,使其包含在网格区域内
将照片的宽度保持在 100%(因此等于其容器)并缩放容器的高度以适合照片。基本上,当窗口变小时,照片的宽度会变小,高度也会变小 - 向上拉标签、相册和旋转元素。
.container {
display: grid;
grid-template-columns: repeat(5, 1fr);
grid-template-rows: 40vh 30vh 30vh;
grid-gap: 10px;
grid-template-areas:
"info photo photo photo photo"
"comment photo photo photo photo"
"comment tag tag album rotate"
}
.photo {
grid-area: photo;
background: yellow;
}
.photo>img {
object-fit: cover;
width: 100%
}
.info {
grid-area: info;
background: pink;
}
.tag {
grid-area: tag;
background: teal;
}
.comment {
grid-area: comment;
background: green;
}
.album {
grid-area: album;
background: red;
}
.rotate {
grid-area: rotate;
background: blue;
}
<div class="container">
<div class="photo">
<img src="http://wallpaper-gallery.net/images/image/image-13.jpg" />
</div>
<div class="info">info</div>
<div class="tag">tag</div>
<div class="comment">comment</div>
<div class="album">album</div>
<div class="rotate">rotate</div>
</div>
【问题讨论】:
-
我不认为你想要完成的事情可以用网格来完成。