H5端关于img居中的一个兼容性bug
2023-06-13 09:14:09 时间
代码已上传至github github代码地址:https://github.com/Miofly/mio.git
最近写原生H5项目,让图片居中时,有时候会有flex布局或者position定位,使其居中,偶尔还会使用margin或者padding进行微调,此写法在大部分手机端以及开发者工具上面都是正常。很意外的是在一些手机上总是不适配。
以下是解决方法
多个img标签需要居中,最好在img外层包装一个div
示例如下
使用position:absolute,left设为0,宽度设为100%,再加上text-align:center完美居中
<div v-show="true" style="position: relative;">
<img style="z-index: 1;" :src="gy" class="full-width-height">
<div style="z-index: 3;position: absolute;top: 1.81rem;left: 0;width: 100%;text-align: center;">
<img style="width: 2.06rem;height: 2.07rem" :src="yuanpan">
</div>
<div style="z-index: 5;position: absolute;top: 1.24rem;left: 0;width: 100%;text-align: center;">
<img class="xuanzhun" style="width: 3.16rem;height: 3.2rem" :src="guang">
</div>
<div style="z-index: 7;position: absolute;top: 2.29rem;text-align: center;left: 0;width: 100%">
<img style="width: 2.87rem;height: 4.15rem;" :src="guanyin">
</div>
</div>
以前给img标签居中,我基本都是直接使用flex布局或者一些其他方法,直接在img标签上给img进行居中,但这种方法存在太多问题,特此警戒
相关文章
- 串口调试助手(CM野人版)4.0有严重Bug,已经跟作者反应,等候更新
- 记一次bug分析过程,并随之引发的思考
- “土法”排查与修复一个 Linux 内核 Bug
- 1个Python 的小 Bug,干倒了估值 1.6 亿美元的公司
- 聊聊苹果的Bug - iOS 10 nano_free Crash
- 【Vue-Spring跨域Bug已解决】has been blocked by CORS policy: The value of the······
- spring jdbctemplate 启动报错(oracle驱动bug)详解数据库
- #Bug何其多#一个macOS Catalina的新bug可能会删掉你的电子邮件
- Oracle Bug之谜(oracle的bug)
- 一个可对显示器造成物理伤害的 Xfce Bug
- 调试mysql Bug,高效管理你的数据库(bug管理mysql)
- 解决IE下select标签innerHTML插入option的BUG(兼容IE,FF,Opera,Chrome,Safari)
- jsTree基于JQuery的排序节点Bug