CSS背景图拉伸不变形

在线效果体验:http://hovertree.com/texiao/mobile/3.htm

请使用手机浏览器查看。

css代码:

.bg{
background:url(http://hovertree.com/texiao/mobile/3/hovertree01.jpg);
filter:"progid:DXImageTransform.Microsoft.AlphaImageLoader(sizingMethod=‘scale‘)";
-moz-background-size:100% 100%;
    background-size:100% 100%;
}  

HTML文件代码:

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>DIV缩放背景自适应(不变形)jQuery-HoverTree</title>
<style type="text/css">
a {
color: white;
}

body {
font-family: 幼圆,宋体,‘Times New Roman‘, Times, serif;color:white;
}

.picwidth {
width: 100%;
text-align: left;
filter: "progid:DXImageTransform.Microsoft.AlphaImageLoader(sizingMethod=‘scale‘)";
-moz-background-size: 100% 100%;
background-size: 100% 100%;
}

body {
margin: 0px;
background-color: #120c0c;

}

.content {
width: 206px;
margin: 0px auto;
padding-top: 10px;
line-height: 16px;
}

.frame {
width: 256px;
margin: 0px auto;
}
</style>
<script src="http://hovertree.com/ziyuan/jquery/jquery-2.1.4.min.js"></script>
</head>
<body>
<div class="frame">
<div id="contentHead" style="height:231px;background-image:url(http://hovertree.com/texiao/mobile/3/hovertree01.jpg)" class="picwidth">
<input type="button" value="放大" id="keleyibig" /><input type="button" value="缩小" id="keleyismall" /><a href="http://hovertree.com/hvtart/bjae/f43r3qry.htm">原文</a>
</div>
<div id="contentBody" style="background-image:url(http://hovertree.com/texiao/mobile/3/hovertree02.jpg);height:99px;color:White;" class="picwidth">
<div class="content">
今日人物:
<div style="text-align:center">谢霆锋</div>
<br />请点击放大,缩小按钮。
</div>
</div>
<div id="contentBottom" style="background-image:url(http://hovertree.com/texiao/mobile/3/hovertree03.jpg);height:124px" class="picwidth">DIV缩放背景自适应(不变形)
<br />请使用支持HTML5的浏览器查看本页
<br /><a href="http://hovertree.com/texiao/">特效库</a> <a href="http://hovertree.com">首页</a> <a href="http://keleyi.com">柯乐义</a> <a href="http://hovertree.com/hvtart/bjae/f43r3qry.htm">原文</a></div>
</div>
<script>
$(function () {

$(".frame").width(300);

var documentWidth = $(document.body).width();
if (documentWidth < 600)
$(".frame").width(documentWidth);

var cHead = $("#contentHead"); var cBody = $("#contentBody"); var cBottom = $("#contentBottom");

function setHeight() {
cHead.height(((cHead.width() / 320) * 289));
cBody.height(((cBody.width() / 80) * 31));
cBottom.height(((cBottom.width() / 64) * 31));
}

setHeight();

$("#keleyibig").on("click", function ()
{
$(".frame").width($(".frame").width() + 50)

setHeight();
})

$("#keleyismall").on("click", function () {
$(".frame").width($(".frame").width() - 50)

setHeight();
})

})
</script>
</body>
</html>

Web前端资源:http://www.cnblogs.com/jihua/p/webfront.html

这张图可作为手机屏幕背景

时间: 2024-08-16 04:47:23

CSS背景图拉伸不变形的相关文章

CSS背景图拉伸自适应尺寸,全浏览器兼容

突然有人问我这个问题,说网上CSS filter的方法在非IE浏览器下不奏效.思考之后,问题之外让我感慨万千啊,很多我们所谓的难题,都会随着时代的发展迎刃而解,或被新的问题所取代. 当CSS背景图片拉伸这个问题产生时,CSS3也只是浮云.... 对于IE而言网上常见的方法是使用CSS滤镜,但那时Firefox还小,Chrome还没出生,IE称霸天下.....但如今,我们用三四行简短的代码就能实现全浏览器兼容的方法: .bg{ background:url(http://wyz.67ge.com/

CSS 背景图拉伸 兼容 FF Chrome IE 等主流浏览器(转)

注:本文欢迎转载,以下为本人亲测,转载请注明:http://blog.csdn.net/wqmain/article/details/8844286 相信各位一定碰到过这种情况,按钮作为DIV的背景图来显示,实际上有多个这样的按钮,而且DIV中的文字,也就是按钮上要显示的文字内容和个数都 不定,这种情况下就需要用背景图片拉伸效果来处理了,只需做一个按钮图片,作为DIV的背景图时随着DIV的宽度或高度自适应就OK了.网上也找过,但不 兼容IE或有bug,下面贴出本人亲测代码,兼容主流浏览器,包括F

CSS背景图拉伸自适应尺寸,全浏览器兼容代码

.bg{ background:url(http://wyz.67ge.com/wp-content/uploads/qzlogo.jpg); -moz-background-size:100% 100%; background-size:100% 100%; }

CSS背景图拉伸自适应尺寸

.bg{ background:url(images/test.jpg); filter:"progid:DXImageTransform.Microsoft.AlphaImageLoader(sizingMethod='scale')"; -moz-background-size:100% 100%; background-size:100% 100%; }

css背景图片拉伸 以及100% 满屏显示

如何用css背景图片拉伸 以及100% 满屏显示呢?这个问题听起来似乎很简单.但是很遗憾的告诉大家.不是我们想的那么简单. 比如一个容器(body,div,span)中设定一个背景.这个背景的长宽值在css2.1之前是不能被修改的.  所以实际的结果是只能重复显示,所以出现了repeat,repeat-x,repeat-y,no-repeat这些属性.就是用来控制背景图片的显示的.所以一般用作背景图片的有2类: 1.是一整张大图,尺寸和区域大小刚好吻合  2.一个很小的条状图,通过repeat后

css 背景图片拉伸[转]

http://www.jeasyuicn.com/css-background-image-stretching.html background-image:url(bg.png); -moz-background-size: 100% 100%; -o-background-size: 100% 100%; -webkit-background-size: 100% 100%; background-size: 100% 100%; -moz-border-image: url(bg.png)

css背景图与html插入img的区别

一直以来都认为css背景图与直接插入img图片的效果是差不多的,直到最近拜读了一位大神的作品,发现大部分图片都是通过背景图形式显示的,于是在此总结了下二者的区别: 1. css中的图片以背景图形式存在,写在html中的图片以标签形式存在.而在网页加载过程中,以css背景存在的图片会等到html结构加载完成才开始加载,而html中的img标签是网页结构(内容)的一部分会在加载结构的过程中加载. 附:在一个单纯由Html和Css组成的页面中,背景图片总是最后加载的,那么假若我们想要使用较小的背景图片

css背景图片拉伸

css背景图片拉伸 background-image:url(bg.png); -moz-background-size: 100% 100%; -o-background-size: 100% 100%; -webkit-background-size: 100% 100%; background-size: 100% 100%; -moz-border-image: url(bg.png) 0; background-repeat:no-repeat\9; background-image:

css背景图定位

css背景图定位 20%的功能满足80%的需求.爱.喜悦.和平. html代码 <!DOCTYPE html> <html> <head> <title>css背景图定位</title> <meta http-equiv="content-type" content="utf-8"/> <style> div{width:34px;height:34px;border:solid 1