定位布局-学习笔记

111 阅读1分钟


深入定位

  • “position: absolute”会将元素转换为块元素。
  • 实现子元素相对于父元素来定位:
  • 绝对定位元素是相对于外层第一个设置了“position: relative”;“position: absolute”或“position: fixed”的祖先元素来进行定位的。

 语法:


    父元素{ position: relative }
    子元素
    {
        position: absolute;
        /*定义top、bottom、left和right*/
    }

🌰栗子:


z-index属性

  • z-index属性只有在元素定义“position: relative” “position: absolute”或者 “position: fixed”时才会被激活。当然,对于“position: fixed”的z-index也
    没什么值得去管,可忽略。