为何iPhone不兼容max-width: 100%?
P粉806834059
P粉806834059 2023-09-02 17:24:50
[CSS3讨论组]
<p>在我的网络浏览器中,如果压缩并且在我的Android手机上,100%的工作完美。但在iPhone上不是这样。</p> <p>对于图片,我通常使用max-width: 100%;,如果情况适合,使用width: 100%;或img-responsive。图片宽度大于600px,因此我将宽度设置为600px以在较大的设备上进行控制。</p> <pre class="brush:php;toolbar:false;">&lt;section class='section20'&gt; &lt;figure class=&quot;image&quot;&gt; &lt;img src=&quot;images/user-content/1/20221003160546.jpg&quot;&gt; &lt;/figure&gt; &lt;/section&gt;</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;">&lt;figure class=&quot;image&quot;&gt; &lt;figure class=&quot;image my-custom-class&quot;&gt;</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>
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 意见反馈 讲师合作 广告合作 最新更新
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习
PHP中文网抖音号
发现有趣的

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号