html - 我怎样才能摆脱 body 和 div 之间的这个空间?

标签 html css

所以我将文本居中。但是现在 bodydiv 之间有一个空白。这是 HTML:

.parent-aligner {
    background: #f2f2f2;
    width: 100vw;
    height: 500px;
    text-align: center; 
  }

  .parent-aligner .aligner {
    display: table-cell;
    height: inherit;
    width: inherit;
    vertical-align: middle;
  }
<div class="container-fluid">
  <div class="parallax">
    <div class="parent-aligner">
      <div class="aligner">
        <p class="textcontent">lorem ipsum text</p>
      </div>  
    </div>
  </div>
</div>

我认为是 width: 100vw; 造成的。但是当我将其更改为 width:100%; 时,文本不再居中。有关如何解决此问题的任何建议?

最佳答案

对于较小的屏幕尺寸,从视口(viewport)宽度中减去滚动条的宽度...

编辑:添加 max-width 属性。

(同时移除 body 上的 margin)

body {
  margin: 0;
}

.parent-aligner {
  background: #f2f2f2;
  width: 100vw;
  max-width: 100%;
  height: 500px;
  text-align: center;
}

.parent-aligner .aligner {
  display: table-cell;
  height: inherit;
  width: inherit;
  vertical-align: middle;
}
<div class="container-fluid">
  <div class="parallax">
    <div class="parent-aligner">
      <div class="aligner">
        <p class="textcontent">lorem ipsum text</p>
      </div>
    </div>
  </div>
</div>

关于html - 我怎样才能摆脱 body 和 div 之间的这个空间?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48260466/

相关文章:

css - 如何在不使用float的情况下让div填充剩余空间?

html - 容器中的三个灵活跨度,其中一个允许文本溢出

html - 带有整体边框的居中 div

javascript - 元素未使用 obj.style.display ='' 显示;

html - 如何在有文字的矩形内制作一个小正方形?

css - 如何在浏览器窗口中居中和调整大小/纵横比未知的 div/img

html - 当您将鼠标悬停在标题按钮上时,标题按钮会变大

html - CSS 在悬停时更改多个元素

html - Firefox 在其他浏览器中的字符串中断行为?

javascript - 在悬停元素中覆盖悬停样式