html - 图片覆盖全屏,底部留白

标签 html css background-image

我希望我的图像完全覆盖背景。此外,如果除了背景之外任何方向都没有内容,我不想要滚动条。

以下是我能得到的最好的,除了我在底部有大约 1 英寸的空白并且水平滚动到大约 95%。

SCSS

body, html {
  padding: 0 !important;
  margin: 0 !important;
}

.workspace {
  background: url("../../../assets/Images/WhatIsHunter.jpg") no-repeat center center fixed;
  background-size: cover;
  height: 100%;
}

最佳答案

在 CSS 中,height 属性的百分比单位是相对于父元素的高度的。因此,根据 .workspace 在 DOM 中的位置,100% 可能有不同的含义。

要覆盖整个视口(viewport),请使用 vh 单位。

.workspace {
  height: 100vh;
}

来自 MDN article on units (强调我的):

vw, vh: Respectively these are 1/100th of the width of the viewport, and 1/100th of the height of the viewport.

因此,其中一百个将构成视口(viewport)的整个高度,这就是您所需要的。

关于html - 图片覆盖全屏,底部留白,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45906785/

相关文章:

html - tabindex ="xxxx"何时中断?

jQuery div 下拉点击事件

html - 透明div,后面有大图效果

html - 不调整大小的全尺寸背景

php - JEA 设施布局添加自定义 css 样式

html - Twitter BootStrap 背景图片

css - 向 dd 元素添加元素符号样式

jquery - 模态窗口隐藏在标题后面?

reactjs - 根据React中的路由更改背景图片

css - 如何反转博客上重复的图像