Home  >  Article  >  Backend Development  >  背景图片随div的大小而改变其大小,该怎么解决

背景图片随div的大小而改变其大小,该怎么解决

WBOY
WBOYOriginal
2016-06-13 11:57:161219browse

背景图片随div的大小而改变其大小
背景图片随div的大小而改变其大小,我的div是可以人为改变的
------解决方案--------------------

<br /><style type="text/css"><br />.dd{<br />	background-image:url('http://www.csdn.net/css/logo.png');<br />	background-size:100% 100%;<br />	width:480px;<br />	height:180px;<br />	border:1px solid #FF0000;<br />}<br /></style><br /><br /><div class="dd"></div><br />

------解决方案--------------------
这个是CSS3,需要IE9及以上才支持。
------解决方案--------------------
用jQuery 获取宽度  在给div层的width属性赋值
------解决方案--------------------
兼容IE了。
<br /><style type="text/css"><br />.dd{<br />    background-image:url('http://www.csdn.net/css/logo.png');<br />    background-size:100% 100%;<br />    width:480px;<br />    height:180px;<br />    border:1px solid #FF0000;<br />	filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(<br />    src='http://www.csdn.net/css/logo.png',<br />    sizingMethod='scale');<br />}<br /></style><br /> <br /><div class="dd"></div><br />

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn