Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/css/32.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Css 绝对div内的图像高度?_Css_Safari_Height_Css Position_Absolute - Fatal编程技术网

Css 绝对div内的图像高度?

Css 绝对div内的图像高度?,css,safari,height,css-position,absolute,Css,Safari,Height,Css Position,Absolute,Safari for Windows在绝对定位分区内没有正确计算img高度。该样式在Chrome和Firefox上运行良好 HTML: 注意事项: 这是HTML的简化。有多个大小不同的图像需要具有相同的高度(因此使用宽度:100%;高度:自动;不起作用) 这需要自适应/响应,因此我无法为图像或容器设置明确的宽度或高度 在类图像上,将“高度”设置为“自动”。这应该可以解决问题 同样的问题,我使用了jquery。到目前为止,我找不到任何解决方案: $('.image-inner').css('he

Safari for Windows在绝对定位分区内没有正确计算img高度。该样式在Chrome和Firefox上运行良好

HTML:

注意事项:

  • 这是HTML的简化。有多个大小不同的图像需要具有相同的高度(因此使用宽度:100%;高度:自动;不起作用)
  • 这需要自适应/响应,因此我无法为图像或容器设置明确的宽度或高度

  • 在类图像上,将“高度”设置为“自动”。这应该可以解决问题


    同样的问题,我使用了jquery。到目前为止,我找不到任何解决方案:

    $('.image-inner').css('height','100%').height($('.image-inner').height());
    

    不能我需要为图像保持一个一致的高度(通过JS切换,但这不是演示问题所必需的)。好的,那么为元素设置一个高度和宽度。你的问题没有解释你需要它。你是对的,我没有解释我需要它。我认为说我尝试了显而易见或更简单的解决方案是愚蠢的。我还应该提到它必须是响应性的,这就是为什么所有东西都是%的,没有设置宽度和高度。
    .image {
        position: relative;
        max-width: 100%;
        height: 0;
        padding-bottom: 75%;
    }
    
    .image-inner {
        position: absolute;
        top: 0;
        left: 0;
        width: 100%;
        height: 100%;
        z-index: 0;
    }
    
    .image img {
        width: auto;
        max-height: 100%;
        margin: 0 auto;
        display: block;
    }
    
    .image {
        position: relative;
        max-width: 100%;
        height: auto;
        padding-bottom: 75%;
    }
    
    $('.image-inner').css('height','100%').height($('.image-inner').height());