我想要得到的是以下图像。
有两个div。内部div位于外部div的中心,文本box1
位于内部div的中心。
CSS代码无法达到目标。
div.father {
align-items: center;
border: 1px solid black;
display: flex;
height: 300px;
justify-content: center;
left: 50%;
position: absolute;
top: 50%;
transform: translate(-50%, -50%);
width: 300px;
}
div.son {
border: 1px solid black;
height: 100px;
width: 100px;
}
<div class="father">
<div class="son">box1</div>
</div>
如何将box1
div放在div.son的中心?
您可以使用弹性盒。这是我的小提琴。
div.father {
border: 1px solid black;
align-items: center;
justify-content: center;
display: flex;
height: 300px;
width: 300px;
left: 50%;
position: absolute;
top: 50%;
transform: translate(-50%, -50%);
/**/
margin-top: 100px;/*only for snippet spacing*/
}
div.son {
border: 1px solid black;
height: 100px;
width: 100px;
align-items: center;
justify-content: center;
display: flex;
}
<div class="father">
<div class="son">box1</div>
</div>
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句