python全屏背景_[转载]完美的背景图全屏代码

具有以下特点:

填满整个页面,没有空白空间

能缩放图像

保留图像尺寸比例

图像居中

不因图像原因产生滚动条

更多地支持全部浏览器

不使用类似FLash的东西

帅气,简单,先进的css3方法

CSS

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 any+

IE 9 +

Opera 10+ (Opera 9.5 supported background-size but not the keywords)

Firefox 3.6+ (Firefox 4 supports non-vendor prefixed version)

查看Demo

CSS-Only Technique #1

CSS

img.bg {

/* Set rules to fill background */

min-height: 100%;

min-width: 1024px;

/* Set up proportionate scaling */

width: 100%;

height: auto;

/* Set up positioning */

position: fixed;

top: 0;

left: 0;

}

@media screen and (max-width: 1024px) { /* Specific to this particular image */

img.bg {

left: 50%;

margin-left: -512px; /* 50% */

}

}

支持

Any version of good browsers: Safari / Chrome / Opera / Firefox

IE 6: Borked - but probably fixable if you use some kind of fixed positioning shim

IE 7/8: Mostly works, doesn't center at small sizes but fills screen fine

IE 9: Works

CSS-Only Technique #2

HTML

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值