我有一个 div 包含周围间隔的影像。问题是我添加到该 div 的影像越多,位于第一个位置的影像就会超出主容器 div 的范围。我添加了table-responsive
该类以使主容器可滚动,但是第一个位置的影像超出了范围,因此我什至无法滚动并查看第一个位置的影像。如何修复它以使影像不会超出父容器的范围?要查看第一个影像不同,请洗掉该容器中的一些影像,您会看到该影像确实存在。任何帮助表示赞赏。提前致谢。
.infoBar {
display: flex;
flex-direction: row;
justify-content: space-around;
position: absolute;
top: 15%;
width: auto;
height: 10%;
max-width: 95%;
column-gap: 25px;
background-color: green;
}
.infoBar::-webkit-scrollbar {
display: none !important;
}
.infoBar .imgWrap {
display: flex;
justify-content: center;
align-items: center;
height: 100%;
width: 20%;
cursor: pointer;
}
.infoBar .imgWrap img {
height: 100%;
cursor: pointer;
}
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css" integrity="sha384-1BmE4kWBq78iYhFldvKuhfTAU6auU8tT94WrHftjDbrCEXSU1oBoqyl2QvZ6jIW3" crossorigin="anonymous">
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/js/bootstrap.min.js" integrity="sha384-QJHtvGhmr9XOIpI6YVutG 2QOK9T ZnN4kzFN1RtK3zEFEIsxhlmWl5/YESvpZ13" crossorigin="anonymous"></script>
<!-- the more .imgWrap div I add to .infoBar the images at the first position goes out of scope of .info bar and can even scroll back to it-->
<div class="table-responsive infoBar" id="infoBar">
<div class="imgWrap"><img src="https://source.unsplash.com/user/c_v_r/1900x800"></div>
<div class="imgWrap"><img src="https://picsum.photos/200/300"></div>
<div class="imgWrap"><img src="https://picsum.photos/200/300"></div>
<div class="imgWrap"><img src="https://picsum.photos/200/300"></div>
<div class="imgWrap"><img src="https://picsum.photos/200/300"></div>
<div class="imgWrap"><img src="https://picsum.photos/200/300"></div>
<div class="imgWrap"><img src="https://picsum.photos/200/300"></div>
<div class="imgWrap"><img src="https://picsum.photos/200/300"></div>
<div class="imgWrap"><img src="https://picsum.photos/200/300"></div>
<div class="imgWrap"><img src="https://picsum.photos/200/300"></div>
<div class="imgWrap"><img src="https://picsum.photos/200/300"></div>
<div class="imgWrap"><img src="https://picsum.photos/200/300"></div>
<div class="imgWrap"><img src="https://picsum.photos/200/300"></div>
<div class="imgWrap"><img src="https://picsum.photos/200/300"></div>
<div class="imgWrap"><img src="https://picsum.photos/200/300"></div>
<div class="imgWrap"><img src="https://picsum.photos/200/300"></div>
</div>
uj5u.com热心网友回复:
Bootstrap 弄乱了你的 CSS,我建议你在使用它之前仔细阅读关于每个类的档案以及他们做了什么。
只有使用 css,您才能实作您想要做的事情(如果我理解正确的话):
- 尽可能多的影像
- 容器中给定大小的所有影像
- 水平滚动
- 每个影像之间的空间
.infoBar {
display: flex;
flex-direction: row;
max-width: 95%;
height: 160px;
margin: auto;
column-gap: 25px;
background-color: green;
overflow-x: auto;
}
.infoBar .imgWrap {
height: 100%;
cursor: pointer;
}
.infoBar .imgWrap img {
height: 100%;
cursor: pointer;
}
<!-- the more .imgWrap div I add to .infoBar the images at the first position goes out of scope of .info bar and can even scroll back to it-->
<div class="infoBar" id="infoBar">
<div class="imgWrap">
<img src="https://source.unsplash.com/user/c_v_r/1900x800">
</div>
<div class="imgWrap"><img src="https://picsum.photos/200/300"></div>
<div class="imgWrap"><img src="https://picsum.photos/200/300"></div>
<div class="imgWrap"><img src="https://picsum.photos/200/300"></div>
<div class="imgWrap"><img src="https://picsum.photos/200/300"></div>
<div class="imgWrap"><img src="https://picsum.photos/200/300"></div>
<div class="imgWrap"><img src="https://picsum.photos/200/300"></div>
<div class="imgWrap"><img src="https://picsum.photos/200/300"></div>
<div class="imgWrap"><img src="https://picsum.photos/200/300"></div>
<div class="imgWrap"><img src="https://picsum.photos/200/300"></div>
<div class="imgWrap"><img src="https://picsum.photos/200/300"></div>
<div class="imgWrap"><img src="https://picsum.photos/200/300"></div>
<div class="imgWrap"><img src="https://picsum.photos/200/300"></div>
<div class="imgWrap"><img src="https://picsum.photos/200/300"></div>
<div class="imgWrap"><img src="https://picsum.photos/200/300"></div>
<div class="imgWrap"><img src="https://picsum.photos/200/300"></div>
</div>
0 评论