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