【问题标题】:small gap between divsdiv之间的小间隙
【发布时间】:2021-01-25 11:31:52
【问题描述】:

我已尝试将字体大小设置为 0,没有边距或仅填充内容框,但 div 之间仍有小间隙,知道为什么会这样吗?是否有任何解决方案来解决这个问题,因为我希望它没有间隙,因为没有边距填充

我用来包含 iframe 的 .video 内部也存在间隙,我将 iframe 设置为 100% 高度,因此它占据了 .video 容器的全部高度,但问题是当我查看 .video 的元素框时。视频高度为 158 像素,当我查看 iframe 时,它​​是 154 像素,为什么会这样?

 .video-section-wrapper {
        width: 100%;
        height: 300px;
        background-color: whitesmoke;
        position: absolute;
        top: 180px;
        border-radius: 4px;
        border-top: orange 5px solid;
        border-bottom: orange 5px solid;
        box-sizing: border-box;
        display: flex;
        justify-content: space-around;
        align-items: center;
    }

    .video-section-box {
        height: 90%;
        width: 27%;
        border: solid black 5px;
        box-sizing: border-box;
        box-shadow: 1px 1px 2px 2px rgba(0,0,0,0.5),-1px -1px 2px 2px rgba(0,0,0,0.5);
        transition: ease-in-out 0.5s;
        overflow: hidden;
    }

    .video-section-box:hover {
        height: 93%;
        width: 30%;
    }

    .video-section-box > .video {
        width: 100%;
    }

    .video-section-box > .video > iframe {
        width: inherit;
        box-sizing: content-box;
        border: none;
        height: 100%;
    }

    .video-section-box > .subtitle-wrapper {
        border-top: rgba(0,0,0,0.5) solid 5px;
        height: 92px;
        width: 100%;
        position: relative;
    }

    .video-section-box > .subtitle-wrapper > .subtitle-header {
        padding-left: 5px;
        background-color: white;
        box-sizing: border-box;
        padding-bottom: 0px;
        margin-bottom: 0px;
        border-bottom: 0px;
    }

    .video-section-box > .subtitle-wrapper > .subtitle-header > h {
        background-color: black;
        color: wheat;
        font-weight: bold;
        background-size: 300px 300px;
        border-top-left-radius: 4px;
        border-top-right-radius: 4px;
        padding-left: 30px;
        padding-right: 30px;
    }

    .video-section-box > .subtitle-wrapper > .subtitle-content {
        background-color: black;
        margin: 0px;
        outline: 0px;
        height: 84px;
        color: wheat;
        display: flex;
        align-items: center;
        justify-content: center;
        box-sizing: border-box;
    }

    .capo-wrap {
        font-size: 17px;
        position: absolute;
        color: wheat;
        display: flex;
        align-items: flex-end;
        height: 78px;
    }

    .capo-wrap > p{
        margin: 0px;
    }

    .video-section-box > .subtitle-wrapper > .subtitle-content > .p {
        margin: 0px;
        padding-top: 0px;
        justify-content: center;
        align-items: center;
        text-align: center;
        font-weight: bolder;
        font-size: 30px;
    }
    <div class="video-section-box">
      <div class="video">
          <iframe>

          </iframe>
      </div>

      <div class="subtitle-wrapper">
          <div class="subtitle-header">
              <h>TUNING</h>                    
          </div>

          <div class="capo-wrap"><p>Capo Fret :</p></div>

          <div class="subtitle-content">
              <div class="p">E A D G B E</div>
          </div>                    
      </div>
   </div>

【问题讨论】:

  • &lt;h&gt; 应该是什么?
  • 将文本存储为标题
  • 可能是因为 h 是内联显示,将其更改为显示内联块或应该可以工作
  • 是的,它确实有效 iframe 呢?我用来包含 iframe 的 .video,我将 iframe 设置为 100% 高度,因此它占据了 .video 容器的全部高度,但问题是当我查看 .video 的元素框时,高度为 158px,当我看看 iframe 是 154px 为什么会这样?

标签: html css


【解决方案1】:

display: inline-block 添加到.video-section-box &gt; .subtitle-wrapper &gt; .subtitle-header &gt; h 选择器。像这样:

.video-section-box > .subtitle-wrapper > .subtitle-header > h {
    ...
    display: inline-block;
}

【讨论】:

    【解决方案2】:

    .video-section-box > .subtitle-wrapper > .subtitle 中的 ma​​rgin-bottom: 0px; 更改为 ma​​rgin-bottom: -1px; -标题{

    .video-section-wrapper {
            width: 100%;
            height: 300px;
            background-color: whitesmoke;
            position: absolute;
            top: 180px;
            border-radius: 4px;
            border-top: orange 5px solid;
            border-bottom: orange 5px solid;
            box-sizing: border-box;
            display: flex;
            justify-content: space-around;
            align-items: center;
        }
    
        .video-section-box {
            height: 90%;
            width: 27%;
            border: solid black 5px;
            box-sizing: border-box;
            box-shadow: 1px 1px 2px 2px rgba(0,0,0,0.5),-1px -1px 2px 2px rgba(0,0,0,0.5);
            transition: ease-in-out 0.5s;
            overflow: hidden;
        }
    
        .video-section-box:hover {
            height: 93%;
            width: 30%;
        }
    
        .video-section-box > .video {
            width: 100%;
        }
    
        .video-section-box > .video > iframe {
            width: inherit;
            box-sizing: content-box;
            border: none;
            height: 100%;
        }
    
        .video-section-box > .subtitle-wrapper {
            border-top: rgba(0,0,0,0.5) solid 5px;
            height: 92px;
            width: 100%;
            position: relative;
        }
    
        .video-section-box > .subtitle-wrapper > .subtitle-header {
            padding-left: 5px;
            background-color: white;
            box-sizing: border-box;
            padding-bottom: 0px;
            margin-bottom: -1px;
            border-bottom: 0px;
        }
    
        .video-section-box > .subtitle-wrapper > .subtitle-header > h {
            background-color: black;
            color: wheat;
            font-weight: bold;
            background-size: 300px 300px;
            border-top-left-radius: 4px;
            border-top-right-radius: 4px;
            padding-left: 30px;
            padding-right: 30px;
        }
    
        .video-section-box > .subtitle-wrapper > .subtitle-content {
            background-color: black;
            margin: 0px;
            outline: 0px;
            height: 84px;
            color: wheat;
            display: flex;
            align-items: center;
            justify-content: center;
            box-sizing: border-box;
        }
    
        .capo-wrap {
            font-size: 17px;
            position: absolute;
            color: wheat;
            display: flex;
            align-items: flex-end;
            height: 78px;
        }
    
        .capo-wrap > p{
            margin: 0px;
        }
    
        .video-section-box > .subtitle-wrapper > .subtitle-content > .p {
            margin: 0px;
            padding-top: 0px;
            justify-content: center;
            align-items: center;
            text-align: center;
            font-weight: bolder;
            font-size: 30px;
            display: inline-block;
        }
     <div class="video-section-box">
          <div class="video">
              <iframe>
    
              </iframe>
          </div>
    
          <div class="subtitle-wrapper">
              <div class="subtitle-header">
                  <h>TUNING</h>                    
              </div>
    
              <div class="capo-wrap"><p>Capo Fret :</p></div>
    
              <div class="subtitle-content">
                  <div class="p">E A D G B E</div>
              </div>                    
          </div>
       </div>

    【讨论】: