/ 博客 / 2077浏览

让图片自适应手机宽度

临睡前把iPhone充了电实验了一下在iOS的Safari中看travel.synyan.net的效果,发现图片撑破了主题,而字体过小,拥挤在左侧,绝壁给常用手机阅读鄙人博客的童鞋带来了不便。怎么解决呢,方法挺简单,找到子主题style.css中的img样式定义,然后加上max-width: 100%;height:auto;。比如Colorlib主题的CSS是这样的:

.entry-content img, .comment-content img, .widget img, img.header-image, .author-avatar img, img.wp-post-image{
    max-width: 100%;
    height:auto;
}

不过据说IE不能正常解析max-width,回头有Windows Phone的童鞋帮我看一下。

10

  1. Bigman

    兼容各种浏览器真是不容易
    不是号称国内还有很多用户还是IE6

    Firefox 30 · Windows 7
    1. S

      @Bigman嗯IE6用户只能任其自生自灭了……

      Opera 22 · Windows 7
  2. Betty

    那你手机看我模板还自适应吗?

    Google Chrome 26 · Windows XP
    1. S

      @Betty适应的。

      Opera 22 · Windows 7
  3. 大肥羊

    自适应体验挺好的。

    Firefox 30 · Windows 7
    1. S

      @大肥羊嗯,希望大家都能用上。 🙂

      Opera 22 · Windows 7
  4. Ryu

    新主题很喜欢! 🙂

    Firefox 30 · Windows XP
    1. S

      @Ryu嗯,花了半个晚上没白费 :mrgreen:

      Opera 22 · Windows 7
  5. 章鱼哥

    但是你这个有个问题,图片不能等比例缩放,图片会变形。

    Google Chrome 31 · Windows 7
    1. S

      @章鱼哥.wp-caption img {
      display: block;
      margin: -2px 0 0 -2px;
      max-width: 98%;
      height:auto;
      }

      Chromium 37 · Ubuntu

回复 S 取消回复

您的电子邮箱地址不会被公开。 必填项已用*标注