我必须在图像中使用javascript函数。我想在分区类中将图像添加为背景图像。我希望它像<img>
标记一样具有响应性和可伸缩性使用。如何实现这一目标?
答案 0 :(得分:1)
CSS3 background-size 可以在这里使用。
background-size: [auto|percentage|units - for width] [auto|percentage|units - for height];
例如:
.bg{
/*will stretch the element's background to its full width (saving proportions of the picture - so it may be cut vertically or not fill the entire height):*/
background-size:100% auto;
/*will stretch the element's background to its full height (it may be cut - this time - horizontally or not fill the entire width):*/
background-size:auto 100%;
/* the background will be forced to the 50% of the el's width and 40% of its height respectively: */
background-size:50% 40%;
}