【问题标题】:Background image not sizing correctly?背景图片尺寸不正确?
【发布时间】:2022-01-08 04:38:59
【问题描述】:

所以在我的手机上,这个网站是这样的:

但是,在我的具有类似大小视口的 PC 上,它看起来像这样:

注意背景图像的差异。

我真的不明白为什么会发生这种情况或如何解决它,但我能做的就是在这里询问并提供背景图像的 CSS。

CSS:

.fw-bg--1 {
  width: auto !important;
  height: 100vh !important;
  background-repeat: no-repeat !important;
  background-size: cover !important;
  background-attachment: fixed !important;
  background-image: linear-gradient(180deg,rgba(0,0,0,.8),rgba(0,0,0,.8) 40%,rgba(0,0,0,.8)),url(https://media.discordapp.net/attachments/898930011359297629/925860960038694922/terrie-shum-edotown2.png);
}

如果您需要更多信息来帮助我,请告诉我,请告诉我! ????

【问题讨论】:

  • 哪一个是想要的结果?
  • 另外,在!importants 之前添加空格以确保正确解析样式。
  • @EliranMalka 我希望它看起来像在我的桌面上的样子。 (缩小)
  • 我明白了,请提供更多上下文;手机的型号是什么?它有什么屏幕尺寸?操作系统?等等等等。
  • 您能否提供所有相关元素(HTML 和 CSS)的代码?仅通过背景样式很难判断。

标签: html css image


【解决方案1】:

默认情况下,背景图像放置在元素的左上角,并在垂直和水平方向重复,尝试定义背景位置中心来解决此问题,您的代码将是这样的:

.fw-bg--1 {
  width: auto!important;
  height: 100vh !important;
  background-repeat: no-repeat!important;
  background-size: cover!important;
  background-position:center
  background-attachment: fixed!important;
  background-image: linear-gradient(180deg,rgba(0,0,0,.8),rgba(0,0,0,.8) 40%,rgba(0,0,0,.8)),url(https://media.discordapp.net/attachments/898930011359297629/925860960038694922/terrie-shum-edotown2.png);
}

【讨论】:

  • 它只是真的放大了。我将如何解决这个问题?这可能是由于高度为100vh对吧?有没有另一种方法可以使标题图像占用相似的空间量
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2012-12-16
  • 2012-12-13
  • 2023-04-11
  • 1970-01-01
  • 2021-07-09
  • 2015-05-22
  • 2011-09-27
相关资源
最近更新 更多