将背景图像放入动态 div 中
我有一个背景图像(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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
使用标准 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
您只需将
background-size: cover;
添加到您的样式属性中即可You can just add
background-size: cover;
to your style attribute