更新时间: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