将背景图像放入动态 div 中

发布于 2024-10-03 05:22:42 字数 212 浏览 0 评论 0原文

我有一个背景图像(700x500px),我想用它填充一个动态div。在此示例中,div 只有 20 像素,但其高度可以超过 500 像素。

<div style="background-image:url('background.jpg');width:710px">
some content some content
</div>

i have a background image (700x500px) and i want to fill wit it a dynamic div. in this example the div is only 20px but it can have a height over 500px.

<div style="background-image:url('background.jpg');width:710px">
some content some content
</div>

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

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

发布评论

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

评论(2

冷血 2024-10-10 05:22:42

使用标准 CSS,您不能只适应背景图像。但是您可以在 div 中使用图像标签并调整其大小。然后在其前面使用您的内容,以便图像将用作背景。

您可以在此处找到更多详细信息、CSS 用法和示例页面:
http://www.quackit.com/html/codes/html_stretch_background_image.cfm

Using standard CSS you can't just fit a background image. But you can use an image tag in a div and make it resize. And then use your content in front of it, so the image will be used as a background.

You can find more details, css usage and an example page here :
http://www.quackit.com/html/codes/html_stretch_background_image.cfm

岁吢 2024-10-10 05:22:42

您只需将 background-size: cover; 添加到您的样式属性中即可

You can just add background-size: cover; to your style attribute

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文