css 网站大背景(按比例缩放背景图片)
来源:互联网 发布:2017最新网络用语大全 编辑:程序博客网 时间:2024/05/13 06:21
很多网站是全背景图片的,而且适应各种主流分辨率,给人一种干净大气的感觉,实属设计派的一个耍酷良方,下面介绍几种实现全屏图片自适应缩放背景图片的方法。
1.帅气简单的CSS3方法
html { background: url(images/bg.jpg) no-repeat center center fixed; -webkit-background-size: cover; -moz-background-size: cover; -o-background-size: cover; background-size: cover;}
- Safari 3+
- Chrome Whatever+
- IE 9+
- Opera 10+
- Firefox 3.6+
2.只使用CSS之方法一
img.bg { min-height: 100%; min-width: 1024px; width: 100%; height: auto; position: fixed; top: 0; left: 0;}@media screen and (max-width: 1024px) { img.bg { left: 50%; margin-left: -512px; }}
- 以下浏览器的任何版本: Safari / Chrome / Opera / Firefox
- IE 6: (各种方案奈我何?!)
- IE 7/8: 大部分工作,小屏幕的时候全屏,但是不是居中
- IE 9: 没问题
3.只使用CSS之方法二
#bg { position:fixed; top:-50%; left:-50%; width:200%; height:200%;}#bg img { position:absolute; top:0; left:0; right:0; bottom:0; margin:auto; min-width:50%; min-height:50%;}
- Safari / Chrome / Firefox
- IE 8+
- Opera
4.jQuery方法
#bg { position: fixed; top: 0; left: 0; }.bgwidth { width: 100%; }.bgheight { height: 100%; }
$(window).load(function() { var theWindow = $(window), $bg = $("#bg"), aspectRatio = $bg.width()/$bg.height(); function resizeBg() { if ( (theWindow.width()/theWindow.height()) $bg.removeClass() .addClass('bgheight'); }else{ $bg.removeClass() .addClass('bgwidth'); } } theWindow.resize(function() { resizeBg(); }).trigger("resize");});
- IE7+
- 任何除了IE的浏览器的任何版本
转载自:网站大背景(按比例缩放背景图片)
0 0
- css 网站大背景(按比例缩放背景图片)
- 网站大背景(按比例缩放背景图片)
- 网站大背景(按比例缩放背景图片)
- 网站大背景(按比例缩放背景图片)
- java swing的背景图片按比例缩放
- java swing的背景图片按比例缩放
- 用CSS按比例缩放图片
- 用CSS按比例缩放图片
- css图片按比例自动缩放
- 用CSS按比例缩放图片
- CSS之容器按比例缩放
- 按比例缩放分辨率大的图片
- css大背景图片处理
- 如何让css背景图片占满全部背景,并且随着浏览器缩放图片保持长宽不变呢?
- div+css怎么让背景图片自动缩放
- css样式小结和脚本实现图片按比例缩放
- CSS----填充,背景图片,背景重复,背景附着,背景定位
- css背景图片和背景颜色一起显示
- maven 常用命令
- CXF实战之集成Spring(三)
- iOS方法和实例变量
- WPF MVVM绑定DateGrid的列的显隐性解决方案
- Spring配置事务中的 transactionAttributes 各属性含义
- css 网站大背景(按比例缩放背景图片)
- Bomb(数位Dp)
- HDU 1997 汉诺塔VII
- operator 的主要用法
- 【二分图匹配】poj1325Machine Schedule
- VTK中图像像素位置的提取
- 一些还没有写的AC自动机题
- RGB图像转换到CIELab空间的研究及优化
- Python去除多余空格