将preserveAspectRatio用于外部svg
#c{
height: 160px;
width: 250px;
background-color: orange;
}
img{
width: 100%;
height: 100%;
}
#c{
height: 160px;
width: 250px;
background-color: orange;
}
img{
width: 100%;
height: 100%;
}
<div>
<img src="https://restcountries.eu/data/caf.svg" alt="" preserveAspectRatio="none">
</div>
回答
您可以使用SVG 片段标识符来覆盖 preserveAspectRatio 的值,例如
<div>
<img src="https://restcountries.eu/data/caf.svg#svgView(preserveAspectRatio(none))">
</div>