相关疑难解决方法(0)

如何在保持图像宽高比的同时拉伸图像以填充<div>?

我需要将此图像拉伸到可能的最大尺寸,而不会溢出<div>或倾斜图像.

我无法预测图像的宽高比,因此无法知道是否使用:

<img src="url" style="width: 100%;">
Run Code Online (Sandbox Code Playgroud)

要么

<img src="url" style="height: 100%;">
Run Code Online (Sandbox Code Playgroud)

我不能同时使用两者(即style ="width:100%; height:100%;")因为这将拉伸图像以适应<div>.

<div>具有的大小为屏幕,这也是不可预测的百分比来设置.

html size image

190
推荐指数
10
解决办法
51万
查看次数

标签 统计

html ×1

image ×1

size ×1