admin管理员组文章数量:1426798
Come a bit unstuck here.
I've got a div thats approx. 2000px wide by 800px tall.
Inside that div I have another div, with a background image.
I want the internal div, to take 80% height of the parent container, and for the width to keep proportion with the height, so the background image doesn't distort, if this makes sense?
Im using CSS3 to scale the background image 100% both x and y.
.internal-box {
background:url(images/elevator.png) repeat scroll 0 0 transparent;
background-size:100% 100%;
height: 80%;
width: auto;
}
/
Come a bit unstuck here.
I've got a div thats approx. 2000px wide by 800px tall.
Inside that div I have another div, with a background image.
I want the internal div, to take 80% height of the parent container, and for the width to keep proportion with the height, so the background image doesn't distort, if this makes sense?
Im using CSS3 to scale the background image 100% both x and y.
.internal-box {
background:url(images/elevator.png) repeat scroll 0 0 transparent;
background-size:100% 100%;
height: 80%;
width: auto;
}
http://jsfiddle/JbmE6/
Share Improve this question edited Feb 5, 2013 at 11:59 Liam asked Feb 5, 2013 at 11:52 LiamLiam 9,86340 gold badges114 silver badges214 bronze badges 3- 3 Please clarify your question and maybe add a jsfiddle example for us to test our solutions. – kleinfreund Commented Feb 5, 2013 at 11:55
- Ive added a fiddle @asifsid88, Hopefully the ment explains better. – Liam Commented Feb 5, 2013 at 11:59
- zenelements./blog/css3-background-images – salexch Commented Feb 5, 2013 at 12:00
1 Answer
Reset to default 5Try this:
background-size: contain;
background-repeat: no-repeat;
However note that this might not be fully supported in all browsers such as IE8.
Also note that this doesn't make the <div>
itself any smaller, it only makes the background image appear in only the relevant portion. If you put a border
on .small
you will see in fact it is 100% width of its container.
本文标签: javascriptScaling div size with background image whilst keeping aspect ratioStack Overflow
版权声明:本文标题:javascript - Scaling div size with background image whilst keeping aspect ratio - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745478551a2660075.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论