[英]Add a responsive background image to a division class bootstrap
I have to use a javascript function inside an image.Hence i would like to add the image as background-image in a division class.I want it to be responsive and scalable just like the <img>
tag that i use. 我必须在图像中使用javascript函数,因此我想将图像添加为除法类中的背景图像。我希望它具有响应性和可伸缩性,就像我使用的<img>
标签一样。 How can this be achieved? 如何做到这一点?
CSS3 background-size can be used here. CSS3 background-size可以在这里使用。
background-size: [auto|percentage|units - for width] [auto|percentage|units - for height];
For example: 例如:
.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%;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.