我想显示具有一定宽度和高度的URL中的图像,即使它具有不同的大小比例.所以我想调整大小(保持比例),然后将图像剪切到我想要的大小.
我可以用html img属性调整大小,我可以用background-image.
我怎么能两个都做?
例:
这个图片:

有大小800x600像素,我想像200x100像素的图像一样显示
随着img我可以调整图像200x150px:
<img
style="width: 200px; height: 150px;"
src="http://i.stack.imgur.com/wPh0S.jpg">
Run Code Online (Sandbox Code Playgroud)
这给了我这个:
<img style="width: 200px; height: 150px;" src="https://i.stack.imgur.com/wPh0S.jpg">
Run Code Online (Sandbox Code Playgroud)
并且background-image我可以剪切图像200x100像素.
<div
style="background-image:
url('https://i.stack.imgur.com/wPh0S.jpg');
width:200px;
height:100px;
background-position:center;"> </div>
Run Code Online (Sandbox Code Playgroud)
给我:
<div style="background-image:url('https://i.stack.imgur.com/wPh0S.jpg'); width:200px; height:100px; background-position:center;"> </div>
Run Code Online (Sandbox Code Playgroud)
我怎么能两个都做?
调整图像大小,然后将其剪切为我想要的大小?