Hovered element to overflow out from an overflow:hidden element css

后端 未结 7 2348
陌清茗
陌清茗 2021-02-13 12:55

I have made a fiddle for reference: http://jsfiddle.net/kLFn9/

The overflow:hidden in question is highlighted.

Basically, i\'m using :hover:af

7条回答
  •  无人及你
    2021-02-13 13:56

    You can use margin-top and padding-top.

    padding-top will extend your parent area, but a negative margin-top will keep it in the expected position.

    It will look like you're escaping the overflow, but in fact you're not.

    div {
        width:500px;
        height:200px;
        background:red;
        margin: 50px;
        overflow: hidden; /* this rule */
    
        background-clip: content-box; /*use this to constrain the background color within the content-box and do not paint the padding */
        padding-top: 200px; /* space required to display the tooltip */
        margin-top: -150px; /*200px - 50px of the original margin*/
    }
        
    span {
     background: blue;
     color: white;
     position: relative;
     top:100px;  
     display:block;   
     width: 100px;  
     margin: auto;    
    }
        
    span:hover:after {
        content: attr(data-name); 
        color: black;
        position: absolute;
        top: -150px;;
        left: 0;   
    }
    hover

    This may introduce pointer events problems, but you can fix them using pointer-events then.

提交回复
热议问题