yog*_*shi 7 html css background-image
我问一个问题,关于这一点,是具体到我的代码和人民是真正有帮助,所以我挑这是更susccessful答案,尽管我并没有解决我的问题.
问题:使用css显示大图像背景的最佳方法是什么?
我很想知道这样做的最佳方法是什么,以便它在上述三个选项中的所有分辨率下都能正常工作.
小智 4
CSS3 解决方案
您可以在 CSS3 中使用background-originand background-size,但 IE8 及更低版本不支持它。
PHP 解决方案 您可以使用 GD2 来缩放特定于用户浏览器的图像,该解决方案还涉及 JavaScript。
Living Social Way
他们插入带有标签的图像<img/>并将其固定。
<style type="text/css">
#background {
z-index: -1; /* put it under everything*/
position: fixed; /* make it stay in the same place, regardless of scrolling */
top: 0;
left: 0;
overflow: hidden; /* clip the image */
width: 100%; /* fill the full width of browser */
min-height: 950px; /* show at least this much of the image */
}
#background img {
width: 100%;
}
</style>
<body>
<div id="background"><img /></div>
<div id="content"><!-- Your Content Here --></div>
</body>
Run Code Online (Sandbox Code Playgroud)
Living Social 在其标签上应用了更多代码<img/>,但似乎有点多余,也许是为了更好的跨浏览器支持,我没有在这里展示。