Backface-visibility and 3D transforms practice


by Jeremy Caudle
notes

I've never used the backface-visibility property before and I've rarely done any 3d transformations as well. Today's a good day to give them a try.

This paragraph should be visible and display off to the side before moving.

View the code:

HTML and JS
<div class="codedoodle-block">
        <div class="card">
            <label for="checkbox">Toggle animation</label><input name="checkbox" id="checkbox" class="hide" type="checkbox" />
            <p>This paragraph should be visible and display off to the side before moving.</p>
            <label for="checkbox2">Toggle animation</label><input name="checkbox" id="checkbox2" class="hide" type="checkbox" />
            <p class="hidden">This paragraph should be hidden and display only after it has started animating.</p>

        </div>
</div>
CSS
/* Code Block styles */

	

        div.codedoodle-block {
            margin:0;
            width: auto;
            background-color: transparent;
            font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
						overflow: hidden;
        }

        .card {
            border: solid 1px #777777;
            min-height: 10em;
            max-width: 15em;
            padding: 1em;
            position: relative;
            margin: 1rem auto;
            background-color: #ffffff;
        }

        .card p {
            transition: transform 1s cubic-bezier(.68,-0.55,.27,1.55), box-shadow 1s cubic-bezier(.68,-0.55,.27,1.55), color 1.5s cubic-bezier(.68,-0.55,.27,1.55);
            transform: perspective(250px) translate3d(75%, 0, 0) rotateY(90deg);
            padding: 1rem .5rem;
            background-color: skyblue;
            margin: 1rem 0 0 0;
            box-shadow: 1rem 0 1rem rgba(0, 0, 0, 0);
            color: transparent;
        }

        .card p:first-of-type {
            backface-visibility: visible;
            -webkit-backface-visibility: visible;
        }

        .card p.hidden {
            backface-visibility: hidden;
            -webkit-backface-visibility: hidden;
            transition: transform 1s cubic-bezier(.68,-0.55,.67,1.02), box-shadow 1s cubic-bezier(.68,-0.55,.27,1.55), color 1.5s cubic-bezier(.68,-0.55,.27,1.55);
            transform: perspective(250px) translate3d(-75%, 0, 0) rotateY(-90deg);
            background-color: orange;
        }

        /* Mobile toggle */

        div.codedoodle-block label {
						text-align: center;
            display:block;
            margin: 1rem auto 1rem auto;
            background-color: #dedede;
            padding: .25rem;
            border: solid 1px rgba(0, 0, 0, 0.2);
            box-shadow: 0 .25rem .125rem rgba(0, 0, 0, 0.1);
        }

        div.codedoodle-block label:active {
            color: white;
        }

        div.codedoodle-block input {
            position: absolute;
            left: -100000px;
            margin-top: -1rem;
        }

        input[type=checkbox]:checked + p, input[type=checkbox]:checked + p.hidden {
            transform: translate3d(0,0,0) rotateY(0deg);
            box-shadow: 0 1rem 1rem rgba(0, 0, 0, 0.1);
            color: #444444;
        }

        .hide {
            height: 1px;
            width: 1px;
            /* position: absolute;
            left: -10000px; */
            display: block;
            overflow: hidden;
        }

Tags