Flipping Book Animation
HTML CODE:-
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1"> <title></title> </head> <body> <div class="container"> <input type="checkbox" id="c1"> <input type="checkbox" id="c2"> <div class="page1"> <img src="https://yt3.ggpht.com/qxJL8DD-4bLtnFRhshGyrq-Al4YWFd1bfvh2Qsco64w-MaiDmIqAv8TI5jvyPwqakHKRZth1oXyR7g=s800-c-fcrop64=1,0000198effffe65a-nd-v1"> </div> <div class="book"> <div class="flip" id="b1"> <div class="back"> <img src="https://yt3.ggpht.com/FXQhqjBiVsYmut8vCkn4OzKPCqhV5Iy91jOJhxzrPowLYSvQOHYnx-FsNPCobeX-uHBSTbDDHOUx=s800-c-fcrop64=1,00001999ffffe666-nd-v1" alt=""> <label for="c1" class="back-btn">Before</label> </div> <div class="front"> <img src="https://yt3.ggpht.com/kIh1YrYQtw7FQY-29eG-nr1MfzKQptTwrisycPIEzqUReC-Au1fAKR_3c7adcgZHzu_gZxi8gzH02w=s800-c-fcrop64=1,00001999ffffe666-nd-v1" alt=""> <label for="c1" class="next-btn">Next</label> </div> </div> <div class="flip" id="b2"> <div class="back"> <img src="https://yt3.ggpht.com/s3OWsOYQOD6Y-6jpCLNF_hs3HCLc-zUTL90XdEULUaYS1h0Vp48Y1SzNDTbJlQdvTFVhFZKld7iQ=s800-c-fcrop64=1,00001999ffffe666-nd-v1" alt=""> <label for="c2" class="back-btn">Before</label> </div> <div class="front"> <img src="https://yt3.ggpht.com/RJ9mUa5o28BWZrIyAfmZxXFeRfo_a--e7JlK2dSpAOWsc2MiWtl3Mfvy6ZoWxpmlsWU7usIstf5en30=s800-c-fcrop64=1,00001999ffffe666-nd-v1"> <label for="c2" class="next-btn">Next</label> </div> </div> </div> </div> </body> </html> |
CSS CODE:-
body{ padding: 0px; margin: 0px; box-sizing: border-box; display: flex; align-items: center; justify-content: center; background-color: black; min-height: 100vh; } img{ width: 100%; height: 100%; } input{ display: none; } .container{ display: flex; } .page1{ width: 250px; height: 300px; } .book{ width: 250px; height: 300px; position: relative; perspective: 1500px; } .flip{ position: absolute; top: 0; left: 0; width: 100%; height: 100%; transform: rotateY(0deg); transform-style: preserve-3d; transform-origin: left; transition: .5s; } .front{ position: absolute; top: 0; left: 0; width: 100%; height: 100%; box-sizing: border-box; padding-left: 2px; } .back{ position: absolute; top: 0; left: 0; width: 100%; height: 100%; z-index: 99; transform: rotateY(180deg); backface-visibility: hidden; } .next-btn,.back-btn{ position: absolute; bottom: 15px; right: 15px; cursor: pointer; color: black; background: white; padding: 2px 8px; border: 2px solid black; } #b1{ z-index: 2; } #b2{ z-index: 1; } #c1:checked ~ .book #b1{ transform: rotateY(-180deg); z-index: 1; } #c2:checked ~ .book #b2{ transform: rotateY(-180deg); z-index: 2; } |