Bootstrap 5填充抛出图像组的纵横比

2022-08-26 00:00:00 html css bootstrap-5 responsiveness

我很难与1行跨/2行2列布局(请查看图片)中的3个图像争辩。我可以让它在一个分辨率下看起来完美,但在其他断点查看它时,由于静态填充大小,比率变得完全错误。

编码:

<section>
    <div class="container">
      <div class="row justify-content-center">
        <div class="col-5 text-center">
          <img class="img-fluid ratio ratio-1x1" src="/assets/mood1-8dc4fbf7f86401c523a66983158d7366ce7b41c40b9b568c9a79f2455ae983f4.png">
        </div>
        <div class="col-md-5 d-flex flex-column">
          <img class="img-fluid d-none d-md-block mb-2 ratio ratio-16x9" src="/assets/mood2-6b77bce1c8930fd5638d4d982b0c01b357dc38d6212588db2ef12ef67dc8f0e4.png">
          <img class="img-fluid d-none d-md-block mt-2 ratio ratio-16x9" src="/assets/mood3-1baca87fe953122237237cbe216e5574d0b6b8b0af20b14057c93281f10d426b.png">
        </div>
      </div>    
    </div>
  </section>

XXL:

请注意两列中图像的底部和顶部是如何完美对齐的。

中:

请注意,底部不再对齐。填充物没有反应,抛出了比率。有什么更好地解决这个问题的办法吗?


解决方案

h-100添加到您的映像可能会有所帮助。

您还可以使用bootstrap gutters此处gx-3根据需要设置您的边沟间距

结果。

展开代码段以查看结果

数据-lang="js"数据-隐藏="假"数据-控制台="真"数据-巴贝尔="假">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css" integrity="sha384-1BmE4kWBq78iYhFldvKuhfTAU6auU8tT94WrHftjDbrCEXSU1oBoqyl2QvZ6jIW3" crossorigin="anonymous">
<section>
    <div class="container">
      <div class="row justify-content-center gx-3">
        <div class="col-5 text-center">
          <img class="img-fluid ratio ratio-1x1 h-100" src="https://images.unsplash.com/photo-1554080353-a576cf803bda?ixid=MnwxMjA3fDB8MHxzZWFyY2h8M3x8cGhvdG98ZW58MHx8MHx8&ixlib=rb-1.2.1&w=1000&q=80">
        </div>
        <div class="col-md-5 d-flex flex-column">
          <img class="img-fluid d-none d-md-block mb-2 ratio ratio-16x9 h-100" src="https://apprendre-la-photo.fr/wp-content/uploads/2018/07/photo-vitesse-obturation-elevee_laurent-breillat-1200x900.jpg">
          <img class="img-fluid d-none d-md-block mt-2 ratio ratio-16x9 h-100" src="https://www.designer.io/wp-content/uploads/2019/10/1-1024x698.png">
        </div>
      </div>    
    </div>
  </section>
  <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>

相关文章