How we can create a flipping profile card using HTML CSS JS? Solution: See this Card Flip Animation Using CSS and jQuery, Flipping Profile Cards.
Previously I have shared some cards related programs, but this is a profile card with a flip animation. Basically, A card is a small rectangular or rounded-rectangular module with images and text. It is an entry point for users to learn more details by clicking the link. And a profile card contains simply an image, name, small description, and other sections like skills, age, etc. When a card completely rotates and shows their backside, then its called flip effect.
Today you will learn to create flipping profile cards. Basically, there are 3 cards and each card contains an image in the whole box and title, description at the bottom side of the card. First, you will see only the image, but when you will hover on it then the title and des will appear. And when you will click on the card, then it will flip to the backside and show the image in circle and cover, and some other texts. There I have used dog profiles, so there are available names & breeds on the front side, and age, weight, and color on the backside.
So, Today I am sharing Card Flip Animation Using CSS and jQuery. There I have used HTML to create the layout, CSS for styling, and jQuery for flip function in this program. This program can be used for showing testimonial or employee profiles with their details. You can use this flip card program on your website as anything you want to show.
If you are thinking now how this flipping card actually is, then see the preview given below.
Preview Of Flipping Profile Cards
See this video preview to getting an idea of how these profile cards look like.
Now you can see this program visually, also you can see it live by pressing the button given above. If you like this, then get the source code of its.
You May Also Like:
Card Flip Animation Using CSS and jQuery Source Code
Before sharing source code, let’s talk about it. First I have created the main div named container and placed all elements inside it. Inside the container div, I have placed 3 divs sections for 3 cards. Each card div section contains many div, list, and other tags like a hyperlink. Inside a single card, there is a title, description, image in the front side and 2 images profile and cover, texts in the backside. Also in the HTML file, I have linked other files like CSS, JS, and jQuery CDN.
Now using CSS I have placed all the items in the right place, as you can see in the preview. With CSS first I gave basic values like size, position, margin, padding, etc to the elements. There I have used flex display to create the layout, and used other flex commands. To create a 3D effect while flipping I used transform-style: preserve-3d; command. I have used @keyframe command to create some animations and @media query for responsive design.
jQuery handling here the flip toggle effect in this program. There I have used JS if{} else{} statements to declare functions, and it adding and removing class names according to user’s action. Left all other things you will understand after getting the codes, I can’t explain all in here in writing. For creating this program you have to create 3 files. First file for HTML, second for CSS, and the third file for JavaScript.
Follow the steps to creating this program without any error.
index.html
Create an HTML file named ‘index.html‘ and put these codes given below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
<!DOCTYPE html> <!--Code By Webdevtrick ( https://webdevtrick.com )--> <html lang="en" > <head> <meta charset="UTF-8"> <title>Card Flip Animation | Webdevtrick.com</title> <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/normalize/5.0.0/normalize.min.css"> <link rel="stylesheet" href="./style.css"> </head> <body> <div class="container"> <div class="card"> <div class="card-1 card-object card-object-hf"><a class="face front" href="#"> <div class="titleS"> <div class="title">Rocky</div> <div class="subtitle">Alaskan Husky</div> </div></a><a class="face back" href="#"> <div class="img-wrapper"> <div class="avatar"></div> </div> <div class="infoS"> <div class="info-title">Rocky</div> <ul class="info-content"> <li class="info-content-item">Age <span>6 years</span></li> <li class="info-content-item">Color <span>White</span></li> <li class="info-content-item">Weight <span>34kg</span></li> </ul> </div></a></div> </div> <div class="card"> <div class="card-2 card-object card-object-hf"><a class="face front" href="#"> <div class="titleS"> <div class="title">Tommy</div> <div class="subtitle">American Pitbull</div> </div></a><a class="face back" href="#"> <div class="img-wrapper"> <div class="avatar"></div> </div> <div class="infoS"> <div class="info-title">Tommy</div> <ul class="info-content"> <li class="info-content-item">Age <span>4 years</span></li> <li class="info-content-item">Color <span>Gray</span></li> <li class="info-content-item">Weight <span>28kg</span></li> </ul> </div></a></div> </div> <div class="card"> <div class="card-3 card-object card-object-hf"><a class="face front" href="#"> <div class="titleS"> <div class="title">Bruno</div> <div class="subtitle">German Shepherd</div> </div></a><a class="face back" href="#"> <div class="img-wrapper"> <div class="avatar"></div> </div> <div class="infoS"> <div class="info-title">Bruno</div> <ul class="info-content"> <li class="info-content-item">Age <span>8 years</span></li> <li class="info-content-item">Color <span>Brown</span></li> <li class="info-content-item">Weight <span>39kg</span></li> </ul> </div></a></div> </div> </div> <script src='https://cdnjs.cloudflare.com/ajax/libs/jquery/3.1.0/jquery.min.js'></script> <script src="function.js"></script> </body> </html> |
style.css
Now create a CSS file named ‘style.css‘ and put these codes given here.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 |
/* Code By Webdevtrick ( https://webdevtrick.com ) */ @import url('https://fonts.googleapis.com/css?family=Josefin+Sans&display=swap'); body { font-family: 'Josefin Sans', sans-serif; background-color: #f3f3f3; color: #222; } html, body { height: 100%; } .container { position: relative; height: 100%; list-style: none; margin: 0; padding: 0 5%; display: -webkit-box; display: flex; -webkit-box-pack: center; justify-content: center; -webkit-box-align: center; align-items: center; } .card { display: block; float: left; position: relative; margin: 0; width: 100%; height: 0; padding: 0 0 28%; -webkit-perspective: 700px; perspective: 700px; } .card-object { color: #FFF; display: block; float: left; position: absolute; top: 6%; left: 6%; width: 88%; height: 88%; -webkit-transform-style: preserve-3d; transform-style: preserve-3d; } .card-object.card-1 .front { background: #222 url(https://webdevtrick.com/wp-content/uploads/husky.jpg) 90% 35%; background-size: 115%; } .card-object.card-1 .back .img-wrapper { background: transparent url(https://webdevtrick.com/wp-content/uploads/husky.jpg) 70% 45%; background-size: 160%; } .card-object.card-1 .back .avatar { background: transparent url(https://webdevtrick.com/wp-content/uploads/husky.jpg) 40% 20%; background-size: 130% 130%; } .card-object.card-2 .front { background: #222 url(https://webdevtrick.com/wp-content/uploads/pitbull.jpg) 50% 90% no-repeat; background-size: 105%; } .card-object.card-2 .back .img-wrapper { background: transparent url(https://webdevtrick.com/wp-content/uploads/pitbull.jpg) 70% 50%; background-size: 140%; } .card-object.card-2 .back .avatar { background: transparent url(https://webdevtrick.com/wp-content/uploads/pitbull.jpg) 50% 50% no-repeat; background-size: 140% 140%; } .card-object.card-3 .front { background: #222 url(https://webdevtrick.com/wp-content/uploads/german.jpg) 80% 100% no-repeat; background-size: 108%; } .card-object.card-3 .back .img-wrapper { background: transparent url(https://webdevtrick.com/wp-content/uploads/german.jpg) 90% 40% no-repeat; background-size: 115%; } .card-object.card-3 .back .avatar { background: #fff url(https://webdevtrick.com/wp-content/uploads/german.jpg) 0 50% no-repeat; background-size: 120% 120%; } .card-object.flip-in.card-1, .card-object.flip-in.card-3 { -webkit-animation: flip-2-hor-top-fwd 0.8s cubic-bezier(0.68, -0.55, 0.265, 1.55) both; animation: flip-2-hor-top-fwd 0.8s cubic-bezier(0.68, -0.55, 0.265, 1.55) both; } .card-object.flip-in.card-2 { -webkit-animation: flip-2-hor-bottom-fwd 0.8s cubic-bezier(0.68, -0.55, 0.265, 1.55) both; animation: flip-2-hor-bottom-fwd 0.8s cubic-bezier(0.68, -0.55, 0.265, 1.55) both; } .card-object.flip-out.card-1, .card-object.flip-out.card-3 { animation: flip-2-hor-top-fwd 0.8s cubic-bezier(0.68, -0.55, 0.265, 1.55) reverse both; } .card-object.flip-out.card-2 { animation: flip-2-hor-bottom-fwd 0.8s cubic-bezier(0.68, -0.55, 0.265, 1.55) reverse both; } .card-object-hf .back { -webkit-transform: rotateX(180deg); transform: rotateX(180deg); } .face { color: #fff; text-decoration: none; display: -webkit-box; display: flex; -webkit-box-pack: center; justify-content: center; -webkit-box-align: end; align-items: flex-end; flex-wrap: wrap; position: absolute; width: 100%; height: 100%; -webkit-backface-visibility: hidden; backface-visibility: hidden; } .face.front { z-index: 20; overflow: hidden; background-repeat: no-repeat; background-position: 50% 50%; } .face.front::before { position: absolute; top: -1px; right: -1px; bottom: -1px; left: -1px; content: ""; background: linear-gradient(45deg, rgba(0, 0, 0, 0.95) 0%, rgba(0, 0, 0, 0.5) 40%, rgba(0, 0, 0, 0.1) 100%) no-repeat; opacity: 0.7; z-index: 20; -webkit-transition: opacity 0.2s ease; transition: opacity 0.2s ease; } .face.front::after { position: absolute; top: 7%; right: 7%; bottom: 7%; left: 7%; border: 1px solid rgba(255, 255, 255, 0.35); z-index: 100; content: ""; } .face.front .titleS { position: absolute; bottom: 3%; left: 25%; right: 25%; overflow: hidden; display: -webkit-box; display: flex; -webkit-box-pack: center; justify-content: center; -webkit-box-align: center; align-items: center; text-align: center; flex-wrap: wrap; z-index: 100; -webkit-transform: translateY(0); transform: translateY(0); -webkit-transition: -webkit-transform 0.28s ease; transition: -webkit-transform 0.28s ease; transition: transform 0.28s ease; transition: transform 0.28s ease, -webkit-transform 0.28s ease; } .face.front .titleS .title { position: relative; width: 100%; text-transform: uppercase; font-size: 2vw; line-height: 1; opacity: 0.8; -webkit-transition: opacity 0.2s ease; transition: opacity 0.2s ease; } .face.front .titleS .title::after { display: block; margin: 7% auto 8% auto; width: 100%; height: 1px; content: ""; background-color: #fff; opacity: 0.5; -webkit-transform: scale(0); transform: scale(0); -webkit-transition: -webkit-transform 0.15s; transition: -webkit-transform 0.15s; transition: transform 0.15s; transition: transform 0.15s, -webkit-transform 0.15s; } .face.front .titleS .subtitle { font-size: 0.9vw; line-height: 1; letter-spacing: 1px; text-transform: uppercase; opacity: 0; -webkit-transition: opacity 0.15s; transition: opacity 0.15s; } .face.front:hover::before { opacity: 0.9; } .face.front:hover .titleS { -webkit-transform: translateY(-50%); transform: translateY(-50%); } .face.front:hover .titleS .title { opacity: 1; } .face.front:hover .titleS .title::after { -webkit-transform: scale(1); transform: scale(1); opacity: 0.5; -webkit-transition-delay: 0.15s; transition-delay: 0.15s; -webkit-transition-duration: 0.2s; transition-duration: 0.2s; } .face.front:hover .titleS .subtitle { opacity: 0.7; -webkit-transition-delay: 0.2s; transition-delay: 0.2s; -webkit-transition-duration: 0.2s; transition-duration: 0.2s; } .face.back { color: #222; background: #fff; z-index: 10; } .info-container { position: absolute; display: -webkit-box; display: flex; -webkit-box-pack: center; justify-content: center; flex-wrap: wrap; -webkit-box-align: start; align-items: flex-start; top: 6%; right: 6%; bottom: 6%; left: 6%; padding: 0; } .img-wrapper { position: absolute; top: 0; left: 0; width: 100%; height: 38%; z-index: 10; } .img-wrapper::after { content: ""; display: block; position: absolute; top: 0; right: 0; bottom: 0; left: 0; background: rgba(14, 6, 70, 0.6); opacity: 0.7; } .avatar { position: absolute; left: 50%; height: 68%; width: 25.84%; display: block; border-radius: 50%; margin-top: 25.08%; margin-left: -12.92%; background-color: #fff; border: 3px solid #FFF; z-index: 20; } .infoS { display: -webkit-box; display: flex; -webkit-box-pack: center; justify-content: center; -webkit-box-align: center; align-items: center; flex-wrap: wrap; position: absolute; top: 50.92%; left: 0; right: 0; bottom: 0; padding: 4% 15% 15%; } .info-title { font-size: 1.5vw; text-align: left; padding: 0; margin: 0; text-align: center; display: block; width: 100%; } .info-content { display: -webkit-box; display: flex; -webkit-box-pack: justify; justify-content: space-between; -webkit-box-align: center; align-items: center; width: 100%; padding: 8% 0 0; margin: 8% 0 0; border-top: 1px solid #e0e0e0; } .info-content-item { color: #222; font-size: 0.75vw; line-height: 1; text-align: center; display: inline-block; padding: 0; margin: 0; text-transform: uppercase; color: #aaa; } .info-content-item span { display: block; font-weight: bold; font-size: 1.1vw; margin-top: 7px; text-transform: none; color: #222; } .info { position: absolute; bottom: 30px; left: 5%; right: 5%; font-size: 1em; text-align: center; } .info a { color: #8c0f8c; text-decoration: none; } .info a:hover { text-decoration: underline; } @-webkit-keyframes flip-2-hor-top-fwd { 0% { -webkit-transform: translateY(0) translateZ(0) rotateX(0); transform: translateY(0) translateZ(0) rotateX(0); -webkit-transform-origin: 50% 0%; transform-origin: 50% 0%; } 100% { -webkit-transform: translateY(-100%) translateZ(100px) rotateX(-180deg); transform: translateY(-100%) translateZ(100px) rotateX(-180deg); -webkit-transform-origin: 50% 100%; transform-origin: 50% 100%; } } @keyframes flip-2-hor-top-fwd { 0% { -webkit-transform: translateY(0) translateZ(0) rotateX(0); transform: translateY(0) translateZ(0) rotateX(0); -webkit-transform-origin: 50% 0%; transform-origin: 50% 0%; } 100% { -webkit-transform: translateY(-100%) translateZ(100px) rotateX(-180deg); transform: translateY(-100%) translateZ(100px) rotateX(-180deg); -webkit-transform-origin: 50% 100%; transform-origin: 50% 100%; } } @-webkit-keyframes flip-2-hor-bottom-fwd { 0% { -webkit-transform: translateY(0) translateZ(0) rotateX(0); transform: translateY(0) translateZ(0) rotateX(0); -webkit-transform-origin: 50% 100%; transform-origin: 50% 100%; } 100% { -webkit-transform: translateY(100%) translateZ(100px) rotateX(180deg); transform: translateY(100%) translateZ(100px) rotateX(180deg); -webkit-transform-origin: 50% 0%; transform-origin: 50% 0%; } } @keyframes flip-2-hor-bottom-fwd { 0% { -webkit-transform: translateY(0) translateZ(0) rotateX(0); transform: translateY(0) translateZ(0) rotateX(0); -webkit-transform-origin: 50% 100%; transform-origin: 50% 100%; } 100% { -webkit-transform: translateY(100%) translateZ(100px) rotateX(180deg); transform: translateY(100%) translateZ(100px) rotateX(180deg); -webkit-transform-origin: 50% 0%; transform-origin: 50% 0%; } } @media (max-width: 650px) { .container { display: block; } .card { height: 200px; } .info-title { font-size: 7vw; } .info-content-item { font-size: 4vw; } .info-content-item span { font-size: 3vw; } .face.front .titleS .title { font-size: 9vw; } .face.front .titleS .subtitle { font-size: 5vw; } } |
function.js
The final step, create a JavaScript file named ‘function.js‘ and put the codes.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
//Code By Webdevtrick ( https://webdevtrick.com ) var $cards = $('.card-object'), $faceButtons = $('.face'); $faceButtons.on('click', flipCard); function flipCard(event) { event.preventDefault(); var $btnFace = $(this), $card = $btnFace.parent('.card-object'); if( $card.hasClass('flip-in') ) { closeCards(); } else { closeCards(); openCard($card); } } function closeCards() { $cards.each( function() { $(this) .filter('.flip-in') .removeClass('flip-in') .queue( function() { // Force reflow hack var reflow = this.offsetHeight; $(this) .addClass('flip-out') .dequeue(); }) }); } function openCard($card) { $card .removeClass('flip-out') .queue( function() { // Force reflow hack var reflow = this.offsetHeight; $(this) .addClass('flip-in') .dequeue(); }); } |
That’s It. Now you have successfully created Card Flip Animation Using CSS and jQuery, Flipping Profile Cards. If you have any doubt or question comment down below.
Thanks For Visiting, Keep Visiting.
Thanks about all…This is really good…