使用css 实现图片自适应大小

在编写网页时,如果图片大小事先是未知的,如果图片过大的话,会影响的网页中其他块的结构

使用css可以将图片的大小调整到一个固定的值

#mian img{
  max-width : 170px ;
  width : 170px ;
  width :expression(document.body.clientWidth> 170 ? "170px" : "auto" );
  max-height : 180px ;
  height : 180px ;
  height :expression(document.body.clientWidth> 180 ? "180px" : "auto" );
  overflow : hidden ;
}

 在如下html代码中

< div id = "maim">
<!--
在mian样式的块中img标签图片的大小会被固定在170px*180px
-->
< img src="01.jpg">
</ div >

 如果图片的大小是事先未知的,这样设置可以使,图像的大小固定,从而不影响网页中其他块的结构

猜你喜欢

转载自570109268.iteye.com/blog/2394291