[英]Place multiple HTML elements hovering over each other in center of a parent element using CSS and mostly relative properties?
I need this markup to then use in an animation. 我需要此标记才能在动画中使用。 This animation should use relative values almost anywhere to scale without breaking and look similar anywhere.
该动画应该在几乎任何地方都可以使用相对值来缩放而不破裂,并且在任何地方看起来都相似。
display: flex
and its aligns and justifies work wrong in my situation, so I went here to ask. display: flex
及其对齐方式并证明在我的情况下工作有误,因此我去这里询问。
This is my markup: 这是我的标记:
.a-parent { height: 100px; width: 100px; border-radius: 50%; background-color: #f0f0f0; } .a-child { height: 10%; width: 10%; background-color: #0099ff; border-radius: 50%; }
<div class="a-parent"> <div class="a-child"></div> <div class="a-child"></div> <div class="a-child"></div> <div class="a-child"></div> <div class="a-child"></div> </div>
How could I center all 5 a-child
elements over each other to make it look like this? 我如何才能使所有5
a-child
元素相互居中以使其看起来像这样?
EDIT: fixed my html, sorry. 编辑:修复我的html,对不起。
Use position relative on the .a-parent
and absolute on a-child
and align children horizontally and vertically center in the parent. 在
.a-parent
上使用相对位置,在a-child
上a-child
绝对位置,并将孩子在父级中水平和垂直居中对齐。
.a-parent { height: 100px; width: 100px; border-radius: 50%; position: relative; background-color: #aaaaaa; } .a-child { height: 10%; width: 10%; background-color: #0099ff; border-radius: 50%; position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%); }
<div class="a-parent"> <div class="a-child"></div> <div class="a-child"></div> <div class="a-child"></div> <div class="a-child"></div> <div class="a-child"></div> </div>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.