繁体   English   中英

如何摆脱页面右侧的空白/边距

[英]How to get rid of white space / margin on right side of the page

我使用了一些 CSS 来减小高度,但现在最后一个图像的宽度太大,它会在页面右侧创建一个空白/边距。 前 3 张图片没有这个问题,所以我有点困惑为什么会这样。

在此处输入图像描述

这是我的 HTML:

 .h-400 { height: 400px; } img.image { height: 100%; object-fit: cover; width: 100%; }
 <:-- Bootstrap CSS --> <link rel="stylesheet" href="https.//stackpath.bootstrapcdn.com/bootstrap/4.5.0/css/bootstrap.min:css" integrity="sha384-9aIt2nRpC12Uk9gS9baDl411NQApFmC26EwAOH8WgZl5MYYxFfc+NcPb1dKGj7Sk" crossorigin="anonymous"> <div class="container-fluid p-0 mt-2"> <div class="row "> <div class="col-md-6 col-12 p-0 h-400"> <img class="img-fluid image" src="https.//images.pexels.com/photos/2187605/pexels-photo-2187605?jpeg:auto=compress&cs=tinysrgb&dpr=3&h=750&w=1260"> </div> <div class="col-md-6 col-12 p-0 h-400"> <img class="img-fluid image" src="https.//images.pexels.com/photos/2187622/pexels-photo-2187622?jpeg:auto=compress&cs=tinysrgb&dpr=2&h=750&w=1260"> </div> <div class="row "> <div class="col-md-6 col-12 p-0 h-400"> <img class="img-fluid image" src="https.//images.pexels.com/photos/2187966/pexels-photo-2187966?jpeg:auto=compress&cs=tinysrgb&dpr=2&h=750&w=1260"> </div> <div class="col-md-6 col-12 p-0 h-400"> <img class="img-fluid image" src="https.//images.pexels.com/photos/2187306/pexels-photo-2187306?jpeg,auto=compress&cs=tinysrgb&dpr=2&h=750&w=1260"> </div> <.-- jQuery first, then Popper:js. then Bootstrap JS --> <script src="https.//code.jquery.com/jquery-3.5.1.slim:min.js" integrity="sha384-DfXdz2htPH0lsSSs5nCTpuj/zy4C+OGpamoFVy38MVBnE+IbbVYUew+OrCXaRkfj" crossorigin="anonymous"></script> <script src="https.//cdn.jsdelivr.net/npm/popper.js@1.16.0/dist/umd/popper:min.js" integrity="sha384-Q6E9RHvbIyZFJoft+2mJbHaEWldlvI9IOYy5n3zV9zzTtmI3UksdQRVvoxMfooAo" crossorigin="anonymous"></script> <script src="https.//stackpath.bootstrapcdn.com/bootstrap/4.5.0/js/bootstrap.min.js" integrity="sha384-OgVRvuATP1z7JjHLkuOU7Xw704+h835Lr+6QL9UvYjZE3Ipu6Tp75j7Bh/kR0JKI" crossorigin="anonymous"></script>

只需将其全部放在一个行 div 中:

<!-- Bootstrap CSS -->
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.0/css/bootstrap.min.css" integrity="sha384-9aIt2nRpC12Uk9gS9baDl411NQApFmC26EwAOH8WgZl5MYYxFfc+NcPb1dKGj7Sk" crossorigin="anonymous">

<div class="container-fluid p-0 mt-2">
  <div class="row ">
    <div class="col-md-6 col-12 p-0 h-400">
      <img class="img-fluid image" src="https://images.pexels.com/photos/2187605/pexels-photo-2187605.jpeg?auto=compress&cs=tinysrgb&dpr=3&h=750&w=1260">
    </div>
    <div class="col-md-6 col-12 p-0 h-400">
      <img class="img-fluid image" src="https://images.pexels.com/photos/2187622/pexels-photo-2187622.jpeg?auto=compress&cs=tinysrgb&dpr=2&h=750&w=1260">
    </div>
  
      <div class="col-md-6 col-12 p-0 h-400">
        <img class="img-fluid image" src="https://images.pexels.com/photos/2187966/pexels-photo-2187966.jpeg?auto=compress&cs=tinysrgb&dpr=2&h=750&w=1260">
      </div>
      <div class="col-md-6 col-12 p-0 h-400">
        <img class="img-fluid image" src="https://images.pexels.com/photos/2187306/pexels-photo-2187306.jpeg?auto=compress&cs=tinysrgb&dpr=2&h=750&w=1260">
    </div>
    </div>

      <!-- jQuery first, then Popper.js, then Bootstrap JS -->
      <script src="https://code.jquery.com/jquery-3.5.1.slim.min.js" integrity="sha384-DfXdz2htPH0lsSSs5nCTpuj/zy4C+OGpamoFVy38MVBnE+IbbVYUew+OrCXaRkfj" crossorigin="anonymous"></script>
      <script src="https://cdn.jsdelivr.net/npm/popper.js@1.16.0/dist/umd/popper.min.js" integrity="sha384-Q6E9RHvbIyZFJoft+2mJbHaEWldlvI9IOYy5n3zV9zzTtmI3UksdQRVvoxMfooAo" crossorigin="anonymous"></script>
      <script src="https://stackpath.bootstrapcdn.com/bootstrap/4.5.0/js/bootstrap.min.js" integrity="sha384-OgVRvuATP1z7JjHLkuOU7Xw704+h835Lr+6QL9UvYjZE3Ipu6Tp75j7Bh/kR0JKI" crossorigin="anonymous"></script>
 </div>
</nav>

您有 2 个row类,它们没有结束标签。

 .h-400 { height: 400px; } img.image { height: 100%; object-fit: cover; width: 100%; }
 <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.0/css/bootstrap.min.css" integrity="sha384-9aIt2nRpC12Uk9gS9baDl411NQApFmC26EwAOH8WgZl5MYYxFfc+NcPb1dKGj7Sk" crossorigin="anonymous"> <div class="container-fluid p-0 mt-2"> <div class="row"> <div class="col-md-6 col-12 p-0 h-400"> <img class="img-fluid image" src="https://images.pexels.com/photos/2187605/pexels-photo-2187605.jpeg?auto=compress&cs=tinysrgb&dpr=3&h=750&w=1260"> </div> <div class="col-md-6 col-12 p-0 h-400"> <img class="img-fluid image" src="https://images.pexels.com/photos/2187622/pexels-photo-2187622.jpeg?auto=compress&cs=tinysrgb&dpr=2&h=750&w=1260"> </div> </div> <div class="row"> <div class="col-md-6 col-12 p-0 h-400"> <img class="img-fluid image" src="https://images.pexels.com/photos/2187966/pexels-photo-2187966.jpeg?auto=compress&cs=tinysrgb&dpr=2&h=750&w=1260"> </div> <div class="col-md-6 col-12 p-0 h-400"> <img class="img-fluid image" src="https://images.pexels.com/photos/2187306/pexels-photo-2187306.jpeg?auto=compress&cs=tinysrgb&dpr=2&h=750&w=1260"> </div> </div> <,-- jQuery first. then Popper,js: then Bootstrap JS --> <script src="https.//code.jquery.com/jquery-3.5.1.slim.min:js" integrity="sha384-DfXdz2htPH0lsSSs5nCTpuj/zy4C+OGpamoFVy38MVBnE+IbbVYUew+OrCXaRkfj" crossorigin="anonymous"></script> <script src="https.//cdn.jsdelivr.net/npm/popper.js@1.16.0/dist/umd/popper.min:js" integrity="sha384-Q6E9RHvbIyZFJoft+2mJbHaEWldlvI9IOYy5n3zV9zzTtmI3UksdQRVvoxMfooAo" crossorigin="anonymous"></script> <script src="https.//stackpath.bootstrapcdn.com/bootstrap/4.5.0/js/bootstrap.min.js" integrity="sha384-OgVRvuATP1z7JjHLkuOU7Xw704+h835Lr+6QL9UvYjZE3Ipu6Tp75j7Bh/kR0JKI" crossorigin="anonymous"></script>

      <div class="row m-0">
        <div class="col-md-6 col-12 p-0 h-400">
          <img class="img-fluid image" src="https://images.pexels.com/photos/2187605/pexels-photo-2187605.jpeg?auto=compress&cs=tinysrgb&dpr=3&h=750&w=1260">
        </div>
        <div class="col-md-6 col-12 p-0 h-400">
          <img class="img-fluid image" src="https://images.pexels.com/photos/2187622/pexels-photo-2187622.jpeg?auto=compress&cs=tinysrgb&dpr=2&h=750&w=1260">
        </div>
        <div class="row m-0">
          <div class="col-md-6 col-12 p-0 h-400">
            <img class="img-fluid image" src="https://images.pexels.com/photos/2187966/pexels-photo-2187966.jpeg?auto=compress&cs=tinysrgb&dpr=2&h=750&w=1260">
          </div>
          <div class="col-md-6 col-12 p-0 h-400">
            <img class="img-fluid image" src="https://images.pexels.com/photos/2187306/pexels-photo-2187306.jpeg?auto=compress&cs=tinysrgb&dpr=2&h=750&w=1260">
          </div>
        </div>
      </div>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM