如何用CSS设置拉伸背景图片

发布于 2024-09-27 07:23:58 字数 84 浏览 4 评论 0原文

如何使用 CSS 拉伸页面背景以及 DIV 和 DIV 的背景图像表格背景...这样,如果窗口大小发生变化,背景图像大小应该相应地拉伸(扩展/收缩)...

how to stretch the background images using CSS for page backgrounds and for DIV & table backgrounds... so that if the window size changes the background image size should stretch (expand / contract) accordingly....

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

红颜悴 2024-10-04 07:23:58

只能在 CSS3 中使用 background-size 来完成。您还可以使用 -o-background-size-webkit-background-size-moz-background-size 来尝试最大化浏览器支持。您应该将该值设置为 100%。在其他浏览器中,一旦图像超出范围,您可以重复背景或使用颜色,但不能拉伸。下面的第一个链接中有一些建议来尝试伪造它。

请参阅:

Only can be done in CSS3 with background-size. You can also use -o-background-size, -webkit-background-size, and -moz-background-size to try and maximize browser support. You should set the value to be 100%. In other browsers you can repeat the background or use a color once you're out of image, but not stretch. There are suggestions in the first link below to try and fake it.

See:

陪我终i 2024-10-04 07:23:58

您可以通过将其固定为图层来在没有 css3 的情况下完成此操作。

<img src="background.png" style="position: fixed; top: 0; left: 0; width: 100%; height: 100%; position:absolute; z-index:-1;" />
<div style="position: static;z-index: 1; ">
    content
</div>

You can do it without css3 by fixing it as a layer.

<img src="background.png" style="position: fixed; top: 0; left: 0; width: 100%; height: 100%; position:absolute; z-index:-1;" />
<div style="position: static;z-index: 1; ">
    content
</div>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文