简体   繁体   English

在div上拉伸图像背景或在div中拉伸完整背景图像

[英]stretch image background on a div or full backgound image in a div

I have this html structure 我有这个HTML结构

<div id="bg">

</div>

and a css 和一个CSS

#bg{
    background: transparent url(images/bg.png) no-repeat center center;
    background-size: 100%;
    width: 300px;
    height: 300px;
   }

as you can see from the above codes, this 'background-size: 100%;' 从上面的代码中可以看到,此“背景大小:100%;” should make the background image in the div(#bg) fill the whole container of (#bg) but unfortunately, it doesnt work at all even i also tried 'background-size: cover;' 应该使div(#bg)中的背景图像充满(#bg)的整个容器,但是不幸的是,即使我也尝试过'background-size:cover;',它也不起作用。 or 'background-size: contain;' 或“背景大小:包含;” but still no lucks, nothing works. 但仍然没有运气,什么都没有。 Is there any way or alternative way that I could make the background image in the div(#bg) full or will fill the container or will stretch proportionally as what the width and height of the div(#bg)? 有什么方法或其他方法可以使div(#bg)中的背景图像变满或填充容器,或按div(#bg)的宽度和高度成比例地拉伸?

Actually you are forgetting a parameter in your property declaration 实际上,您忘记了属性声明中的参数

Demo 演示版

background-size: 100% 100%;

Explanation: You are using background-size: 100%; 说明:您正在使用background-size: 100%; which will suffice only for x and not for y so you need to have 2 100% , 1 for the x and other for y 这仅适用于x而不适用y因此您需要2 100%x 1, y其他

Well, you have this solution background-size:100% 100%; 好吧,您有这个解决方案的背景大小:100%100%;

But it doesn't work in all browsers, if you want the fix for IE8,7 and 6 (I think) you ca try this: 但这并不适用于所有浏览器,如果您想修复IE8,7和6(我认为),可以尝试以下方法:

filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src='image.jpg', sizingMethod='scale');
    -ms-filter: "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='image.jpg', sizingMethod='scale')";

jQuery<div> 背景图像全尺寸拉伸</div><div id="text_translate"><p>基本上我要做的是用纯 HTML、CSS 和 jQuery 重新创建这个站点。</p><p> 目前该网站在搜索结果中的表现不太好,显然是因为它是 Flash,所以这就是我要解决的问题。</p><p> 我正在寻找的东西非常复杂,但我很乐意为所需的任何单独部件提供解决方案,并且我会弄清楚如何将它们放在一起。 我在互联网上到处搜索,并打电话找到任何接近我想要的东西。</p><p> 这就是我需要的。 主要是我担心的图像DIV...</p><ul><li> 我有两个 DIV,一个将保存图像,另一个将保存其下方的链接。 顶部 DIV 的高度为 70%,第二个为 30%。</li><li> 70% 高度顶部 DIV 中的图像应拉伸到<strong>至少填充</strong>DIV。 我的意思是图像周围不应该有空白,但显然图像也需要保持其纵横比。</li><li> 如果可能的话,我希望一些图像能够在这个 DIV 中旋转,具有简单的淡入淡出效果,可能是从 XML 文件加载的(但不一定)。</li></ul><p> 这是在我头上还是很容易做到?</p><p> 谢谢你提供的所有帮助。</p></div> - jQuery <div> background image full size stretch

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 拉伸背景图像以占据 div 的整个高度 - Stretch background image to occupy full height of div jQuery<div> 背景图像全尺寸拉伸</div><div id="text_translate"><p>基本上我要做的是用纯 HTML、CSS 和 jQuery 重新创建这个站点。</p><p> 目前该网站在搜索结果中的表现不太好,显然是因为它是 Flash,所以这就是我要解决的问题。</p><p> 我正在寻找的东西非常复杂,但我很乐意为所需的任何单独部件提供解决方案,并且我会弄清楚如何将它们放在一起。 我在互联网上到处搜索,并打电话找到任何接近我想要的东西。</p><p> 这就是我需要的。 主要是我担心的图像DIV...</p><ul><li> 我有两个 DIV,一个将保存图像,另一个将保存其下方的链接。 顶部 DIV 的高度为 70%,第二个为 30%。</li><li> 70% 高度顶部 DIV 中的图像应拉伸到<strong>至少填充</strong>DIV。 我的意思是图像周围不应该有空白,但显然图像也需要保持其纵横比。</li><li> 如果可能的话,我希望一些图像能够在这个 DIV 中旋转,具有简单的淡入淡出效果,可能是从 XML 文件加载的(但不一定)。</li></ul><p> 这是在我头上还是很容易做到?</p><p> 谢谢你提供的所有帮助。</p></div> - jQuery <div> background image full size stretch div class 中的背景图像 - Backgound Image in div class 如何在DIV中拉伸背景图像 - How to stretch the background image inside a DIV 如何拉伸背景图像以填充div - How to stretch the background image to fill a div 拉伸div背景图片的宽度并设置高度 - Stretch width of div background image with set height 背景图像伸展Div的100%高度 - Background Image Stretch 100% Height of Div 在div拉伸内设置背景图片 - Set background image inside div stretch div内的“拉伸”背景图片-100%的高度 - 'Stretch' background image within a div - 100% height 如何设置背景图片大小= 100%或拉伸到最大 <div> 背景 - how to set background image size= 100% or stretch upto the full <div> background
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM