码迷,mamicode.com
首页 > Web开发 > 详细

[CSS] Control Image Aspect Ratio Using CSS

时间:2016-10-27 00:45:30      阅读:324      评论:0      收藏:0      [点我收藏+]

标签:back   aspect   tomato   blog   ack   demo   fit   box   image   

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;
}

 

[CSS] Control Image Aspect Ratio Using CSS

标签:back   aspect   tomato   blog   ack   demo   fit   box   image   

原文地址:http://www.cnblogs.com/Answer1215/p/6002203.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!