我必须在图像中使用 javascript 函数。因此我想将图像添加为分区类中的背景图像。我希望它像 <img>
一样具有响应性和可扩展性。我使用的标签。如何实现?
最佳答案
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%;
}
关于javascript - 将响应式背景图像添加到部门类 Bootstrap ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21643575/