【问题标题】:What is the different between parent: relative child: absolute with child:relative? [duplicate]父母:相对孩子:绝对与孩子:相对有什么区别? [复制]
【发布时间】:2021-12-13 05:36:52
【问题描述】:

我知道如果我使用孩子的位置作为相对位置,我可以将孩子的位置移动到父母身上。像这样:

#child{
  position: relative;
  left: 30px;  }

有时我看到父母的位置是相对的,而孩子的位置是绝对的。像这样。

 #parent{
  position: relative;

  }
 #child{
  position: absolute;
  left: 30px;
  }

但这两者有什么不同呢?

【问题讨论】:

    标签: html css position css-position


    【解决方案1】:

    两者都相对于最近的定位祖先定位。

    不同之处在于,position: absolute 的子级从正常流程中移除。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-01-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-11-14
      • 1970-01-01
      相关资源
      最近更新 更多