代码之家  ›  专栏  ›  技术社区  ›  agis

根据特定分辨率更改图像高度

  •  1
  • agis  · 技术社区  · 12 年前

    我正在使用Twitter Bootstrap,我有一组包含一些图像的列。

    当用户在480px以下观看图像时,我希望更改图像的高度,而不丢失其纵横比。

    以下是标记:

     <div class="container-fluid">
       <div class="row">
       <div class="project no-padding col-xs-12">
    
          <a href="#">
              <figure>
                <img class="img-responsive" src="image.jpg">
              </figure>
    
          </a>
    
       </div>
       </div>
       ...
    

    我尝试过使用这个CSS:

    @media (max-width: @screen-xs-min) {
    
    .project img { height:200px;}
    
    }
    

    这样做的问题是,将图像拉伸到那个高度,看起来一点都不好看。

    有什么变通方法可以用CSS实现这一点吗?如果没有,有任何JS插件可以帮助我做到这一点吗?

    1 回复  |  直到 12 年前
        1
  •  0
  •   Aroll605    12 年前

    你有没有试过“.image responsible”这门课?

    <img src="..." class="img-responsive" alt="Responsive image">
    

    从…起 http://getbootstrap.com/css/#images