实现方法:
1、撑开父元素高度: 设置padding(内边距)值 + 子元素高度
2、定位 position(子绝父相) + 偏移值 top + margin-top 回退 [ 需要计算,有点 麻烦 ]
3、添加与小盒子(box1)同级的span标签(兄弟元素) + 基线对齐
4、弹性盒子布局 [ 推荐 ]
5、定位 position(子绝父相) + 偏移值 top:0;bottom:0; + 外边距 margin: auto;
示例
代码实现:
<div class="box">
<div class="box1"></div>
</div>
.box{
width: 500px;
height: 300px;
background-color: aquamarine;
}
.box1{
width: 200px;
height: 100px;
background-color