css 怎样让图片居中缩放

html-css011

css 怎样让图片居中缩放,第1张

//把图片当作背景,可以使用background-size属性,background-position属性。例子

.bg {

    background: url( "http://www.hqyt.net/upload/2016/09/13/147375594449qmms8.jpg" ) center center no-repeat scroll

    background-size: cover

    min-height: 300px

}

<div class="bg"></div>

效果演示:源代码:.box { /*非IE的主流浏览器识别的垂直居中的方法*/ display: table-cellvertical-align:middle/*设置水平居中*/ text-align:center/* 针对IE的Hack */ *display: block*font-size: 175px/*约为高度的0.873,200*0.873 约为175*/ *font-family:Arial/*防止非utf-8引起的hack失效问题,如gbk编码*/ width:200pxheight:200pxborder: 1px solid #eee} .box img { /*设置图片垂直居中*/ vertical-align:middle/*非IE6下的等比缩放*/ max-height:150pxmax-width:150px/*IE6下的等比缩放,注意expression其实是运行了一个JS程序,所以如果图片很多的话会引起CPU占用率高*/ width:expression(this.width >150 &&this.height <= this.width ?