html中div元素的图像背景
问题描述:
嗨.
我在html页面中有一个"div"元素.div的"width属性"基于百分比,例如"width:80%",我想将图片设置为div的背景属性.
我有一个宽度为1000px的图像,所以我想图像宽度随div的宽度而变化.
那我该怎么做?
hi.
i have a "div" element in my html page.the "width property" of div is based on percent e.g "width:80%",i wanna set a image to div''s background property.
i have a image that its width is 1000px so i wanna image width change with width of div.
so how i do it?
thank.
答
如何使用background-size属性?
您可以使背景为拉伸,平铺或都不为背景.查看此属性的"cover","contain"和"100%"值.
How about you use the background-size property?
You can have the background either stretch, tile or neither. Look into the ''cover'', ''contain'' and ''100%'' values for this attribute.