dqef7931 2013-07-03 22:47
浏览 15

如何使网页上的图像适合最大宽度,而不会影响较小的图像?

I have a blog set-up for my website. Imagine there is a limited space for an article, and I want to define an area for there to be an image at the top of the articles that can never exceed a maximum width. What I have so far is basic CSS styling to define the max-width, etc. What I want to know is how can I control it so that smaller images do not get affected?

I.e. So if I have a space of 700px, images larger than 700px will get sized down but images smaller than 700px will stay the same and maybe be centered or whatever I wanted.

I looked around but couldn't find a way to word this that would yield results. If this can't be done through CSS, I also have PHP to work with if necessary.

Thanks for reading and any help!

  • 写回答

2条回答 默认 最新

  • douzi2749 2013-07-03 22:49
    关注

    Using pure CSS you can do this:

    .post img {
      width: auto;
      height: auto;
      max-width: 700px;
      max-height: 1000px;
    }
    

    Note: this is IE8+, and other latest browsers. See: http://caniuse.com/#search=max-width

    评论

报告相同问题?

悬赏问题

  • ¥15 在获取boss直聘的聊天的时候只能获取到前40条聊天数据
  • ¥20 关于URL获取的参数,无法执行二选一查询
  • ¥15 液位控制,当液位超过高限时常开触点59闭合,直到液位低于低限时,断开
  • ¥15 marlin编译错误,如何解决?
  • ¥15 有偿四位数,节约算法和扫描算法
  • ¥15 VUE项目怎么运行,系统打不开
  • ¥50 pointpillars等目标检测算法怎么融合注意力机制
  • ¥20 Vs code Mac系统 PHP Debug调试环境配置
  • ¥60 大一项目课,微信小程序
  • ¥15 求视频摘要youtube和ovp数据集