html的cover属性,html – 有一个等价于background-size:cover和包含图像元素?

解决方案#1 – 新的

object-fit property(

No IE support yet)

只是设置对象适合:盖;在img。

body {

margin: 0;

}

img {

display: block;

width: 100vw;

height: 100vh;

object-fit: cover;

}

c6feba69975874c8b6efa8ad78870655.png

你可以阅读更多关于这个新的属性在这个webplatform article。

从上面的文章 – 关于’cover’值:

The whole image is scaled down or expanded till it fills the box

completely, the aspect ratio is maintained. This normally results in

only part of the image being visible.

此外,这里是从上面的文章a fiddle演示object-fit属性的所有值。

解决方案#2 – 用css替换img的背景图片

body {

margin: 0;

}

img {

position: fixed;

width: 0;

height: 0;

padding: 50vh 50vw;

background: url(http://lorempixel.com/1500/1000/city/Dummy-Text) no-repeat;

background-size: cover;

}

bc47f487f80e4faf0826acfcb78f021a.png

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值