【发布时间】:2013-04-01 05:13:49
【问题描述】:
当 html 的内容增加时,我想拉伸图像。并且每当内容增加时,就会自动拉伸背景图像,而无需在 css 中重复。在 Html 页面中。
【问题讨论】:
当 html 的内容增加时,我想拉伸图像。并且每当内容增加时,就会自动拉伸背景图像,而无需在 css 中重复。在 Html 页面中。
【问题讨论】:
这是我的 CSS:
div {
background-image: url(http://placekitten.com/200/300);
background-repeat: no-repeat;
min-width: 200px;
min-height: 300px;
background-size: 100% 100%;
}
background-size: cover; 也可以使用,但效果略有不同。
【讨论】:
这是我避免拉伸的建议:
div {
background-image: url(http://placekitten.com/200/300);
background-repeat: no-repeat;
height: auto;
width: 100%;
background-position: 50% 0;
background-size: 100%;
}
【讨论】:
我们可以在添加大内容时拉伸背景图像而不用在css中重复图像
请尝试下一个:
background-size: cover;
或
background-size: contain;
【讨论】: