如何拉伸背景图像以填充 div [英] How to stretch the background image to fill a div
本文介绍了如何拉伸背景图像以填充 div的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想为不同的 div 设置背景图片,但我的问题是:
I want to set a background image to different divs, but my problems are:
- 图片大小固定(60px).
- 改变 div 的大小
如何拉伸背景图像以填充 div 的整个背景?
How can I stretch the background-image to fill the whole background of the div?
#div2{
background-image:url(http://s7.static.hootsuite.com/3-0-48/images/themes/classic/streams/message-gradient.png);
height:180px;
width:200px;
border: 1px solid red;
}
推荐答案
添加
background-size:100% 100%;
到背景图像下的 CSS.
to your css underneath background-image.
您还可以指定确切的尺寸,即:
You can also specify exact dimensions, i.e.:
background-size: 30px 40px;
这里:JSFiddle
这篇关于如何拉伸背景图像以填充 div的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文