【发布时间】:2022-08-15 16:22:28
【问题描述】:
我用 flexbox 创建了一个图片库,但它比电脑屏幕大。这使得 flexbox 滚动。问题是在我的页面中弹性框上方有一个导航栏,当弹性框向上滚动屏幕时它会重叠。所以我希望 flexbox 容器有一个特定的尺寸和在其中滚动的项目,而不是整个盒子在屏幕上滚动。请提出解决方案。
.gallery_container {
background-color: rgba(243, 239, 236, 0.7);
padding: 10px;
}
.gallery_header {
text-align: center;
font-family: calibri;
}
.photo_container {
display: flex;
background-color: rgba(0, 0, 0, 1);
flex-direction: row;
flex-wrap: wrap;
justify-content: center;
align-items: center;
}
.photo_container img {
object-fit: cover;
width: 45%;
height: 400px;
margin: 5px;
}
<div class=\"gallery_container\">
<h2 class=\"gallery_header\">Gallery</h2>
<div class=\"photo_container\">
<img src=\"photoA.jpg\">
<img src=\"photoB.jpg\">
<img src=\"photoC.jpg\">
<img src=\"photoD.jpg\">
</div>
</div>
-
添加最大高度或特定高度并声明溢出规则。