首页  >  问答  >  正文

设置了margin:0 auto;无法居中咋回事?

<!DOCTYPE html>

<html>

<head>

<meta charset ="UTF-8">

<title>1.单列等宽布局</title>

<!--样式-->

<style type="text/css">

.container{

max-width: 960px;<!--设置最大宽度为960px-->

margin:0 auto;<!--设置内部的块元素水平居中-->

}

.header{

height:50px;

background-color:#21ff80;

}

.main{

height:600px;

background-color:#80007f;

}

.footer{

height:100px;

background-color:#21ff80;

}

</style>


</head>


<body>

<h4>单列等宽布局基本思路:</h4>

<p>1.页面的头部,主体和底部全部放在一个容器中统一设置<br>

   2.容器中的子块只需要设置一下高度即可

</p>


<div>

<div>头部</div>

<div>主体</div>

<div>底部</div>

</div>



</body>





</html>


cp3cp32359 天前1584

全部回复(2)我来回复

  • cp3

    cp32018-05-04 16:15:58

    好了解决了,注释出了问题,用的Notepad++写的,直接用快捷键注释,没注意看。

    回复
    0
  • oswell

    oswell2018-05-04 16:09:30

    你只写了样式,但是并没有使用样式

    回复
    0
  • 取消回复