正反兩面不同圖片

* {
            margin: 0;
            padding: 0;
        }
        .parent {
            height: 400px;
            margin:50px auto;
            background-color: #ccc;
        }
        .son {
            width: 300px;
            height: 300px;
            position: relative;
            transform-style: preserve-3d;
            transition: all 1s;
            margin: 0 auto;
        }
        .son::after,.son::before {
            content: "";
            position: absolute;
            left: 0;
            top: 0;
            display: block;
            width: 100%;
            height: 100%;
            background: url(./images/bg.png);
        }
        .son::before {/*這里將before放在背面*/
            background-position: right top;
            /*提前將前面的圖片旋轉(zhuǎn)到背面*/
            transform: rotateY(180deg);
        }
        .son::after {
            background-position: left top;
            /*將背面的圖片不能看到背面和看到是一樣的*/
            backface-visibility: visible;
        }
        .son:hover {
            /*此時(shí)整個(gè)容器旋轉(zhuǎn)180,剛好將之前旋轉(zhuǎn)的180抵消,所以看到的是正面而不是鏡像*/
            transform: rotateY(180deg);
        }
<div class="parent">
        <div class="son"></div>
    </div>
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

推薦閱讀更多精彩內(nèi)容