如何将div放在另一个div中?

时间:2016-02-10 12:36:25

标签: html css center

div1 位于屏幕中央,我想在 div1

的中心 div2
<div id="div1">
       <div id="div2"></div> 
    </div>

的CSS:

 #div1{ 
     top:0;
     left:0;
     right:0;
     bottom:0;
     margin:auto;
     position:fixed;
     width:595px;
     height:842px;
     background-color:#F0F0F0;
 }

#div2{

}

1 个答案:

答案 0 :(得分:0)

<style>
#div1{ 
 top:0;
 left:0;
 right:0;
 bottom:0;
 margin:auto;
 position:fixed;
 width:595px;
 height:842px;
 display:table;
 }

#div2{
display:table-cell;
vertical-align: middle;
margin:auto; 
background-color:red;
position:relative;
}

</style>
<div id="div1">
   <div id="div2">content</div> 
</div>

js fiddle here http://www.broadleafcommerce.com/docs/core/current/appendix/removing-thymeleaf