keyi

 

设置div中的div居中显示

方法一、

 

<div class=\'big\'>
    
    <div class=\'small\'>box1</div>
 
 </div>

style样式:
.big{
  height:200px;
  width:200px;
  border:black solid 1px;
  position:absolute;
  left:150px;
  

}
.small{
  height:100px;
  width:100px;
  background-color:green;
  position:relative;
  left:100px;
  top:100px;
  margin-top:-50px;
  margin-left:-50px;
  border:black solid 1px;
}

方法二、

 

div class=\'big2\'>
    
    <div class=\'small2\'>box3</div>
 
 </div>


.big2{
  height:200px;
  width:200px;
  border:black solid 1px;
  text-align:center;

}
.small2{
  height:100px;
  width:100px;
  background-color:green;
  margin:50px auto; //外面的div高度的一半
  border:black solid 1px;
}

 

posted on 2016-10-13 13:12  路修远而求索  阅读(65110)  评论(0编辑  收藏  举报

分类:

技术点:

相关文章:

  • 2021-12-20
  • 2022-02-03
  • 2021-12-23
  • 2021-12-01
  • 2021-11-12
  • 2022-12-23
  • 2022-12-23
  • 2021-11-21
猜你喜欢
  • 2022-12-23
  • 2021-10-26
  • 2021-07-06
  • 2021-11-21
  • 2021-12-01
  • 2022-12-23
  • 2021-12-02
相关资源
相似解决方案