Css 如何在不剪切图像的情况下设置背景图像高度,就像响应图像一样?

Css 如何在不剪切图像的情况下设置背景图像高度,就像响应图像一样?,css,Css,我在我的一个上应用了set背景图像,具有以下属性: .mydiv-left { background: url(path to image) no-repeat center center fixed; height:auto; // also tried with 100% background-size:auto // also tried with "100%" and "100% 100%" as well as "cover" } 这个结果是没有图像显示

我在我的一个
上应用了set
背景图像
,具有以下属性:

.mydiv-left {
     background: url(path to image) no-repeat center center fixed;
     height:auto; // also tried with 100%
     background-size:auto // also tried with "100%" and "100% 100%" as well as "cover"
}
这个结果是没有图像显示,但当我设置此图像的高度时,它会切断图像。因为该图像具有高分辨率,我希望它能够在不删除任何部分/信息的情况下适合我的div的较小区域

请记住,背景图像是动态的,并在循环中不断更改其他div

试试这个

CSS

如果您发布整个代码,很容易找到解决方案。

没有内容/高度将导致高度为0。我想这就是为什么你看不到自己的形象。
给你的
一个尺寸,背景尺寸就可以了


最简单的建议是以像素为单位为div指定
min height
,保持标记不变,下面是CSS

CSS

 .mydiv-left {
    background: url(http://www.wallng.com/images/2013/08/image-explosion-colors-background-beautiful-263613.jpg) no-repeat center center fixed;
    color : #FFF;
    min-height:200px;    /*this is the key*/
    height:auto;
    background-size: 100% 100%;
    background-repeat: no-repeat;
}
如果您给出
高度:auto
,它会将
div
缩放到内容高度。

如果您想显示
div
min height
是一个解决方案

谢谢大家的帮助,我可以通过以下代码完成:

mydiv {

  background: url(images/bg.jpg) no-repeat;
  height: 150px; 
  -webkit-background-size: cover;
  -moz-background-size: cover;
  -o-background-size: cover;
  background-size: cover;
}

最主要的是最后四行按我想要的方式工作。

你不能设置背景图像的动态高度和宽度。对于动态高度宽度,您必须在div中使用。是的,我以前也这样做过,但现在我的客户要求将其设置为div上的背景图像,而不是使用图像。请发布代码或发送js提琴。
.mydiv-left {
    background-image: url(path to image);
    height:(in px);
    width: (in px);
    background-size: 100% 100%;
    background-repeat: no repeat;
    background-position: center center;     
}
mydiv {

  background: url(images/bg.jpg) no-repeat;
  height: 150px; 
  -webkit-background-size: cover;
  -moz-background-size: cover;
  -o-background-size: cover;
  background-size: cover;
}
.mydiv-left {
    background-image: url(path to image);
    height:(in px);
    width: (in px);
    background-size: 100% 100%;
    background-repeat: no repeat;
    background-position: center center;     
}