在css中,可以使用“background-size”設(shè)置banner圖自適應(yīng),語(yǔ)法“background-size:cover”;其中cover是指把背景圖像擴(kuò)展至足夠大,以使背景圖像完全覆蓋背景區(qū)域。
本教程操作環(huán)境:windows7系統(tǒng)、CSS3&&HTML5版、Dell G3電腦。
//test.css .index-banner-top { width: 100%; background: url(../imgs/guanyu.png) no-repeat center center; height: 210px; background-size:cover } @media only screen and (max-width: 640px){ .index-banner-top { height: 100px; } }
//test.html <p class="index-banner-top"></p>
電腦端顯示:
手機(jī)端顯示: