【问题标题】:How can get the div background image to scale to the page size?如何让 div 背景图像缩放到页面大小?
【发布时间】:2015-02-22 00:40:13
【问题描述】:

我正在尝试使 div 标题的背景图像缩放到页面大小。这是当前的 css:

.Header {
    background-image: url(Images/logo.png);
    height: 160px;
    width: 960px;
    margin-left: auto;
    margin-right: auto;
    margin-top: 20px;
}

【问题讨论】:

  • background-size: cover 也许?
  • 这篇CSS Tricks 文章展示了如何做到这一点。
  • 但请注意,这些东西并不总是适用于所有浏览器。
  • @JoshCrozier 当我添加这个时,背景图像根本不显示

标签: html css image scale


【解决方案1】:

将位置设为header的绝对位置,宽度设为100%

position:absolute;
width:100%;

【讨论】:

  • 抱歉似乎无法解决。图像重复,当我改变窗口大小时,图像不会改变大小
  • 意味着如果你调整窗口大小,它会变成多个图像?你能给我小提琴吗?我试试jsfiddle.net
猜你喜欢
  • 2013-06-21
  • 1970-01-01
  • 2015-10-27
  • 1970-01-01
  • 2023-04-03
  • 1970-01-01
  • 2016-04-30
  • 2016-06-20
相关资源
最近更新 更多