没什么好听名字 2023-03-07 11:24 采纳率: 68.4%
浏览 42

孙元素被爷元素隐藏问题

孙(C)元素被爷(A)元素隐藏问题。

我定义C元素为绝对布局,B元素为相对布局,然后会被A元素隐藏,在不改变A元素的 overflow和position的情况下 有没有办法让C元素不被A隐藏,当然把C元素放到A元素外面就可以,但是C又要相对于B来定位。

img

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />

    <title>Document</title>
    <style>
        body,
        html {
            height: 100vh;
            padding: 0;
            margin: 0;
        }
        .a{
            /*在实际项目中。overflow和position 无法改变 */
            overflow: hidden;
            position: relative;
            width: 130px;
            background-color: burlywood;
        }
        .b{
            
            width:100px;
            height:100px;
            position: relative;
            background-color: antiquewhite;
        }
        .c{
            position:absolute;
            width: 100px;
            height: 20px;
            background-color: blue;
            color:white;
            left:50px;
            top:0;
            padding:10px;
            /* z-index: 9999; */
        }
    </style>
</head>


<div class="a">
    A
    <div class="b">
        B
        <div class="c">CCCCCCCCCCCCCCCCCC</div>
    </div>
</div>

</body>

</html>

  • 写回答

2条回答 默认 最新

  • 文盲老顾 新星创作者: 信息安全技术领域 2023-03-07 11:57
    关注

    设置下z-index样式,这个是层深,遮挡问题一般都是这个属性解决

    评论

报告相同问题?

问题事件

  • 修改了问题 3月7日
  • 修改了问题 3月7日
  • 创建了问题 3月7日