HTML設置頁面居中的五種方式


<!DOCTYPE html>

<html>

<head>

<meta charset="utf-8">

<title>頁面居中的幾種寫法</title>

<style type="text/css">

*{margin: 0px; padding: 0px;}

#info{width:80%; height: 800px; background-color: pink;}

/* 第1種:*/

#info{margin: 0px auto;}

/* 第2種:內邊距,后面的width和overflow必須寫*/

body{

padding: 0 10%;

width: 100%;

overflow: hidden;

}

/* 第3種:absolute和relative都可以 */

#info{

position: absolute;

left: 10%;

}

/* 第4種:行內塊級*/

body{

text-align: center;

}

#info{

display: inline-block;

}

第5種:彈性盒子的主軸對齊*/

/*body{

display:flex;

    justify-content:center;

}

</style>

</head>

<body>

<div id="info"></div>

</body>

</html>

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM