html - 为什么我的 div 容器没有与它上面的部分完全对齐?两者之间有一条细线

标签 html css

enter image description here我正在尝试使用 Bootstrap 为此网页布局创建多个部分。我在页面标题的顶部做了一个部分,我有一个包含多张卡片的 div 容器。我不明白为什么容器和部分之间会出现这个细边框。谁能帮我解决这个问题?

我在下面粘贴了我遇到问题的代码,以防有帮助。谢谢!

实验室团队页面

<section>

<div class="container-fluid" style="background-color: lightgrey; border: none">
  <div class="row justify-content-center">

    <!--Mike's Card -->
     <div class="card m-4" style="width: 18rem;">
         <img src="..." class="card-img-top" alt="...">
         <div class="card-body">
           <h5 class="card-title">Mike</h5>
           <p class="card-text">Some quick example text to build on the card title and make up the bulk of the card's content.</p>
           <a href="../team/mike/" class="btn btn-primary">See Mike's Page</a>
         </div>
    </div>

    <!--Carl's Card -->
    <div class="card m-4" style="width: 18rem;">
        <img src="..." class="card-img-top" alt="...">
        <div class="card-body">
          <h5 class="card-title">Carl</h5>
          <p class="card-text">Some quick example text to build on the card title and make up the bulk of the card's content.</p>
          <a href="../team/carl/" class="btn btn-primary">See Carl's Page</a>
        </div>
    </div>

    <!--Aidan's Card -->
    <div class="card m-4" style="width: 18rem;">
        <img src="..." class="card-img-top" alt="...">
        <div class="card-body">
          <h5 class="card-title">Aidan</h5>
          <p class="card-text">Some quick example text to build on the card title and make up the bulk of the card's content.</p>
          <a href="../team/aidan/" class="btn btn-primary">See Aidan's Page</a>
        </div>
    </div>

  </div> <!--row closing tag -->


</div> <!-- card container closing tag -->

最佳答案

我发现此代码上方部分中的 h1 确实产生了间隙。这是来自 h1 元素上的 margin-bottom。

在 h1 上将 margin-bottom 设置为 0,并添加一些 padding-bottom 来处理落在该行下方的任何小写字母:

<section id="title">
<h1 style="background-color: blue; margin: 0; padding:.5rem;">Aidan's problem page</h1>
</section>

<section>

    <div class="container-fluid" style="background-color: lightgrey; border: none">
      <div class="row justify-content-center">

        <!--Mike's Card -->
         <div class="card m-4" style="width: 18rem;">
             <img src="..." class="card-img-top" alt="...">
             <div class="card-body">
               <h5 class="card-title">Mike</h5>
               <p class="card-text">Some quick example text to build on the card title and make up the bulk of the card's content.</p>
               <a href="../team/mike/" class="btn btn-primary">See Mike's Page</a>
             </div>
        </div>

        <!--Carl's Card -->
        <div class="card m-4" style="width: 18rem;">
            <img src="..." class="card-img-top" alt="...">
            <div class="card-body">
              <h5 class="card-title">Carl</h5>
              <p class="card-text">Some quick example text to build on the card title and make up the bulk of the card's content.</p>
              <a href="../team/carl/" class="btn btn-primary">See Carl's Page</a>
            </div>
        </div>

        <!--Aidan's Card -->
        <div class="card m-4" style="width: 18rem;">
            <img src="..." class="card-img-top" alt="...">
            <div class="card-body">
              <h5 class="card-title">Aidan</h5>
              <p class="card-text">Some quick example text to build on the card title and make up the bulk of the card's content.</p>
              <a href="../team/aidan/" class="btn btn-primary">See Aidan's Page</a>
            </div>
        </div>

      </div> <!--row closing tag -->


    </div> <!-- card container closing tag -->
</section>

关于html - 为什么我的 div 容器没有与它上面的部分完全对齐?两者之间有一条细线,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59336280/

相关文章:

javascript - 为什么 &lt;script&gt; src 中的路径以单斜杠开头会导致错误?

html - border-collapse 在 chrome 和 firefox 中的工作方式不同

html - 使用具有固定位置 div 的 Bootstrap 网格

javascript - 有没有办法在js插入后在浏览器中显示html源?

html - <span>/<div> 是 css 的简写 - 这是合法的吗?

html - 如何垂直居中/对齐 <pre> 标签旁边的文本

JQuery 更改 Sharepoint 列表中整行文本的颜色

css - 我如何从 react 大日历中覆盖特定的 css 样式

jquery - 我的左侧菜单不起作用

php - 不使用 php 的电子邮件表单提交