欢迎来到DIVCSS5查找CSS资料与学习DIV CSS布局技术!
响应式图像
 
<img src="..." class="img-responsive" alt="响应式图像">
通过添加 img-responsive class 可以让 Bootstrap 3 中的图像对响应式布局的支持更友好。
 
接下来让我们看下这个 class 包含了哪些 css 属性。
 
在下面的代码中,可以看到img-responsive class 为图像赋予了 max-width: 100%; 和 height: auto; 属性,可以让图像按比例缩放,不超过其父元素的尺寸。
 
.img-responsive {
  display: block;
  height: auto;
  max-width: 100%;
}
这表明相关的图像呈现为 block。当您把元素的 display 属性设置为 block,以块级元素显示。
 
设置 height:auto,相关元素的高度取决于浏览器。
 
设置 max-width 为 100% 会重写任何通过 width 属性指定的宽度。这让图片对响应式布局的支持更友好。
 
如果需要让使用了 .img-responsive 类的图片水平居中,请使用 .center-block 类,不要用 .text-center。

如需转载,请注明文章出处和来源网址:http://www.divcss5.com/html/h65089.shtml