可以在没有滚动条的情况下获得模态工作
因此,我试图在没有滚动条的主页的情况下进行模态工作。模式内的是高度不同的照片。当适合视图高度内的照片在模态内部时,没有滚动条。当它是更高的图像时,滚动条出现。
我正在尝试使它做到,因此无论照片的大小如何,都不会出现滚动条。我已经删除了一些重复的代码,以简短。我添加了图片以进行澄清。
我已经尝试对不同属性设置视线,但似乎没有任何作用。
有人可以帮我帮助我...
<div class="container pt-5 pb-3 galleryContainer" id="gallery">
<div id="carouselGallery" class="carousel slide" data-bs-ride="carousel">
<div class="carousel-inner">
<div class="carousel-item active">
<a data-bs-toggle="modal" data-bs-target="#galleryModal" data-bs-slide-to="0">
<img src="img/gallery/01.jpg" class="d-block w-100 galleryImage" alt="...">
</a>
</div>
</div>
<button class="carousel-control-prev" type="button" data-bs-target="#carouselGallery" data-bs-slide="prev">
<span class="carousel-control-prev-icon" aria-hidden="true"></span>
<span class="visually-hidden">Previous</span>
</button>
<button class="carousel-control-next" type="button" data-bs-target="#carouselGallery" data-bs-slide="next">
<span class="carousel-control-next-icon" aria-hidden="true"></span>
<span class="visually-hidden">Next</span>
</button>
</div>
</div>
<!-- Modal -->
<div class="modal fade" id="galleryModal" tabindex="-1" aria-labelledby="gallery" aria-hidden="true">
<div class="modal-dialog modal-dialog-centered">
<div class="modal-content">
<div id="galleryCarousel" class="carousel slide" data-bs-ride="carousel" data-bs-interval="false">
<div class="carousel-inner overflow-hidden">
<div class="carousel-item active">
<img src="img/gallery/01.jpg" class="d-block w-100" alt="">
</div>
</div>
<button class="carousel-control-prev" type="button" data-bs-target="#galleryCarousel" data-bs-slide="prev">
<span class="carousel-control-prev-icon" aria-hidden="true"></span>
<span class="visually-hidden">Previous</span>
</button>
<button class="carousel-control-next" type="button" data-bs-target="#galleryCarousel" data-bs-slide="next">
<span class="carousel-control-next-icon" aria-hidden="true"></span>
<span class="visually-hidden">Next</span>
</button>
</div>
<div class="modal-footer"><button type="button" class="btn btn-primary" data-bs-dismiss="modal">Close</button></div>
</div>
</div>
</div>
body {
margin: 0;
padding: 0;
font-family: 'Open Sans', sans-serif;
}
.modal-dialog {
height: calc(99vh-80px);
}
.galleryImage {
object-fit: cover;
height: 500px;
}
So I'm trying to get a modal to work without the main page having scroll bars. Inside the modal are photos with different heights. When a photo that fits within the view height is inside the modal, there are no scroll bars. When it's a taller image, the scroll bars show up.
I'm trying to make it so no scroll bars show up regardless of the size of the photo. I've removed some repetitive code for brevity. I've added pictures for clarification.
I've tried setting a viewheight on different attributes but nothing seems to be working.
modal without scroll bars
modal with scroll bars on main window
Can someone please help me out...
<div class="container pt-5 pb-3 galleryContainer" id="gallery">
<div id="carouselGallery" class="carousel slide" data-bs-ride="carousel">
<div class="carousel-inner">
<div class="carousel-item active">
<a data-bs-toggle="modal" data-bs-target="#galleryModal" data-bs-slide-to="0">
<img src="img/gallery/01.jpg" class="d-block w-100 galleryImage" alt="...">
</a>
</div>
</div>
<button class="carousel-control-prev" type="button" data-bs-target="#carouselGallery" data-bs-slide="prev">
<span class="carousel-control-prev-icon" aria-hidden="true"></span>
<span class="visually-hidden">Previous</span>
</button>
<button class="carousel-control-next" type="button" data-bs-target="#carouselGallery" data-bs-slide="next">
<span class="carousel-control-next-icon" aria-hidden="true"></span>
<span class="visually-hidden">Next</span>
</button>
</div>
</div>
<!-- Modal -->
<div class="modal fade" id="galleryModal" tabindex="-1" aria-labelledby="gallery" aria-hidden="true">
<div class="modal-dialog modal-dialog-centered">
<div class="modal-content">
<div id="galleryCarousel" class="carousel slide" data-bs-ride="carousel" data-bs-interval="false">
<div class="carousel-inner overflow-hidden">
<div class="carousel-item active">
<img src="img/gallery/01.jpg" class="d-block w-100" alt="">
</div>
</div>
<button class="carousel-control-prev" type="button" data-bs-target="#galleryCarousel" data-bs-slide="prev">
<span class="carousel-control-prev-icon" aria-hidden="true"></span>
<span class="visually-hidden">Previous</span>
</button>
<button class="carousel-control-next" type="button" data-bs-target="#galleryCarousel" data-bs-slide="next">
<span class="carousel-control-next-icon" aria-hidden="true"></span>
<span class="visually-hidden">Next</span>
</button>
</div>
<div class="modal-footer"><button type="button" class="btn btn-primary" data-bs-dismiss="modal">Close</button></div>
</div>
</div>
</div>
body {
margin: 0;
padding: 0;
font-family: 'Open Sans', sans-serif;
}
.modal-dialog {
height: calc(99vh-80px);
}
.galleryImage {
object-fit: cover;
height: 500px;
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
感谢@danield和他的回答,我能够解决这个问题:
https://stackoverflow.com/users/703717/danield < /a>
如何限制模态的高度? 。
tl; dr并编辑为Bootstrap 5,
Thanks to @Danield and his answer below I was able to solve this problem:
https://stackoverflow.com/users/703717/danield
How to limit the height of the modal?.
TL;DR and edited for Bootstrap 5,