How we can create different types of modal boxes using HTML CSS JS? Solution: See this Responsive Flexbox Modals Multiple Types Of, Flexible Modal Design.
Previously I have shared some Modal related programs, but this is a bunch of modals with different types using flexbox. Basically, a modal box is a scripted effect that allows you to overlay a small element over a website. The main benefit of modal boxes is, they avoid the need to use window pop-ups or page reloads. When can create multiple types of modal boxes like with overlay effect, navigation, toggle close features, etc. This program is all about that, there are some different types of modal boxes which contains different elements and design.
Today you will learn to create Flexible Modal Design using CSS and jQuery. Basically, there are 9 different types of modal boxes. Some are plain, some have icon menu, some have a color overlay, etc. The interesting thing about these modals is, they passing data like color, text, etc over data attributes. Also, there is a smooth transition effect when the modal open or close. And these modal boxes have a responsive design, it will fit on any screen size.
So, Today I am sharing Responsive Flexbox Modals Multiple Types Of. There I have used HTML CSS for creating layout and styling and jQuery for functioning. All modals based on CSS flex command and passing data through HTML data attribute. This is a group or bunch of modal boxes, you can pick your favorite one and use it on your own website. You can use it for showing content, form, images, or other types of things.
If you are thinking now how this modal boxes actually are, then see the preview given below.
Preview Of Flexible Modal Boxes Design
See this video preview to getting an idea of how these modals look like.
Now you can see these modal boxes visually, also you can see and text live by pressing the button given above. If you like this then get the source code of its.
You May Also Like:
- Toast Message with Close Animation
- jQuery Quiz Program
- Responsive Animated Gallery
- Smart Fixed Navigation
Responsive Flexbox Modals Multiple Types Source Code
Before sharing source code, let’s talk a little bit about it. First I have created a main div named container and placed all the items inside it. Inside the main div I have placed another div named modals for store all contents. There I have used HTML list and hyperlink tags to create the button and modal box also. Inside every list item, I have placed a hyperlink tag and put all values using HTML Data-* attribute. There I have not created any sperate section for creating the modals, each button and its modal box in a single line of code.
Now using CSS I have placed all the items in the right place, as you can see in the preview. As you know there I have used CSS flexbox or flex display ( display: flex; ) command to create the program. And I gave basic values like size, position, margin, padding, etc to all the items. I used the CSS transition command to create the animation effect, and @media query to create responsive elements.
jQuery handling here the modal open/close function and passing data using data attribute values. jQuery fetched data attributes using $(this).attr command and stored in variables. And it adding and removing class names according to user actions. Also, it is changing HTML values dynamically.
Left all other things you will understand after getting the codes, I can’t explain in writing. For creating this program you have to create 3 files. First file for HTML, second for CSS, and the third 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 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 |
<!DOCTYPE html> <!--Code By Webdevtrick ( https://webdevtrick.com )--> <html lang="en" > <head> <meta charset="UTF-8"> <title>Responsive Flexbox-based Modal | Webdevtrick.com</title> <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" /> <link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.5.0/css/font-awesome.min.css" rel="stylesheet"> <link rel="stylesheet" href="style.css"> </head> <body> <div class="container"> <div class="modals"> <h2>Responsive Flexbox-Based Modals</h2> <p>Passing data-attributes!</p> <ul> <li><a class="sm_open" data-modal="examplePlain" data-effect="pushdown">Modal Plain</a></li> <li><a class="sm_open" data-modal="exampleAdvanced" data-effect="pushup" data-icons="is_right" data-header-type="detached">Modal (w/Detached Header and Right Icon Menu)</a></li> <li><a class="sm_open" data-modal="exampleAdvanced" data-effect="pushup" data-icons="is_right">Modal (w/Header and Right Icon Menu)</a></li> <li><a class="sm_open" data-modal="exampleAdvanced" data-effect="pushup" data-icons="is_left">Modal (w/Header and Left Icon Menu)</a></li> <li> <a class="sm_open" data-modal="exampleData" data-effect="pushdown" data-header="#1 This header is from the link" data-overlay="none" data-content="This is a sample HTML string being passed with a data-attribute... <p><h3>Super easy to change, simply by tweaking the button launching the modal.</h3></p>" data-container-color="green">Modal (Passing Data-Attributes w/Transparent Overlay) </a> </li> <li> <a class="sm_open" data-modal="exampleData" data-effect="pushdown" data-header="#1 This header is from the link" data-overlay="red" data-content="This is a sample HTML string being passed with a data-attribute... <p><h3>Super easy to change, simply by tweaking the button launching the modal.</h3></p>" data-container-color="red">Modal (Passing Data-Attributes w/Eye-Searing Red Overlay Color) </a> </li> <li> <a class="sm_open" data-modal="exampleData" data-effect="pushup" data-header="#1 This header is from the link" data-content="This is a sample HTML string being passed with a data-attribute... <p><h3>Super easy to change, simply by tweaking the button launching the modal.</h3></p>" data-container-color="tan">Modal (Passing Data-Attributes w/HTML) </a> </li> <li> <a class="sm_open" data-modal="exampleData" data-effect="pushdown" data-header="#2 This header is from the link" data-content="....and this is a second sample string being passed with a data-attribute attached to the button." data-container-color="red">Modal (Passing Data-Attributes #1) </a> </li> <li> <a class="sm_open" data-modal="exampleData" data-effect="pushdown" data-header="#3 This header is from the link" data-content="...and this is yet another sample string being passed with a data-attribute attached to the button. I'm just typing this sentence to give a little more bulk to the modal...not filling it with important info, but making it stand out from the other examples a bit more." data-container-color="green">Modal (Passing Data-Attributes #2) </a> </li> </ul> </div> <div class="slim_modal" id="examplePlain"> <div class="sm_content"> <div class="sm_content_inner_wrap"> <div class="sm_area_top"> <h3>Example Modal Content <span>...for this CSS Demo</span> </h3> </div> <div class="sm_area_bottom"> <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Deserunt nihil asperiores recusandae odio distinctio earum voluptatibus, quisquam repellendus voluptas quaerat quis est totam, optio quia, molestias voluptatum error libero pariatur!</p> </div> <a class="sm_close sm_close_button">CLOSE</a> </div> </div> </div> <div class="slim_modal" id="exampleAdvanced"> <div class="sm_content"> <div class="sm_header">Hi. I'm a Header.</div> <div class="sm_icon_menu"> <ul> <li class="sm_close"><i class="fa fa-times fa-fw "></i></li> <li><i class="fa fa-gear fa-fw"></i></li> <li><i class="fa fa-plus fa-fw"></i></li> <li><i class="fa fa-sitemap fa-fw"></i></li> <li><i class="fa fa-user fa-fw"></i></li> </ul> </div> <div class="sm_content_inner_wrap"> <div class="sm_area_top"> <h3>Example Modal Content <span>...for this CSS Demo</span> </h3> </div> <div class="sm_area_bottom"> <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Deserunt nihil asperiores recusandae odio distinctio earum voluptatibus, quisquam repellendus voluptas quaerat quis est totam, optio quia, molestias voluptatum error libero pariatur!</p> </div> <div class="sm_close sm_close_button">CLOSE</div> </div> </div> </div> <div class="slim_modal" id="exampleData"> <div class="sm_content"> <div class="sm_header"></div> <div class="sm_icon_menu is_right"> <ul> <li class="sm_close"><i class="fa fa-times fa-fw "></i></li> </ul> </div> <div class="sm_content_inner_wrap"> <div class="sm_area_all"></div> <a class="sm_close sm_close_button">CLOSE</a> </div> </div> </div> </div> <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.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 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 |
/* Code By Webdevtrick ( https://webdevtrick.com ) */ html * { -webkit-font-smoothing: antialiased; -moz-osx-font-smoothing: grayscale; } html, body { height: 100%; } body { font-family: "Montserrat", sans-serif; color: #404040; margin: 0 auto; background: #9acfef; } .container { text-align: center; display: flex; align-items: center; justify-content: center; height: 100%; } .container .modals { background: #ffffff; max-width: 60%; padding: 40px; border-radius: 6px; -webkit-border-radius: 6px; -moz-border-radius: 6px; -ms-border-radius: 6px; -o-border-radius: 6px; -webkit-box-shadow: 0px 0px 80px 0px rgba(30, 30, 30, 0.2); -moz-box-shadow: 0px 0px 80px 0px rgba(30, 30, 30, 0.2); box-shadow: 0px 0px 80px 0px rgba(30, 30, 30, 0.2); font-size: .9em; } .container .modals .holder_svg { padding-bottom: 25px; border-bottom: 1px solid #efefef; margin-bottom: 25px; } .container .modals .holder_svg svg { max-width: 40%; } .container .modals p { padding-bottom: 20px; margin: 0 auto; } .container .modals ul { padding: 0px; margin: 0 auto; list-style-type: none; } .container .modals ul li { display: inline-block; margin: 0 auto; background: #e9e9e9; color: #303030; padding: 10px; text-decoration: none; margin-bottom: 1px; } .container .modals ul li a { display: table-cell; } .slim_modal { position: fixed; width: 100%; height: 100%; top: 0; left: 0; display: -webkit-box; display: -webkit-flex; display: -moz-flex; display: -ms-flexbox; display: flex; -webkit-box-align: center; -ms-flex-align: center; -webkit-align-items: center; -moz-align-items: center; align-items: center; -webkit-box-pack: center; -ms-flex-pack: center; -webkit-justify-content: center; -moz-justify-content: center; justify-content: center; background: rgba(0, 0, 0, 0.85); z-index: 2; display: none; font-size: 1em; -webkit-transition: background 0.5s ease 0.06s; -moz-transition: background 0.5s ease 0.06s; -ms-transition: background 0.5s ease 0.06s; -o-transition: background 0.5s ease 0.06s; transition: background 0.5s ease 0.06s; } .slim_modal.none { background: rgba(10, 10, 10, 0); } .slim_modal.red { background: rgba(228, 30, 58, 0.8); } .slim_modal.tan { background: rgba(202, 180, 75, 0.8); } .slim_modal.green { background: rgba(111, 171, 85, 0.8); } .slim_modal .sm_content { background: whitesmoke; text-align: center; max-width: 800px; } @media only screen and (min-width: 320px) { .slim_modal .sm_content { padding: 0px; width: 100%; height: 100%; border-radius: 0px; -webkit-border-radius: 0px; -moz-border-radius: 0px; -ms-border-radius: 0px; -o-border-radius: 0px; } } @media only screen and (min-width: 414px) { .slim_modal .sm_content { padding: 0px; width: 100%; height: 100%; border-radius: 0px; -webkit-border-radius: 0px; -moz-border-radius: 0px; -ms-border-radius: 0px; -o-border-radius: 0px; } } @media only screen and (min-width: 769px) { .slim_modal .sm_content { padding: 15px; width: 80%; max-height: 90%; height: auto; border-radius: 4px; -webkit-border-radius: 4px; -moz-border-radius: 4px; -ms-border-radius: 4px; -o-border-radius: 4px; } } @media only screen and (min-width: 1025px) { .slim_modal .sm_content { padding: 15px; width: 80%; max-height: 90%; height: auto; border-radius: 4px; -webkit-border-radius: 4px; -moz-border-radius: 4px; -ms-border-radius: 4px; -o-border-radius: 4px; } } @media only screen and (min-width: 1401px) { .slim_modal .sm_content { padding: 15px; width: 80%; max-height: 90%; height: auto; border-radius: 4px; -webkit-border-radius: 4px; -moz-border-radius: 4px; -ms-border-radius: 4px; -o-border-radius: 4px; } } .slim_modal .sm_content .sm_content_inner_wrap { position: relative; margin: 0 auto; height: 100%; background: #ffffff; -webkit-box-shadow: 0px 0px 1px 0 rgba(30, 30, 30, 0.5); -moz-box-shadow: 0px 0px 1px 0 rgba(30, 30, 30, 0.5); box-shadow: 0px 0px 1px 0 rgba(30, 30, 30, 0.5); z-index: 2; } @media only screen and (min-width: 320px) { .slim_modal .sm_content .sm_content_inner_wrap { border-radius: 0px; -webkit-border-radius: 0px; -moz-border-radius: 0px; -ms-border-radius: 0px; -o-border-radius: 0px; } } @media only screen and (min-width: 414px) { .slim_modal .sm_content .sm_content_inner_wrap { border-radius: 0px; -webkit-border-radius: 0px; -moz-border-radius: 0px; -ms-border-radius: 0px; -o-border-radius: 0px; } } @media only screen and (min-width: 769px) { .slim_modal .sm_content .sm_content_inner_wrap { border-radius: 4px; -webkit-border-radius: 4px; -moz-border-radius: 4px; -ms-border-radius: 4px; -o-border-radius: 4px; } } @media only screen and (min-width: 1025px) { .slim_modal .sm_content .sm_content_inner_wrap { border-radius: 4px; -webkit-border-radius: 4px; -moz-border-radius: 4px; -ms-border-radius: 4px; -o-border-radius: 4px; } } @media only screen and (min-width: 1401px) { .slim_modal .sm_content .sm_content_inner_wrap { border-radius: 4px; -webkit-border-radius: 4px; -moz-border-radius: 4px; -ms-border-radius: 4px; -o-border-radius: 4px; } } .slim_modal .sm_content .sm_content_inner_wrap .sm_close_button { padding: 10px; width: auto; display: block; background: #efefef; } .slim_modal .sm_content .sm_content_inner_wrap .sm_area_top, .slim_modal .sm_content .sm_content_inner_wrap .sm_area_bottom, .slim_modal .sm_content .sm_content_inner_wrap .sm_area_all { padding: 4em; } .slim_modal .sm_content .sm_content_inner_wrap .sm_area_top h3 span, .slim_modal .sm_content .sm_content_inner_wrap .sm_area_bottom h3 span, .slim_modal .sm_content .sm_content_inner_wrap .sm_area_all h3 span { display: block; font-size: .7em; } .slim_modal .sm_content .sm_content_inner_wrap .sm_area_top { background: rgba(30, 30, 30, 0.02); } .slim_modal .sm_content .sm_content_inner_wrap .sm_area_bottom { background: white; } .slim_modal .sm_content .sm_icon_menu { opacity: 1; box-sizing: border-box; position: absolute; top: 40px; background: whitesmoke; -webkit-transition: all 0.3s ease 0s; -moz-transition: all 0.3s ease 0s; -ms-transition: all 0.3s ease 0s; -o-transition: all 0.3s ease 0s; transition: all 0.3s ease 0s; } .slim_modal .sm_content .sm_icon_menu ul { list-style-type: none; padding: 0; margin: 0 auto; } .slim_modal .sm_content .sm_icon_menu ul li { font-size: 1.1em; height: 3em; line-height: 3em; background: #e6e6e6; padding: 0px 8px 0px 8px; margin-bottom: 1px; color: rgba(30, 30, 30, 0.4); -webkit-transition: all 0.5s ease 0s; -moz-transition: all 0.5s ease 0s; -ms-transition: all 0.5s ease 0s; -o-transition: all 0.5s ease 0s; transition: all 0.5s ease 0s; } .slim_modal .sm_content .sm_icon_menu ul li.sm_close { background: #ffffff; } .slim_modal .sm_content .sm_icon_menu ul li:nth-child(2) { margin-top: 10px; } .slim_modal .sm_content .sm_icon_menu ul li:hover { background: #ffffff; color: rgba(30, 30, 30, 0.7); } .slim_modal .sm_content .sm_icon_menu ul li::last-child { border: none; } .slim_modal .sm_content .sm_icon_menu.is_right { right: 0px; border-radius: 0px 4px 4px 0px; -webkit-border-radius: 0px 4px 4px 0px; -moz-border-radius: 0px 4px 4px 0px; -ms-border-radius: 0px 4px 4px 0px; -o-border-radius: 0px 4px 4px 0px; } @media only screen and (min-width: 320px) { .slim_modal .sm_content .sm_icon_menu.is_right { top: 70px; right: 0px; z-index: 9; -webkit-box-shadow: 0px 0px 0px 0px rgba(30, 30, 30, 0); -moz-box-shadow: 0px 0px 0px 0px rgba(30, 30, 30, 0); box-shadow: 0px 0px 0px 0px rgba(30, 30, 30, 0); padding: 1px; border: none; } } @media only screen and (min-width: 414px) { .slim_modal .sm_content .sm_icon_menu.is_right { top: 70px; right: 0px; z-index: 9; -webkit-box-shadow: 0px 0px 0px 0px rgba(30, 30, 30, 0); -moz-box-shadow: 0px 0px 0px 0px rgba(30, 30, 30, 0); box-shadow: 0px 0px 0px 0px rgba(30, 30, 30, 0); padding: 1px; border: none; } } @media only screen and (min-width: 769px) { .slim_modal .sm_content .sm_icon_menu.is_right { top: 15px; right: 15px; z-index: 1; -webkit-box-shadow: 15px 0px 30px 0px rgba(30, 30, 30, 0.2); -moz-box-shadow: 15px 0px 30px 0px rgba(30, 30, 30, 0.2); box-shadow: 15px 0px 30px 0px rgba(30, 30, 30, 0.2); border: 1px solid rgba(30, 30, 30, 0.1); border-left: none; } } @media only screen and (min-width: 1025px) { .slim_modal .sm_content .sm_icon_menu.is_right { top: 15px; right: 15px; z-index: 1; -webkit-box-shadow: 15px 0px 30px 0px rgba(30, 30, 30, 0.2); -moz-box-shadow: 15px 0px 30px 0px rgba(30, 30, 30, 0.2); box-shadow: 15px 0px 30px 0px rgba(30, 30, 30, 0.2); border: 1px solid rgba(30, 30, 30, 0.1); border-left: none; } } @media only screen and (min-width: 1401px) { .slim_modal .sm_content .sm_icon_menu.is_right { top: 15px; right: 15px; z-index: 1; -webkit-box-shadow: 15px 0px 30px 0px rgba(30, 30, 30, 0.2); -moz-box-shadow: 15px 0px 30px 0px rgba(30, 30, 30, 0.2); box-shadow: 15px 0px 30px 0px rgba(30, 30, 30, 0.2); border: 1px solid rgba(30, 30, 30, 0.1); border-left: none; } } .slim_modal .sm_content .sm_icon_menu.is_left { border-radius: 4px 0px 0px 4px; -webkit-border-radius: 4px 0px 0px 4px; -moz-border-radius: 4px 0px 0px 4px; -ms-border-radius: 4px 0px 0px 4px; -o-border-radius: 4px 0px 0px 4px; } @media only screen and (min-width: 320px) { .slim_modal .sm_content .sm_icon_menu.is_left { top: 70px; left: 0px; z-index: 9; -webkit-box-shadow: 0px 0px 0px 0px rgba(30, 30, 30, 0); -moz-box-shadow: 0px 0px 0px 0px rgba(30, 30, 30, 0); box-shadow: 0px 0px 0px 0px rgba(30, 30, 30, 0); padding: 1px; border: none; } } @media only screen and (min-width: 414px) { .slim_modal .sm_content .sm_icon_menu.is_left { top: 70px; left: 0px; z-index: 9; -webkit-box-shadow: 0px 0px 0px 0px rgba(30, 30, 30, 0); -moz-box-shadow: 0px 0px 0px 0px rgba(30, 30, 30, 0); box-shadow: 0px 0px 0px 0px rgba(30, 30, 30, 0); padding: 1px; border: none; } } @media only screen and (min-width: 769px) { .slim_modal .sm_content .sm_icon_menu.is_left { top: 15px; left: 15px; z-index: 1; -webkit-box-shadow: -15px 0px 30px 0px rgba(30, 30, 30, 0.2); -moz-box-shadow: -15px 0px 30px 0px rgba(30, 30, 30, 0.2); box-shadow: -15px 0px 30px 0px rgba(30, 30, 30, 0.2); border: 1px solid rgba(30, 30, 30, 0.1); border-right: none; } } @media only screen and (min-width: 1025px) { .slim_modal .sm_content .sm_icon_menu.is_left { top: 15px; left: 15px; z-index: 1; -webkit-box-shadow: -15px 0px 30px 0px rgba(30, 30, 30, 0.2); -moz-box-shadow: -15px 0px 30px 0px rgba(30, 30, 30, 0.2); box-shadow: -15px 0px 30px 0px rgba(30, 30, 30, 0.2); border: 1px solid rgba(30, 30, 30, 0.1); border-right: none; } } @media only screen and (min-width: 1401px) { .slim_modal .sm_content .sm_icon_menu.is_left { top: 15px; left: 15px; z-index: 1; -webkit-box-shadow: -15px 0px 30px 0px rgba(30, 30, 30, 0.2); -moz-box-shadow: -15px 0px 30px 0px rgba(30, 30, 30, 0.2); box-shadow: -15px 0px 30px 0px rgba(30, 30, 30, 0.2); border: 1px solid rgba(30, 30, 30, 0.1); border-right: none; } } .slim_modal .sm_content .sm_header { box-sizing: border-box; right: 0; left: 0; top: 0; bottom: 0; color: rgba(30, 30, 30, 0.7); text-transform: uppercase; margin: 0 auto; display: inline-block; height: 40px; line-height: 40px; opacity: 0; -webkit-transition: all 0.3s ease 0s; -moz-transition: all 0.3s ease 0s; -ms-transition: all 0.3s ease 0s; -o-transition: all 0.3s ease 0s; transition: all 0.3s ease 0s; } @media only screen and (min-width: 320px) { .slim_modal .sm_content .sm_header { position: relative; width: 100%; background: #e6e6e6; border-radius: 0px; -webkit-border-radius: 0px; -moz-border-radius: 0px; -ms-border-radius: 0px; -o-border-radius: 0px; padding-top: 0; } } @media only screen and (min-width: 414px) { .slim_modal .sm_content .sm_header { position: relative; width: 100%; background: #e6e6e6; border-radius: 0px; -webkit-border-radius: 0px; -moz-border-radius: 0px; -ms-border-radius: 0px; -o-border-radius: 0px; padding-top: 0; } } @media only screen and (min-width: 769px) { .slim_modal .sm_content .sm_header { position: absolute; width: 90%; background: whitesmoke; border-radius: 4px 4px 0px 0px; -webkit-border-radius: 4px 4px 0px 0px; -moz-border-radius: 4px 4px 0px 0px; -ms-border-radius: 4px 4px 0px 0px; -o-border-radius: 4px 4px 0px 0px; padding-top: 7.5px; text-align: center; } } @media only screen and (min-width: 1025px) { .slim_modal .sm_content .sm_header { position: absolute; width: 90%; background: whitesmoke; border-radius: 4px 4px 0px 0px; -webkit-border-radius: 4px 4px 0px 0px; -moz-border-radius: 4px 4px 0px 0px; -ms-border-radius: 4px 4px 0px 0px; -o-border-radius: 4px 4px 0px 0px; padding-top: 7.5px; text-align: center; } } @media only screen and (min-width: 1401px) { .slim_modal .sm_content .sm_header { position: absolute; width: 90%; background: whitesmoke; border-radius: 4px 4px 0px 0px; -webkit-border-radius: 4px 4px 0px 0px; -moz-border-radius: 4px 4px 0px 0px; -ms-border-radius: 4px 4px 0px 0px; -o-border-radius: 4px 4px 0px 0px; padding-top: 7.5px; text-align: center; } } .slim_modal .sm_content.pushup { -moz-transform: scale(0.98) translateY(20px); -o-transform: scale(0.98) translateY(20px); -ms-transform: scale(0.98) translateY(20px); -webkit-transform: scale(0.98) translateY(20px); transform: scale(0.98) translateY(20px); -webkit-transition: all 0.5s ease 0s; -moz-transition: all 0.5s ease 0s; -ms-transition: all 0.5s ease 0s; -o-transition: all 0.5s ease 0s; transition: all 0.5s ease 0s; -webkit-box-shadow: 0px 0px 0px 0px rgba(30, 30, 30, 0.4); -moz-box-shadow: 0px 0px 0px 0px rgba(30, 30, 30, 0.4); box-shadow: 0px 0px 0px 0px rgba(30, 30, 30, 0.4); opacity: 0; } .slim_modal .sm_content.pushup.show { -webkit-box-shadow: 0px 20px 80px 0px rgba(30, 30, 30, 0.4); -moz-box-shadow: 0px 20px 80px 0px rgba(30, 30, 30, 0.4); box-shadow: 0px 20px 80px 0px rgba(30, 30, 30, 0.4); opacity: 1; } .slim_modal .sm_content.pushdown { -moz-transform: scale(0.98) translateY(-20px); -o-transform: scale(0.98) translateY(-20px); -ms-transform: scale(0.98) translateY(-20px); -webkit-transform: scale(0.98) translateY(-20px); transform: scale(0.98) translateY(-20px); -webkit-transition: all 0.5s ease 0s; -moz-transition: all 0.5s ease 0s; -ms-transition: all 0.5s ease 0s; -o-transition: all 0.5s ease 0s; transition: all 0.5s ease 0s; -webkit-box-shadow: 0px 0px 0px 0px rgba(30, 30, 30, 0.4); -moz-box-shadow: 0px 0px 0px 0px rgba(30, 30, 30, 0.4); box-shadow: 0px 0px 0px 0px rgba(30, 30, 30, 0.4); opacity: 0; } .slim_modal .sm_content.pushdown.show { -webkit-box-shadow: 0px -20px 80px 0px rgba(30, 30, 30, 0.4); -moz-box-shadow: 0px -20px 80px 0px rgba(30, 30, 30, 0.4); box-shadow: 0px -20px 80px 0px rgba(30, 30, 30, 0.4); opacity: 1; } .slim_modal .sm_content.show { -moz-transform: scale(1); -o-transform: scale(1); -ms-transform: scale(1); -webkit-transform: scale(1); transform: scale(1); -webkit-transition: all 0.3s ease 0s; -moz-transition: all 0.3s ease 0s; -ms-transition: all 0.3s ease 0s; -o-transition: all 0.3s ease 0s; transition: all 0.3s ease 0s; } .slim_modal .sm_content.show .sm_icon_menu { -webkit-transition: all 0.5s ease 0.06s; -moz-transition: all 0.5s ease 0.06s; -ms-transition: all 0.5s ease 0.06s; -o-transition: all 0.5s ease 0.06s; transition: all 0.5s ease 0.06s; } @media only screen and (min-width: 320px) { .slim_modal .sm_content.show .sm_icon_menu.is_right { top: 70px; right: 0px; } } @media only screen and (min-width: 414px) { .slim_modal .sm_content.show .sm_icon_menu.is_right { top: 70px; right: 0px; } } @media only screen and (min-width: 769px) { .slim_modal .sm_content.show .sm_icon_menu.is_right { top: 15px; right: -25px; } } @media only screen and (min-width: 1025px) { .slim_modal .sm_content.show .sm_icon_menu.is_right { top: 15px; right: -25px; } } @media only screen and (min-width: 1401px) { .slim_modal .sm_content.show .sm_icon_menu.is_right { top: 15px; right: -25px; } } @media only screen and (min-width: 320px) { .slim_modal .sm_content.show .sm_icon_menu.is_left { top: 70px; left: 0px; } } @media only screen and (min-width: 414px) { .slim_modal .sm_content.show .sm_icon_menu.is_left { top: 70px; left: 0px; } } @media only screen and (min-width: 769px) { .slim_modal .sm_content.show .sm_icon_menu.is_left { top: 15px; left: -25px; } } @media only screen and (min-width: 1025px) { .slim_modal .sm_content.show .sm_icon_menu.is_left { top: 15px; left: -25px; } } @media only screen and (min-width: 1401px) { .slim_modal .sm_content.show .sm_icon_menu.is_left { top: 15px; left: -25px; } } .slim_modal .sm_content.show .sm_header { -webkit-transition: top 0.5s ease 0.1s; -moz-transition: top 0.5s ease 0.1s; -ms-transition: top 0.5s ease 0.1s; -o-transition: top 0.5s ease 0.1s; transition: top 0.5s ease 0.1s; opacity: 1; } @media only screen and (min-width: 320px) { .slim_modal .sm_content.show .sm_header { top: 0px; z-index: 9; } } @media only screen and (min-width: 414px) { .slim_modal .sm_content.show .sm_header { top: 0px; z-index: 9; } } @media only screen and (min-width: 769px) { .slim_modal .sm_content.show .sm_header { top: -40px; z-index: 1; } } @media only screen and (min-width: 1025px) { .slim_modal .sm_content.show .sm_header { top: -40px; z-index: 1; } } @media only screen and (min-width: 1401px) { .slim_modal .sm_content.show .sm_header { top: -40px; z-index: 1; } } .slim_modal .sm_content.show .sm_header.detached { -webkit-transition: opacity 0.5s ease 0.1s; -moz-transition: opacity 0.5s ease 0.1s; -ms-transition: opacity 0.5s ease 0.1s; -o-transition: opacity 0.5s ease 0.1s; transition: opacity 0.5s ease 0.1s; border-radius: 4px; -webkit-border-radius: 4px; -moz-border-radius: 4px; -ms-border-radius: 4px; -o-border-radius: 4px; background: rgba(0, 0, 0, 0.9); color: rgba(255, 255, 255, 0.8); } @media only screen and (min-width: 320px) { .slim_modal .sm_content.show .sm_header.detached { top: 0px; z-index: 9; } } @media only screen and (min-width: 414px) { .slim_modal .sm_content.show .sm_header.detached { top: 0px; z-index: 9; } } @media only screen and (min-width: 769px) { .slim_modal .sm_content.show .sm_header.detached { top: -60px; padding-top: 0; z-index: 1; } } @media only screen and (min-width: 1025px) { .slim_modal .sm_content.show .sm_header.detached { top: -60px; padding-top: 0; z-index: 1; } } @media only screen and (min-width: 1401px) { .slim_modal .sm_content.show .sm_header.detached { top: -60px; padding-top: 0; z-index: 1; } } .sm_content.red { background: #EF798A; } .sm_content.red .sm_header { background: #EF798A; color: #ffffff; } .sm_content.tan { background: #E1D59A; } .sm_content.tan .sm_header { background: #E1D59A; color: #ffffff; } .sm_content.green { background: #9acfef; } .sm_content.green .sm_header { background: #9acfef; color: #ffffff; } |
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 |
$(document).ready(function() { $('.sm_open').on('click', function(){ var modal = $(this).attr('data-modal'); var modaloverlaycolor = $(this).attr('data-overlay'); var modaleffect = $(this).attr('data-effect'); var modalheader = $(this).attr('data-header'); var modalheadertype = $(this).attr('data-header-type'); var modalcontent = $(this).attr('data-content'); var modaliconside = $(this).attr('data-icons'); var modalcontainercolor = $(this).attr('data-container-color'); $('#' + modal).addClass(modaloverlaycolor); $('#' + modal + ' .sm_content').addClass(modaleffect); $('#' + modal + ' .sm_content .sm_header').html(modalheader); $('#' + modal + ' .sm_content .sm_header').addClass(modalheadertype); $('#' + modal + ' .sm_content .sm_area_all').html(modalcontent); $('#' + modal + ' .sm_icon_menu').addClass(modaliconside); $('#' + modal + ' .sm_content').addClass(modalcontainercolor); $('#' + modal).fadeIn().css("display", "flex"); setTimeout(function(){ $('#'+modal + ' .sm_content').addClass('show'); }, 400); }); $('.sm_close').on('click', function(){ var $modal = $(this).parents('.slim_modal'); closeModal($modal); }); $('.slim_modal').on('click', function(e) { if (e.target !== this) return; var $modal = $(this); closeModal($modal); }); function closeModal($modal) { $modal.find('.sm_content').removeClass('show'); setTimeout(function(){ $modal.removeClass('red green tan none'); $modal.find('.sm_content').removeClass('red green tan'); $modal.find('.sm_icon_menu').removeClass('is_right is_left'); $modal.find('.sm_header').removeClass('detached'); $modal.fadeOut(); }, 400); } }); |
That’s It. Now you have successfully created Responsive Flexbox Modals Multiple Types Of, Flexible Modal Design. If you have any doubt or question comment down below.
Thanks For Visiting, Keep Visiting.