首页 > 代码库 > [CSS] Control Image Aspect Ratio Using CSS
[CSS] Control Image Aspect Ratio Using CSS
Resize images and videos to fill their parent and maintain their aspect ratio with pure CSS. The new object-fit
and object-position
properties allow you to scale images and videos, much like you could with background-size
and background-position
.
img { width: 90vw; height: 75vh; border: 3px solid tomato;}.img-con1 img{ object-fit: fill;}.img-con2 img{ object-fit: contain;}.img-con3 img{ object-fit: cover;}.img-con4 img{ object-fit: none;}.img-con5 img{ object-fit: scale-down;}.img-con6 img{ object-fit: fill; object-position: 20px 5px;}/* Demo styles only */* { box-sizing: border-box;}body { margin: 0;}
<iframe style="width: 100%; height: 500px;" src="https://embed.plnkr.co/gwACXqvA4baVo4DkTedB/" width="320" height="240"></iframe>
[CSS] Control Image Aspect Ratio Using CSS
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。