【发布时间】:2015-06-23 07:48:51
【问题描述】:
我正在尝试制作一个简单的网站,其中标题在浏览器中拉伸 100% 宽,然后将标题下方的内容设置为 1100 像素宽居中。这在桌面浏览器(Chrome、Safari、Firefox)上运行良好。但是在移动端有问题。我没有做任何响应式 CSS,但标题中的图像仍应填充浏览器的宽度。这是我与此标头相关的代码。
HTML:
<div class="featured" style="background-image:url('image.jpg');" onclick="location.href='#';">
<div class="featured-details">
<h2><a href="#">Headline</a></h2>
<p>Some text goes here</p>
</div>
</div>
CSS:
.featured {
width: 100%;
height: 500px;
position: relative;
background-size: cover;
background-position:center center;
overflow: hidden;
cursor: pointer;
box-sizing: border-box;
z-index: 100;
}
.featured-details {
color: #ebebeb;
bottom: 10px;
width: 1100px;
left: 0;
right: 0;
margin-left: auto;
margin-right: auto;
position: absolute;
z-index: 150;
}
如您所见,它在桌面上运行良好:http://sistestopp.com/uploads/desktop.png
但在移动设备上,标题不是 100%:http://sistestopp.com/uploads/mobile.png (页脚做同样的事情)。
有什么建议吗?
【问题讨论】:
-
是的,抱歉,临时 URL 是 sistestopp.com/ny
-
您希望您的标题图像拉伸到移动视图中的其他内容 div 还是什么?
-
但是如果你想让你的标题图像响应然后使用 background-size:100%..仍然不确定你的观点所以告诉我们到底是什么问题..thanx
-
如果您查看手机屏幕截图,您可以看到标题图像(带有羊)没有填满浏览器。我只是希望它一直向右延伸。它在所有桌面浏览器上都能完美运行,但移动浏览器似乎对此存在问题。在此处查看屏幕截图:sistestopp.com/uploads/mobile.png