【发布时间】:2021-03-05 15:37:39
【问题描述】:
我对引导程序还很陌生。我有一个包含三列的 bootstrap 4 页面。中间一列有一个容器,我在一个网格中排列了 4 个图像。在大屏幕上,我希望这个容器尽可能大,同时仍然适合屏幕(并保留内部图像的纵横比。我可以通过手动设置列宽(例如 col -lg-5),但是根据屏幕的纵横比,图像容器要么没有填满整个高度,要么溢出超出视图。允许列自动宽度导致列占据 100% 宽度(图像很大)这不是我想要的。我可以使用max-height: 100vh; 将图像容器的高度设置为 100%,我认为这应该可以解决问题,但是该容器内的行不能缩放适合。而是垂直方向有溢出。
示例如下:
<div class="container-fluid">
<div class="row justify-content-center">
<div class="col-auto" style="background-color:red;">
<h2>Column 1</h2>
</div>
<!-- I want the content in this column to take up 100% height on large screens, but 100% width on small screens (columns stack) -->
<div class="col-auto" style="background-color:green;">
<h2>Column 2</h2>
<div id="img-container" class="container" style="max-height:100vh;">
<div class="row">
<div class="col p-0">
<img class="img-fluid" src="http://climate.met.psu.edu/ewall/test.png">
</div>
<div class="col p-0">
<img class="img-fluid" src="http://climate.met.psu.edu/ewall/test.png">
</div>
</div>
<div class="row">
<div class="col p-0">
<img class="img-fluid" src="http://climate.met.psu.edu/ewall/test.png">
</div>
<div class="col p-0">
<img class="img-fluid" src="http://climate.met.psu.edu/ewall/test.png">
</div>
</div>
</div>
</div>
<div class="col-auto" style="background-color:blue;">
<h2>Column 3</h2>
</div>
</div>
</div>
https://www.codeply.com/p/x1EiL25vhm
期望的结果: 我希望图像容器始终以自动宽度占据 100% 的高度,直到侧面使用所有可用空间。在小屏幕上,三列应垂直堆叠,第 2 列将占据 100% 的宽度。
【问题讨论】:
-
您能与我们分享您的代码吗?看看有什么问题会有所帮助:)
-
请不要使用外部网站来展示您的代码,因为它不能保证是静态的,并且并非所有读者都可以访问。相反,请edit 您的问题包含您在使用formatted text 时遇到问题的代码的minimal reproducible example
-
style="max-height:100%;" -
我对其进行了编辑以在此处包含代码。链接失效了吗?
-
max-height 100% 不起作用 - 在这种情况下没有溢出,但容器没有缩放到视图的高度
标签: html css bootstrap-4