【发布时间】:2011-09-22 10:55:43
【问题描述】:
我的网页有一个始终位于窗口顶部的标题图像。当窗口最大化时,标题图像居中,但在小窗口(或智能手机浏览器)中查看时,标题设置在窗口的左侧,右侧被裁剪。因为 header div 比页面内容宽,所以当窗口小于 header 时出现水平滚动条,而不是页面。
我希望页眉图像始终居中,如果窗口小于页眉,则左右两边都被裁剪。此外,只有在窗口宽度小于页面宽度时才会打开水平滚动条。
这张图片可能会更清楚地解释它:
http://postimage.org/image/49ne3k3o/
到目前为止我的代码:
CSS:
#headerwrap {
position: relative;
width: 998px;
height: 100px;
margin: 0 auto;
pointer-events: none;
}
#header{
position: fixed;
top: 0;
width: 998px;
margin: 0;
background: url('../images/top.png') no-repeat;
height:100px;
z-index: 1;
pointer-events: none;
}
和 HTML 实现:
<div id="headerwrap"\>
<div id="header">
</div>
</div>
(页面宽690px,页眉998px)
任何帮助将不胜感激。
【问题讨论】:
标签: html css image center crop