中心DIV不工作

时间:2016-09-19 04:46:43

标签: html css center

我试图简单地将div放在另一个div中。 我在另一篇文章中读到,只要我试图居中的div的宽度小于容器宽度,并设置了margin: 0 auto;,它应该居中,而不是我的代码的情况。我需要帮助

我的容器

#main {
    width: 1200px;
    height: 800px;
    margin: 0 auto;
    border-radius: 6px;
}

div我试图集中在我的容器内

#tablesection { 
    width: 600px;
    margin: 0 auto; 
    text-align: center;
}

3 个答案:

答案 0 :(得分:0)

#outer{
   background-color: #000;
   float: left;
   height: 200px;
   width: 100%;
   }
#centerDiv{
   background-color: #fff;
   height: 150px;
   margin: auto;
   width: 70%;
}

检查此demo

答案 1 :(得分:-1)

对不起家伙BIG菜鸟的错误......在我的风格部分有另一个css声明,其中一个关闭括号丢失导致所有这些。 它是一个支架可以导致所有随机行为的疯狂

所以代码在FACT工作。感谢帮助人们知道这样的整个社区来帮助像我这样的新手感觉很好

答案 2 :(得分:-1)

#main {
width:1200px;
height:800px;
margin: 0 auto;
border-radius: 6px;
background:red;
}
 #tablesection { 
   width:600px; 
   border:1px solid;
   margin:0 auto;
   background:green;
}

其工作

相关问题