【问题标题】:How to fix CSS gradient background leaving whitespace at the bottom on mobile browser如何修复CSS渐变背景在移动浏览器的底部留下空白
【发布时间】:2019-08-05 04:06:25
【问题描述】:

我想在移动设备上修复 CSS 渐变背景。

现在,在移动设备上,当用户放大页面并向下滚动时,他会看到 css 渐变结束,然后看到空白。缩小后空白区域仍然存在。看到这个image

放大/缩小或滚动似乎不会导致桌面出现问题

该页面目前在http://beta.qalamproject.com/上线

我尝试过在正文选择器中包含背景 css 而不是 html,但似乎无法找出导致问题的原因。

* {
  margin: 0;
  padding: 0;
  /* font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif; */
}

html {
  margin: 0;
  background-image: radial-gradient( circle farthest-corner at 10% 20%,  rgba(226,240,254,1) 0%, rgba(255,247,228,1) 90% );
  background-attachment: fixed;
  background-size: auto 100%;
    background-repeat: no-repeat;
  height: 100%;
}

body {
  font-family:'Open Sans', sans-serif;
  margin: 10em 1em 0em 1em;
  text-align: center;
}

我希望背景渐变填充整个页面,无论用户如何缩放、滚动等。相反,现在背景结束并且用户看到白色。

【问题讨论】:

  • 根据您上面的代码,不会有空格。我只能假设这是因为您有额外的 CSS 设置了溢出,或者将 height 推到超过 100%
  • 只有我拥有的其他 CSS 用于页面上的文本。该问题仅在移动设备上普遍存在。在台式机上还不错
  • 这种情况发生在所有移动设备上还是特定设备上?
  • 尝试使用 100vh 而不是 100%,检查是否有效
  • 使用高度 100vh 并删除边距。如果要包含文本,请创建一个容器并设置一个最大宽度

标签: html css gradient


【解决方案1】:

尝试将背景大小设置为cover

html {
    margin: 0;
    background-image: radial-gradient( circle farthest-corner at 10% 20%, rgba(226,240,254,1) 0%, rgba(255,247,228,1) 90% );
    background-attachment: fixed;
    background-size: cover;
    background-repeat: no-repeat;
    height: 100%;
}

【讨论】:

  • 感谢您的建议。但是,这并没有解决问题,用户在缩放和向下滚动时仍然会看到空白
  • 啊,真可惜。不幸的是,我在复制问题时遇到了麻烦:(
  • 你试过去掉“高度”吗?我通常不会为我的 html 定义高度。
猜你喜欢
  • 2015-12-08
  • 2011-10-10
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-11-26
  • 2015-09-03
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多