码农知识堂 - 1000bd
  •   Python
  •   PHP
  •   JS/TS
  •   JAVA
  •   C/C++
  •   C#
  •   GO
  •   Kotlin
  •   Swift
  • 元素的层级与绝对定位布局


    目录

    一、效果展示

    二、元素层级

    1、效果

    2、特点

    3、修改

    三、绝对定位布局

    1、水平垂直布局公式(在绝对定位下必须满足)

    2、要求

    四、代码

    1、元素层级

    2、绝对定位布局


    一、效果展示

      

    二、元素层级

    1、效果

    层级高的元素会覆盖层级低的元素

    2、特点

    (1)父元素层级永远不会超过子元素大小

    (2)同层级优先显示标签靠后的元素

    3、修改

    (1)通过z-index修改层级优先级大小

    (2)z-size需要数字参数,愈大层级越高

    三、绝对定位布局

    1、水平垂直布局公式(在绝对定位下必须满足)

    (1)水平

    left + margin-left\right + padding-left\right + content + right = width

    (2)垂直

    top + margin-top\bottom + padding-top\bottom + bottom = height

    2、要求

    (1)left、right、top、bottom具有最高优先级

    (2)在过度约束条件下,若不对此四个值限定,则默认为auto,优先修改此四类值

    四、代码

    1、元素层级

    1. html>
    2. <html lang="en">
    3. <head>
    4. <meta charset="UTF-8">
    5. <meta http-equiv="X-UA-Compatible" content="IE=edge">
    6. <meta name="viewport" content="width=device-width, initial-scale=1.0">
    7. <title>元素的层级title>
    8. <style>
    9. .box1{
    10. width: 200px;
    11. height: 200px;
    12. background-color: #bfa;
    13. position: relative;
    14. z-index: 1;
    15. }
    16. .box2{
    17. width: 200px;
    18. height: 200px;
    19. background-color: red;
    20. position: absolute;
    21. left: 50px;
    22. top: 50px;
    23. z-index: 2;
    24. }
    25. .box3{
    26. width: 200px;
    27. height: 200px;
    28. background-color: yellow;
    29. position: absolute;
    30. left: 100px;
    31. top: 100px;
    32. z-index: 3;
    33. }
    34. .box4{
    35. width: 100px;
    36. height: 100px;
    37. background-color: blue;
    38. position: absolute;
    39. }
    40. style>
    41. head>
    42. <body>
    43. <div class="box1">div>
    44. <div class="box2">div>
    45. <div class="box3">
    46. <div class="box4">div>
    47. div>
    48. body>
    49. html>

    2、绝对定位布局

    1. html>
    2. <html lang="en">
    3. <head>
    4. <meta charset="UTF-8" />
    5. <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    6. <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    7. <title>绝对定位布局title>
    8. <style>
    9. .box1 {
    10. background-color: #bfa;
    11. width: 400px;
    12. height: 400px;
    13. position: relative;
    14. }
    15. .box2 {
    16. background-color: red;
    17. width: 50px;
    18. height: 50px;
    19. margin: auto;
    20. position: absolute;
    21. left: 0px;
    22. right: 0px;
    23. top: 0px;
    24. bottom: 0px;
    25. }
    26. style>
    27. head>
    28. <body>
    29. <div class="box1">
    30. <div class="box2">div>
    31. div>
    32. body>
    33. html>

  • 相关阅读:
    11.20顺序表查找,质数查找,折半查找,任意折查找
    【C++】AVL树的4中旋转调整
    使用Golang调用摄像头
    html+css+php+mysql实现注册+登录+修改密码(附完整代码)
    浅谈人工智能服务器和人工智能工作站的区别
    electron-vue使用video标签循环播放视频,解决卡顿、闪烁。
    【JavaEE初阶】多线程 _ 进阶篇 _ 锁的优化、JUC的常用类、线程安全的集合类
    【云原生】服务网格kiali开发环境搭建问题解析
    在 MySQL 和 PostgreSQL 中存储三元数据
    Spring框架(一)
  • 原文地址:https://blog.csdn.net/comegoing_xin_lv/article/details/126166846
  • 最新文章
  • 沪漂五周年了:我越来越迷茫了
    Agentic Skill Routing 实战:别再把所有 Skill 塞进 AI Agent 上下文
    MySQL-Seconds_behind_master的精度误差
    [MAF预定义ChatClient中间件-03]CachingChatClient——利用缓存省钱省时间
    AI的至暗历史:从万众期待到被政府撤资,AI的两次死亡徘徊
    Agent OS :五种驯服不确定性的范式
    PortSwigger SQL注入LAB11
    数据库即时编译JIT
    [Begin]AI Learn Data Day 0
    深度学习进阶(二十七)现代 LLM 的核心架构设计其二:SwiGLU
  • 热门文章
  • 十款代码表白小特效 一个比一个浪漫 赶紧收藏起来吧!!!
    奉劝各位学弟学妹们,该打造你的技术影响力了!
    五年了,我在 CSDN 的两个一百万。
    Java俄罗斯方块,老程序员花了一个周末,连接中学年代!
    面试官都震惊,你这网络基础可以啊!
    你真的会用百度吗?我不信 — 那些不为人知的搜索引擎语法
    心情不好的时候,用 Python 画棵樱花树送给自己吧
    通宵一晚做出来的一款类似CS的第一人称射击游戏Demo!原来做游戏也不是很难,连憨憨学妹都学会了!
    13 万字 C 语言从入门到精通保姆级教程2021 年版
    10行代码集2000张美女图,Python爬虫120例,再上征途
小工具 小游戏
Copyright © 2022 侵权请联系2656653265@qq.com    京ICP备2022015340号-1

京公网安备 11010502049817号