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

后端 未结 7 2361
陌清茗
陌清茗 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:32

    Unfortunately, there's no (easy) way to allow a child tag to override the effects of the overflow:hidden declaration on the parent div. See: Allow specific tag to override overflow:hidden

    Your only possible recourse would be with javascript: first grab the span's offset relative to the document, then move it to another location in the DOM (i.e. direct child to the body), set its position to absolute, and use the offsets you grabbed to set its left and top properties, that would locate it at the same position within the document, but now it's not contained by the div, and so no longer needs to obey overflow:hidden.

    0 讨论(0)
  • 2021-02-13 13:43

    You can set child's position to fixed.

    0 讨论(0)
  • 2021-02-13 13:48

    In some cases you can escape with div{position: absolute;}

    0 讨论(0)
  • 2021-02-13 13:51

    I'm not sure what your trying to get at, but I recreated a tooltip framework for you to view. It's basically smoke and mirrors where I call :hover and the .class associated with it.

    http://jsfiddle.net/WE8Dw/

    Hope this helps.

    0 讨论(0)
  • 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;   
    }
    <div>
    <span data-name="here">hover</span>
    </div>

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

    0 讨论(0)
  • 2021-02-13 13:57

    I am using simple z-index for force the element hovered to escape the parent element. Please check

    div {
     width:500px;
    height:200px;
     background:red;   
        margin: 50px;
        overflow: hidden; /* this rule */
    }
    
    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: fixed; /* Here I replaced position abosolute to fixed */
    top: 10px;  /* Here I replaced top -150px  to 10px */
     left: 250px;  /* Here I replaced positionleft 0 to 250px */
     z-index:99999;} /* Here I added new z-index property to 99999 */
    <div>
    <span data-name="here">hover</span>
    </div>

    0 讨论(0)
提交回复
热议问题