为何iPhone不兼容max-width: 100%?
P粉806834059
P粉806834059 2023-09-02 17:24:50
0
2
620
<p>在我的网络浏览器中,如果压缩并且在我的Android手机上,100%的工作完美。但在iPhone上不是这样。</p> <p>对于图片,我通常使用max-width: 100%;,如果情况适合,使用width: 100%;或img-responsive。图片宽度大于600px,因此我将宽度设置为600px以在较大的设备上进行控制。</p> <pre class="brush:php;toolbar:false;"><section class='section20'> <figure class="image"> <img src="images/user-content/1/20221003160546.jpg"> </figure> </section></pre> <p>CSS:</p> <pre class="brush:php;toolbar:false;">.section20 .image, .section20 img { width: 600px !important; max-width: 100% !important; }</pre> <p>添加!important或不添加都没有区别。格式化编辑器是CKEditor 5。它在处理代码中的类时非常严格。如果在代码视图中添加自定义类,当返回到格式化编辑器视图时,它将从figure中删除它。</p> <pre class="brush:php;toolbar:false;"><figure class="image"> <figure class="image my-custom-class"></pre> <p>custom-class会被删除。</p>
P粉806834059
P粉806834059

全部回复(2)
P粉145543872

不要硬编码宽度和高度。使用rem或vw/vh(推荐)。

.section20 .image,
.section20 img {
width: 35rem ; // 或者输入相应的rem值
max-width: 100vh ; 
}

表示此元素的高度等于视口高度的100%。

P粉604507867

检查你的选择器。

使用.section20 .image指定img包装器保持在600px,并且不会随max-width: 100%;而调整大小。

改用.image img

.image img {
  width: 600px;
  max-width: 100%;
}
<section class='section20'>
  <figure class="image">
    <img src="https://dummyimage.com/600x400/000/fff">
  </figure>
</section>
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责声明 Sitemap
PHP中文网:公益在线PHP培训,帮助PHP学习者快速成长!