gpt4 book ai didi

image - 使用 img max-width : 100% works in Chrome but not IE when parent div has position: absolute 使用浏览器窗口自动调整图像大小

转载 作者:行者123 更新时间:2023-11-28 10:03:31 24 4
gpt4 key购买 nike

我正在构建一个响应式网站,我发现使用 img max-width:100% 调整浏览器窗口大小的自动调整图像大小在 Chrome 中有效,但在 IE 和 Firefox 中无效,当任何父级或祖先具有 position:absolute;

(有关此技术的信息,请参阅 http://webdesignerwall.com/tutorials/responsive-design-with-css3-media-queries)

以下代码可用于演示或重现此问题。你也可以在 http://sketchmotion.com/image-test2/ 看到这个.您会注意到调整浏览器窗口的大小会调整 Chrome 中的图像大小,但不会调整 IE(我正在运行 IE 11)。但是,如果您删除以下行:

    .mydiv{
position: absolute;
}

您会发现它现在可以在 Chrome 和 IE 中运行。

这没有帮助,因为我使用 position: absolute;在我网站上的一些父 div 上。我需要我的网站在 IE 和 Firefox 中运行。

如果有解决此问题的方法,请告诉我,以便我可以使用网站上的浏览器窗口调整图像大小。

<html>
<head>

<!-- <link href="/cssh/ImageTest.css" rel="stylesheet" type="text/css"></link> -->

<style type="text/css">

.mydiv{
position: absolute;
}

img{
/*** Scaling Images with the Browser Window in CSS is pretty simple to implement for both images and video. ***/
/*** You can set the media element’s max-width to 100 percent, and the browser will make ***/
/*** the image shrink and expand depending on its container. ***/
/*** To maintain the right proportions use auto height ***/
max-width: 100%;
height: auto;
width: auto\9; /* ie8 */
}

</style>



</head>

<body>


<!-- -->
<div class="mydiv">
<div class="slides">
<div class="slide">
<img alt="" src="http://sketchmotion.com/ImagesSM/SM_Slider_1_SketchMotion_w_Sketch.jpg" />
</div>
</div>
</div>



</body>
</html>

最佳答案

试试这个:

.mydiv {
position: absolute;
width: 100%;
}

我没有确切的解释,但这行得通。 :)

关于image - 使用 img max-width : 100% works in Chrome but not IE when parent div has position: absolute 使用浏览器窗口自动调整图像大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20577491/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com