通过 github 搜索 object-fit ie  ,  借鉴大佬兼容 ie 的经验。

下载解压到文件夹 , 打开测试目录 , 查看 demo

使用 ie 打开demo , 查看显示效果 :

代码 :

<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<link rel="stylesheet" href="styles.css">
<link rel="stylesheet" href="../dist/polyfill.object-fit.css">
<style>
img {
width: 100%;
height: 35em; margin: 10px 0;
border: 5px solid red; object-fit: cover;
overflow: hidden;
}
</style>
</head>
<body>
<h1><code>object-fit: cover;</code></h1>
<img src="data:image.jpg"> <script src="../dist/polyfill.object-fit.js"></script>
<script>
// Call polyfill to fit in images
document.addEventListener('DOMContentLoaded', function () {
objectFit.polyfill({
selector: 'img',
fittype: 'cover'
});
});
</script>
</body>
</html>

通过 demo 可以发现 需要引入的文件  :polyfill.object-fit.css   和   dist/polyfill.object-fit.js  。

还需要 底部初始化 , 在 fittype 后 输入 object-fit  的类型。 即可实现对 ie 的兼容


以下是我个人的实践 :

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="./polyfill.object-fit.min.css">
<title>响应式图片</title>
<style>
body{
margin: 0;
}
img{
height: 100vh;
width: 100%;
display: block;
object-fit: cover;
}
</style>
</head>
<body> <picture>
<!-- 横屏 320px-->
<source media="(min-width: 320px) and (max-width: 640px) and (orientation: landscape)" srcset="./img/lx.png"> <!-- 竖屏 320px-->
<source media="(min-width: 320px) and (max-width: 640px) and (orientation: portrait)" srcset="./img/lx2.png"> <!-- 横屏 640px -->
<source media="(min-width: 640px) and (orientation: landscape)" srcset="./img/lx.png"> <!-- 竖屏 640px-->
<source media="(min-width: 640px) and (orientation: portrait)" srcset="./img/lx.png"> <!-- 默认 -->
<img src="./img/lx.png" alt="this is a picture">
</picture> <script src="./polyfill.object-fit.min.js"></script>
<script>
document.addEventListener('DOMContentLoaded', function () {
objectFit.polyfill({
selector: 'img',
fittype: 'cover'
});
});
</script>
</body>
</html> <!-- 解决图片下的白边
/* 第一种 display: block; */
/* 第二种 */
vertical-align:bottom;
/* 第三种 img的父级容器,添加属性overflow:hidden */
-->

css : object-fit 兼容 ie 的解决方案的更多相关文章

  1. 在线生成CSS样式和兼容的字体格式

    http://www.fontsquirrel.com/tools/webfont-generator 在线生成CSS样式和兼容的字体格式.

  2. css 清除浮动 兼容IE+, FF

    上代码: <!doctype html> <html> <head> <meta charset="utf-8"> <titl ...

  3. div+css 布局下兼容IE6 IE7 FF常见问题

    div+css 布局下兼容IE6 IE7 FF常见问题 收藏 所有浏览器 通用 (市面上主要用到的IE6 IE7 FF)height: 100px; IE6 专用 _height: 100px; IE ...

  4. css gray,grayscale,css变灰兼容大部分浏览器

    css gray,grayscale,css变灰兼容大部分浏览器 html { filter: url("data:image/svg+xml;utf8,<svg xmlns=\'ht ...

  5. css线性渐变兼容

    css线性渐变兼容 background: linear-gradient(top, rgba(54, 77, 127, 0.8), rgba(54, 77, 127, 0.8)); backgrou ...

  6. oracle 在C# 中调用oracle的数据库时,出现引用库和当前客户端不兼容的问题解决方案

    oracle 在C# 中调用oracle的数据库时,出现引用库和当前客户端不兼容的问题解决方案 解决方案 1.直接引用  Oracle.ManagedDataAccess.Client.dll动态库即 ...

  7. CSS模糊效果及其兼容方法

    今天在整理IE滤镜时网站访问这里,居然找到模糊滤镜blur(),感觉太不可思议了,想不到IE居然会有这么多种滤镜效果,这基本上是模仿PS的.今天的重点是模糊滤镜 CSS模糊效果及其兼容方法 实例 兼容 ...

  8. webstorm 添加css前缀(兼容)自动添加

    Webstorm自动添加css前缀( 兼容) 百度了很多在webstorm中添加css前缀(兼容)自动添加,autoprefixer插件是首选,对于基本的css,还有less都支持,所以就选择了aut ...

  9. css - object-fit ie兼容

    css - object-fit ie兼容 参考资料 github 解决object-fit兼容IE浏览器实现图片自适应 demo <!-- * @createDate: 2022-08-30 ...

  10. 解决CSS各种IE各种兼容问题(Google解决方案)

    google的 ie7 – js中是一个JavaScript库(解决IE与W3C标准的冲突的JS库),使微软的Internet Explorer的行为像一个Web标准兼容的浏览器,支持更多的W3C标准 ...

随机推荐

  1. cp {,bak}用法(转载)

    cp filename{,bak} cp filename{,.bak} 这个命令是用来把filename备份成filename.bak的 等同于命令 cp filename filename.bak ...

  2. python Django api 返回图片

    re_path(r"report_img/(.*)$",views.ReportImage.as_view()) def return_img(request): img_dir ...

  3. 快速掌握服务网格系列二:云原生、K8S、服务网格(Service Mesh)及微服务之间的关系

    快速掌握服务网格系列二:云原生.K8S.服务网格(Service Mesh)及微服务之间的关系 首先看下CNCF对云原生的定义: Cloud native technologies empower o ...

  4. Typecho 反向代理 http 访问强制启用生成 https 链接

    问题描述 微酷是使用Nginx反向代理内网的Typecho站点,为了效率内网访问不需要使用https,这样Typecho接收到的请求是http协议的,于是网站内部资源链接被修改成了http. 解决方案 ...

  5. mac phpbrew安装

    php 编译安装php 7.2.26 aliyun 镜像中心:https://developer.aliyun.com/mirror/ 1.安装brew /usr/bin/ruby -e " ...

  6. 扎根CNCF社区贡献五年是怎样的体验?听听华为云原生开源团队的负责人怎么说

    摘要:本月我们要重点介绍王泽锋(Kevin Wang),他是 CNCF 社区的长期贡献者,华为云原生开源团队的负责人,KubeEdge 和 Volcano 项目的联合创始人.Kevin 回答了几个关于 ...

  7. 火山引擎 DataLeap 构建Data Catalog系统的实践(三):关键技术与总结

    更多技术交流.求职机会,欢迎关注字节跳动数据平台微信公众号,回复[1]进入官方交流群 关键技术 构建一个好的Data Catalog系统,需要考虑的核心产品设计和技术设计有很多.篇幅所限,本文只概要介 ...

  8. Solon2 开发之插件,三、插件体外扩展机制(E-Spi)

    插件体外扩展机制,简称:E-Spi.用于解决 fatjar 模式部署时的扩展需求.比如: 把一些"业务模块"做成插件包放到体外 把数据源配置文件放到体外,方便后续修改 其中, .p ...

  9. Spring解决泛型擦除的思路不错,现在它是我的了。

    你好呀,我是歪歪. Spring 的事件监听机制,不知道你有没有用过,实际开发过程中用来进行代码解耦简直不要太爽. 但是我最近碰到了一个涉及到泛型的场景,常规套路下,在这个场景中使用该机制看起来会很傻 ...

  10. html jquery from 表单提交 application/x-www-form-urlencoded 改成 json

    html jquery from 表单提交 $(form).ajaxSubmit  application/x-www-form-urlencoded  改成 json 要使用 jQuery 根据 n ...