简体   繁体   English

最小高度不缩放

[英]min-height doesn't scale

I want to scale a image in all IE Browsers. 我想在所有IE浏览器中缩放图像。

My Code: 我的代码:

<div class="outer"><img src="text.png" /></div>

CSS 的CSS

.outer {
   position:absolute;
   top: 0;
   left: 0;
   height: 100%;
   width: 100%;
   text-align: center;
}
img {
   min-height: 100%;
}

Like this the img-Tag makes a autoscale with the width. 像这样,img-Tag会自动调整宽度。 But that doesn't work in IE. 但这在IE中不起作用。 The Image just scale vertical. 图像只是垂直缩放。

Can anybody help me ? 有谁能够帮助我 ?

If you want the image width to always span the entirety of the browser window, you have to ensure you set the body and parenting containers (in this case outer ) to have width: 100% so that width percentages work correctly for descendants. 如果要使图像宽度始终覆盖整个浏览器窗口,则必须确保将body容器和育儿容器(在本例中为outer )设置为width: 100%以便宽度百分比对于后代而言正确工作。 Then, set an explicit width to the image at 100% and the height should scale automatically. 然后,将图像的显式宽度设置为100% ,并且高度应自动缩放。

body, .outer {
    width: 100%;
}
img {
    width: 100%;
}

jsfiddle jsfiddle

According to msdn , 根据msdn

If the height of the containing block is not explicitly set, then the element has no minimum height and the min-height property is interpreted as 0%. 如果未明确设置包含块的高度,则该元素没有最小高度,并且min-height属性被解释为0%。

You need to mention height to the parent container explicitly. 您需要明确提及父容器的高度。

body{height: 800px;}  /* set your own height here */

According to Sitepoint 根据Sitepoint

If the height of the containing block is not specified explicitly (that is, it depends on content height), and this element is not absolutely positioned, the percentage value is treated as zero. 如果未明确指定包含块的高度(即,它取决于内容的高度),并且该元素的位置不是绝对的,则将百分比值视为零。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM