【问题标题】:Why are the boxes not aligned correctly?为什么盒子没有正确对齐?
【发布时间】:2019-09-24 01:49:10
【问题描述】:

由于某种原因,顶部的盒子在左侧留下了额外的空间,但我不知道为什么。非常感谢您的帮助。

HTML:

  <section class="proj-box">
       <div class="wrapper">
         <div class="thumb" id="Dthumb">
           <a href="Dough.html">
             <img src="Doughblack.png" alt="screen mockups of Dough app">
           </a>
         <h3 id="Dtitle">Dough - Your new financial companion</h3>
       </div>
       <div class="thumb" id="Fthumb">
         <a href="Flyte.html">
           <img src="flytebig.png" alt="screen mockups of Flyte app">
         </a>
         <h3 id="Ftitle">Flyte - Flight Search App</h3>
       </div>
       <div class="thumb" id="Othumb">
         <a href="OrderUp.html">
           <img src="OrderUpred.png" alt="screen mockups of OrderUp app">
         </a>
         <h3 id="Otitle">OrderUp - Food Delivery App</h3>
       </div>
     </div>
   </section>

CSS:The picture shows that the black box isn't aligned with the red box

.proj-box .thumb {
  width: 380px;
  height: 380px;
  float: left;
  margin: 20px 20px 0;
}
.proj-box img {
  width: 380px;
  border: 1px solid #ddd;
  border-radius: 4px;
}
.proj-box img:hover {
  box-shadow: 0 0 2px 1px #D89E9E;
}

【问题讨论】:

    标签: html css containers


    【解决方案1】:

    你错过了“div”标签

    <section class="proj-box">
       <div class="wrapper">
         <div class="thumb" id="Dthumb">
           <a href="Dough.html">
             <img src="Doughblack.png" alt="screen mockups of Dough app">
           </a>
           <h3 id="Dtitle">Dough - Your new financial companion</h3>
         </div>
         <div class="thumb" id="Fthumb">
           <a href="Flyte.html">
             <img src="flytebig.png" alt="screen mockups of Flyte app">
           </a>
           <h3 id="Ftitle">Flyte - Flight Search App</h3>
         </div>
         <div class="thumb" id="Othumb">
           <a href="OrderUp.html">
             <img src="OrderUpred.png" alt="screen mockups of OrderUp app">
           </a>
           <h3 id="Otitle">OrderUp - Food Delivery App</h3>
         </div>
       </div>
     </div>
    

    试试这个。

    【讨论】:

      【解决方案2】:

      由于浮动元素的宽度超过了总可用宽度,最后一个元素被推到下一行。尝试使用flex 或grid。请使用grid找到sn-p

      .proj-box .wrapper {
        display: grid;
        grid-template-columns: repeat(3, 1fr);
        grid-gap: 1em;
      }
      
      .proj-box .thumb {}
      
      .proj-box img {
        width: 380px;
        border: 1px solid #ddd;
        border-radius: 4px;
      }
      
      .proj-box img:hover {
        box-shadow: 0 0 2px 1px #D89E9E;
      }
      <section class="proj-box">
        <div class="wrapper">
          <div class="thumb" id="Dthumb">
            <a href="Dough.html">
              <img src="Doughblack.png" alt="screen mockups of Dough app">
            </a>
            <h3 id="Dtitle">Dough - Your new financial companion</h3>
          </div>
          <div class="thumb" id="Fthumb">
            <a href="Flyte.html">
              <img src="flytebig.png" alt="screen mockups of Flyte app">
            </a>
            <h3 id="Ftitle">Flyte - Flight Search App</h3>
          </div>
          <div class="thumb" id="Othumb">
            <a href="OrderUp.html">
              <img src="OrderUpred.png" alt="screen mockups of OrderUp app">
            </a>
            <h3 id="Otitle">OrderUp - Food Delivery App</h3>
          </div>
        </div>
      </section>

      【讨论】:

      • 谢谢,看起来好多了,但是,这样做会将我的导航栏推到中心,我该如何解决?
      • 也许我没有使用.proj-box .wrapper 来获取该特定元素。我已经编辑了,你现在可以试试吗?
      猜你喜欢
      • 2018-05-24
      • 2021-10-18
      • 2016-05-30
      • 2021-09-16
      • 1970-01-01
      • 2023-03-25
      • 2022-01-18
      • 2012-01-27
      • 2023-02-17
      相关资源
      最近更新 更多