用什么代碼實現(xiàn)?不允許有白色底色產(chǎn)生,因為手機高度不一樣
設(shè)計圖要標(biāo)準(zhǔn)(750)確認是背景圖(通屏底圖)應(yīng)用場景:移動端宣傳頁面或者活動頁面
錯誤的寫法:加到div中結(jié)合圖片設(shè)置min-height,但是頁面不會回彈
終極方案
html,body{ width:100%; height:100%}
body{ font-family: "華文細黑"; background:url("../img/Flyer-bg.png") no-repeat; background-size: 100%;}
一個hack方案解決垂直劇中問題
<head> <meta charset="utf-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width,minimum-scale=1.0"> <title>緩存</title> <script src="js/jquery-1.8.2.min.js"></script> <script src="js/store.min.js"></script> <style> .parent{ width:200px; height: 200px; /* 以下屬性垂直居中 */ position: absolute; top: 0; bottom: 0; left: 0; right: 0; margin: auto; background-color: #aaa; } </style></head><body> <div class="parent">111</div></body>
其他方案
<!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8"> <title>Document</title></head><body> <div id="Layer1" style="position:fixed; left:0px; top:0px; width:100%; height:100%"> <img src="https://www.qianbuxian.com/uploads/banners/20171214085954_shouye5.jpg" width="100%" height="100%"/> </body></html>
清除浮動
.float-left { float: left;}.float-right { float: right;}.clear-fix:after { display: table; content: ''; clear: both;}
到此這篇關(guān)于HTML5 body設(shè)置自適應(yīng)全屏的文章就介紹到這了,更多相關(guān)HTML5自適應(yīng)全屏內(nèi)容請搜索武林網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持武林網(wǎng)!
新聞熱點
疑難解答