Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does setting overflow:hidden; break the backface-visibility declaration?

I have a "flippable" modal dialogue consisting of two divs (front and back):

<div class="modal-dialogue">
    <div class="modal-content">
        <div class="front">
             <h1>Front</h1>
        </div>
        <div class="back">
             <h1>Back</h1>
        </div>
    </div>
</div>

Using CSS transform I flip the modal over to reveal the back by adding the "flipped" class to the modal-content with:

.modal-content.flipped {
    -webkit-transform: rotateY(180deg);
}

This all works fine... except when I add the overflow:hidden; property to the modal-content. Suddenly, the back div is not visible and instead the backface of the front div becomes visible (even though it has backface-visibility set to hidden).

This seems very strange. Why would setting the overflow property change the backface-visibility in this way?

You can see it in action in this fiddle: https://jsfiddle.net/amxp02mx/ . It works fine, but if you comment out line 31 in the CSS, making the overflow:hidden, it is broken.

Can anyone explain why?

like image 214
Rich Avatar asked Sep 02 '15 11:09

Rich


1 Answers

document.querySelector(".modal-content")
    .addEventListener("click", function () {
    this.classList.toggle("flipped");
});
    .modal-dialogue {
        z-index: 1050;
        display: block;
        width: 25rem;
        min-height: 30rem;
        margin-left: -12.5rem;
        margin-top: -15rem;
        position: fixed;
        left: 50%;
        top: 50%;
        -webkit-perspective: 800px;
    }
    .modal-content {
        width: 25rem;
        min-height: 30rem;
        position: relative;
        background-color: transparent;
        border-radius: 10px;
        outline: none;
        transition: 0.8s ease;
        -webkit-transform-style: preserve-3d;
        -webkit-transition: -webkit-transform 1s;
        margin: 5rem auto 0 auto;
        
        /* With overflow:hidden; the back of the panel is 
        not visible and the backface-visibility:hidden 
        stops working. Why? */
        overflow: hidden;
        
        /* With overflow: visible; it works fine. */
        overflow: inherit;
    }
    .modal-content div {
        display: block;
        position: absolute;
        width: 100%;
        height: 100%;
        -webkit-backface-visibility: hidden;
        color: white;
        font-size: 140px;
        font-weight: bold;
        text-align: center;        
        overflow: hidden;
    }
    .modal-content .front {
        background: red;
        z-index:0;
    }
    .modal-content .back {
        background: blue;
        -webkit-transform: rotateY(180deg);
        z-index:-1;
    }
    .modal-content.flipped {
        -webkit-transform: rotateY(180deg);
    }
<div class="modal-dialogue">
    <div class="modal-content">
        <div class="front">
             <h1>Front</h1>

        </div>
        <div class="back">
             <h1>Back</h1>

        </div>
    </div>
</div>

you can see the explanation here in the documentation: https://drafts.csswg.org/css-transforms/#grouping-property-values

also your issue is easily fixed by adding

overflow:hidden;

to the .modal-content div rule

https://jsfiddle.net/amxp02mx/4/

like image 87
Victor Radu Avatar answered Oct 13 '22 22:10

Victor Radu