01
margin:0px;
background: url(images/bg.png) no-repeat;
background-size:100% 100%;
background-attachment:fixed;
url(images/beijing.png)——圖片路徑的位置;
no-repeat—— 圖片不重復(fù);
center 0px——center是距離頁面左邊的定位,0px是距離頁面上面的定位;
background-position: center 0——就是圖片的定位,同上;
background-size: cover;——把背景圖像擴(kuò)展至足夠大,以使背景圖像完全覆蓋背景區(qū)域。背景圖像的某些部分也許無法顯示在背景定位區(qū)域中;
min-height: 100vh;——視窗的高度,“視區(qū)”所指為瀏覽器內(nèi)部的可視區(qū)域大小,即window.innerWidth/ window.innerHeight大小。
02
background: url("bg.png") no-repeat;
height:100%;
width:100%;
overflow: hidden;
background-size:cover;//或者background-size:100%;
03
給body標(biāo)簽指定背景圖,這樣背景圖就可以填充整個瀏覽器viewport了。其實,該方案對所有的塊級容器都可以生效。塊級容器的寬高是動態(tài)的,那么背景圖將自動伸縮,充滿整個容器。文章來源:http://www.zghlxwxcb.cn/news/detail-667707.html
css body標(biāo)簽的樣式如下:文章來源地址http://www.zghlxwxcb.cn/news/detail-667707.html
body {
/* 加載背景圖 */
background-image: url(images/bg.jpg);
/* 背景圖垂直、水平均居中 */
background-position: center center;
/* 背景圖不平鋪 */
background-repeat: no-repeat;
/* 當(dāng)內(nèi)容高度大于圖片高度時,背景圖像的位置相對于viewport固定 */
background-attachment: fixed;
/* 讓背景圖基于容器大小伸縮 */
background-size: cover;
/* 設(shè)置背景顏色,背景圖加載過程中會顯示背景色 */
background-color: #464646;
}
到了這里,關(guān)于3種CSS實現(xiàn)背景圖片全屏鋪滿自適應(yīng)的方式的文章就介紹完了。如果您還想了解更多內(nèi)容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!