【问题标题】:Background image all screen resolution ( my code cut photo)背景图像所有屏幕分辨率(我的代码剪切照片)
【发布时间】:2019-12-02 17:29:41
【问题描述】:

背景图我想调成所有分辨率,但是写的时候background-size:cover;整张照片看不到,切了一半,为什么?

*, html{
    margin:0;
    padding: 0;
    height: 100%;
    width: 100%;
    background-image: url('../img/image3.jpg');
    background-repeat: no-repeat;
    background-attachment: fixed;
    background-size: cover;
}

【问题讨论】:

  • 可能是因为您将背景图像放在每个元素上。把它放在body标签上以覆盖整个视口。
  • 覆盖保持纵横比
  • 所以不要把照片放在html里?放入div? @symlink
  • @koki 仅将其放在body 标签上。给htmlbody一个height: 100%
  • @symlink 删除边距、内边距和宽度?

标签: html css


【解决方案1】:

删除您拥有的整个样式规则。您可能希望您的 html 具有默认的边距、填充和宽度属性,但是当您在项目中进一步推进时,您可以处理这些。现在,将 html 和 body 的高度设为 100%。然后将背景图像附加到您的身体标签,因此它将始终占据视口的 100%。我也为你的 body 标签添加了颜色和边距,因为你的 html 会继承颜色,这里的边距是一种“重置”样式,以确保浏览器不会在 body 标签周围放置边距:

html,
body {
  height: 100%;
}

body {
  margin: 0;
  color: white;
  background-image: url(http://placekitten.com/500/500);
  background-repeat: no-repeat;
  background-attachment: fixed;
  background-size: cover;
  background-position: center;
}
This is text directly inside the body tag.
<p>This is html inside the body tag, it should have its own styling</p>

【讨论】:

  • 但是在这种情况下,猫的照片被切成了两半。
  • 我希望它不要被剪掉,整张照片都是
  • @koki 看到我的编辑。也许您正在寻找background-position: center
  • 在您的代码中,只有猫的脸是可见的。原件也是下面的一部分。我希望照片是完整的,而不是裁剪的
猜你喜欢
  • 2016-07-23
  • 2011-03-10
  • 2017-01-04
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多