【发布时间】:2013-05-12 20:54:35
【问题描述】:
我已经搜索了几个小时,现在我想是时候问这个问题了。我无法让放置在标题中的背景图像适合屏幕。它适用于各种计算机分辨率,但我遇到麻烦的是当我在手机上查看时,它不想缩小。我已经完成了最小高度,最大高度,我已经尝试了所有方法,我认为部分问题是标题 div 本身比这张图片小,但我也不太了解,需要一些指导,我m 在 CSS 场景中相对较新。
这是我所拥有的:
#header {
background-image: url('http://hamsoc.polymath.io/wp-content/uploads/2013/05/hamsocheader.png');
background-repeat: no-repeat;
background-position: center center;
-webkit-background-size: cover;
-moz-background-size: cover;
-o-background-size: cover;
background-size: cover;
height: 209px;
}
提前感谢您的帮助!
Duncan Beattie 给了我答案,它就像一个魅力。他是这样说的:
"你有 background-size: 适合高度的封面 背景图像到 div 的固定高度,209px。除掉 固定高度并替换为 padding-bottom:15% 这将保持 div 的纵横比相同,并在视口中缩放图像 更小。”
【问题讨论】:
标签: css image background width resolution