且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

高度:Internet Explorer 8 及更低版本中的自动

更新时间:2023-12-04 13:44:10

试试这个:

img {
  width: inherit;  /* Make images fill their parent's space. Solves IE8. */
  max-width: 100%; /* Add !important if needed. */
  height: auto;    /* Add !important if needed. */
}

或:

img { max-width:100%; height: auto; } /* Enough everywhere except IE8. */
@media  screen {img { width: auto }} /* Prevent height distortion in IE8. */

两种解决方案都有效.不同之处在于 width:inherit 使图像填充其父空间,而 width:auto 将它们最大化为它们的实际尺寸.请参阅 fit.css

Both solutions work. The difference is that width:inherit makes images fill their parent's space whereas width:auto maxes them at their actual dimensions. See fit.css