loading

CSS - 绝对定位让的两个元素中心重合

白蓝两个元素的原点不重合

✨技巧✨:两个元素的宽度和高度相差除以 2 得到的值分别设置其 left 和 top。

<div class="re">
  <div class="rd ab inner"></div>
  <div class="rd ab outer"></div>
</div>
<style>
.inner {
  width: 150px;
  height: 150px;
  z-index: 1;
  left: 15px;
  top: 15px;
  background-color: blue;
}

.outer {
  width: 180px;
  height: 180px;
  z-index: -1;
  background-color: aliceblue;
}
</style>

蓝白水平垂直居中

.rd {
  border-radius: 50%;
}

.ab {
  position: absolute;
}

.re {
  position: relative;
}
posted @ 2023-04-13 16:24  Himmelbleu  阅读(11)  评论(0编辑  收藏  举报