Mẫu code Ribbons 6



Ribbon động, Khuyến mãi hoặc giảm giá cho các trang bán hàng!

1. HTML

<div class="ribbon">
  <div class="medallion"></div>

  <div class="ribbon-1">
    <span class="inner">
                                <span class="fadeLeft">Funtime</span>
    </span>
  </div>

  <div class="ribbon-2">
    <span class="inner">
                                <span class="fadeRight">Extravaganza</span>
    </span>
  </div>

  <div class="ribbon-3">
    <span class="inner">
                                <span class="fadeLeft">Each Funtime Purchase = One Chance to Win</span>
    </span>
  </div>

  <div class="ball fadeIn">
    <span class="ball-text">
                                <strong>$1,000</strong>
                                Daily Prize
                            </span>
  </div>
</div>

2. CSS

@import "https://fonts.googleapis.com/css?family=Oswald:400,700";

body {
  font-family: 'Oswald', sans-serif;
    letter-spacing: 1px;
}

* {
  box-sizing: border-box;  
}

.ribbon {
        position: absolute;
        top: 0;
        left: 0;
        margin: 0 auto;
        right: 0;

        [class*="ribbon-"] {
            margin: 74px auto 0;
            transform-origin: 50% 50%;
            transform: rotate(-8.5deg);
            position: relative;
            z-index: 4;
            width: 287px;
            height: 56px;
            
            .inner {
                background: #003468;
                color: #fff;
                text-transform: uppercase;
                text-align: center;
                display: block;
                width: 0;
                height: 100%;
                padding: 11px 0;
                font-size: 1.5em;
                text-shadow: 3px 3px 1px #001b47;
                position: relative;
                z-index: 2;
                transform: skewX(-9deg);
                transition: width .12s ease-in-out;
            }
            
            &:before {
                content: '';
                transform-origin: 0 0;
                transform: rotate(-17.25deg) skewX(-9deg) translateX(158px);
                display: block;
                width: 0;
                height: 100%;
                position: absolute;
                top: 0;
                left: 4px;
                background: #001b47;
                z-index: -1;
                transition: all .12s ease-in-out .7s;
            }
        }

        .ribbon-1 {
            .inner {
                letter-spacing: 19px;
                font-weight: 700;
            }
        }

        &.active .inner {
            width: 100%;
        }

        &.active [class*="ribbon-"]:before,
        &.active [class*="ribbon-"]:after {
        }

        &.active .ribbon-1 {
            .inner {
                transition-delay: .82s;
            }

            &:before {
                width: 158px;
                transform: rotate(-17.25deg) skewX(-9deg) translateX(0);
            }
        }
        
        .ribbon-2 {
            z-index: 3;
            font-size: 45px;
            width: 451px;
            height: 137px;
            margin-top: 22px;

            .inner {
                padding: 19px 0;

                &:before,
                &:after {
                    content: '';
                    position: absolute;
                    top: 14px;
                    left: 14px;
                    right: 14px;
                    bottom: 14px;
                    background: url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAeYAAAALCAYAAACqPi4nAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAyhpVFh0WE1MOmNvbS5hZG9iZS54bXAAAAAAADw/eHBhY2tldCBiZWdpbj0i77u/IiBpZD0iVzVNME1wQ2VoaUh6cmVTek5UY3prYzlkIj8+IDx4OnhtcG1ldGEgeG1sbnM6eD0iYWRvYmU6bnM6bWV0YS8iIHg6eG1wdGs9IkFkb2JlIFhNUCBDb3JlIDUuNi1jMDE0IDc5LjE1Njc5NywgMjAxNC8wOC8yMC0wOTo1MzowMiAgICAgICAgIj4gPHJkZjpSREYgeG1sbnM6cmRmPSJodHRwOi8vd3d3LnczLm9yZy8xOTk5LzAyLzIyLXJkZi1zeW50YXgtbnMjIj4gPHJkZjpEZXNjcmlwdGlvbiByZGY6YWJvdXQ9IiIgeG1sbnM6eG1wPSJodHRwOi8vbnMuYWRvYmUuY29tL3hhcC8xLjAvIiB4bWxuczp4bXBNTT0iaHR0cDovL25zLmFkb2JlLmNvbS94YXAvMS4wL21tLyIgeG1sbnM6c3RSZWY9Imh0dHA6Ly9ucy5hZG9iZS5jb20veGFwLzEuMC9zVHlwZS9SZXNvdXJjZVJlZiMiIHhtcDpDcmVhdG9yVG9vbD0iQWRvYmUgUGhvdG9zaG9wIENDIDIwMTQgKE1hY2ludG9zaCkiIHhtcE1NOkluc3RhbmNlSUQ9InhtcC5paWQ6NjEyM0FFRTU0NUUzMTFFNTlDMjdDMEJDMDFCNjlGNDkiIHhtcE1NOkRvY3VtZW50SUQ9InhtcC5kaWQ6NjEyM0FFRTY0NUUzMTFFNTlDMjdDMEJDMDFCNjlGNDkiPiA8eG1wTU06RGVyaXZlZEZyb20gc3RSZWY6aW5zdGFuY2VJRD0ieG1wLmlpZDpEOUZEM0I5NDQ1QkQxMUU1OUMyN0MwQkMwMUI2OUY0OSIgc3RSZWY6ZG9jdW1lbnRJRD0ieG1wLmRpZDo2MTIzQUVFNDQ1RTMxMUU1OUMyN0MwQkMwMUI2OUY0OSIvPiA8L3JkZjpEZXNjcmlwdGlvbj4gPC9yZGY6UkRGPiA8L3g6eG1wbWV0YT4gPD94cGFja2V0IGVuZD0iciI/Pm3y348AAAIOSURBVHja7JvhboIwEMfbOZgyQF9h2cPtrfZ8+7APU0RQt7FrciQ3QqHodFT+v+RCc9ikHtX/tUe1GjFVVc3okij/0GRL5ScrT8edkt15OG4zv2cejvuRLPBw3BFZ6OG452y+8UC28HDcAc/xa/FN9k72RvaqSfzMH/EL2RPZMwcyFRMh4YkcKwAAAGC6GAHNyHZke7I1Wcm2Zp+5t+F2Trbltku/TGv9pQeuYGuxTjmjSISAS99CCHwt6l2+JfeNOaMN8PwBAAAMkSgWxIKF7oOvRYdQ5tx26kei+XmNL6JHG+Gqaop1yAIe8hZD7VuJbYc2X73ltuJ7kfAtMZcBAOAqWFeJ3N62CGXp2o9E83grgdJTnymUAEixluIfcVIQdPjq+knM91PhS/hztW+O3yUAYMSi2be6PHn7lkTzgBBDmMeaBEixbtbwkx6frVTQ5sNzBeB22DiuLvu2b8u2fiSae4QYwgwunwDcK3sN31bXt5UKusoHEaINJk524urSafuWRLNEiCHMAAxNAmQNv6+u3ywV9JUPZKlghmiDgeS2VaJyfznIJrBGNAuEGECYwZQTAHNGOVXudX1ZFnApH6RiBwFcnp0QynNWl60CS6KZI8QAwgzA7SQBlzgCGCp/jgUWLUJ5zuryl8CSaG4xywCAMAMw1iTgr44AmutBnfdykBHNDE8FgP/lR4ABABGzGigi55YSAAAAAElFTkSuQmCC') center bottom no-repeat;
                    background-size: 100%;
                    opacity: 0;
                    transition: opacity .3s ease-in-out 1.86s;
                }

                &:before {
                    transform-origin: 50% 50%;
                    transform: rotate(180deg);
                }
            }
            
            &:before {
                width: 0;
                left: 11px;
                transform: rotate(-10.25deg) skewX(-9deg) translateX(451px);
                height: 47px;
                transition-delay: .94s;
            }
        }

        &.active .ribbon-2 {
            .inner {
                transition-delay: 1.06s;

                &:before,
                &:after {
                    opacity: 1;
                }
            }

            &:before {
                width: 376px;
                transform: rotate(-10.25deg) skewX(-9deg) translateX(0);
            }
        }
        
        .ribbon-3 {
            z-index: 2;
            font-size: 9px;
            width: 326px;
            height: 55px;
            margin-top: 24px;
            
            .inner {
                color: #e8a713;
                padding: 19px 0;
            }
             
            &:before {
                width: 0;
                height: 47px;
                left: 11px;
                transform: rotate(-10.25deg) skewX(-9deg) translateX(387px);
                transition-delay: 1.18s;
            }
            
            &:after {
                content: '';
                transform-origin: 100% 100%;
                transform: rotate(-15.3deg) skewX(9deg) translateX(72px);
                display: block;
                width: 0;
                height: 45px;
                position: absolute;
                bottom: 0;
                right: 4px;
                background: #001b47;
                z-index: -1;
                transition-delay: 1.42s;
            }
        }

        &.active .ribbon-3 {
            .inner {
                transition-delay: 1.3s;
            }

            &:before {
                width: 387px;
                transform: rotate(-10.25deg) skewX(-9deg) translateX(0);
            }

            &:after {
                width: 56px;
                transform: rotate(-15.3deg) skewX(9deg) translateX(0);
            }
        }
        
        .ball {
            width: 190px;
            height: 190px;
            background: #e8a713;
            border-radius: 95px;
            padding: 85px 20px 0;
            text-align: center;
            color: #001b47;
            border: 10px solid #001b47;
            margin: -87px auto 0;
            position: relative;
            left: 18px;
            z-index: 1;
            transform-origin: 50% 50%;
            transform: rotate(-8.5deg);

            .ball-text {
                font-size: 12px;
                line-height: 1.2;
                text-align: right;
                display: block;
                width: 119px;
            
                strong {
                    font-size: 39px;
                    font-style: italic;
                    display: block;
                    margin: 0 auto;
                }
            }

        }

        .fadeLeft {
            opacity: 0;
            transform: translateX(-100%);
            transition: all .3s ease-in-out 1.56s;
            display: block;
        }
        
        .fadeRight {
            opacity: 0;
            transform: translateX(100%);
            transition: all .3s ease-in-out 1.56s;
            display: block;
        }

        .fadeIn {
            opacity: 0;
            transition: all .3s ease-in-out 1.42s;
            display: block;
        }

        &.active {
            .fadeLeft,
            .fadeRight {
                opacity: 1;
                transform: translateX(0);
            }

            .fadeIn {
                opacity: 1;
            }
        }
    }

3. JAVASCRIPT

$(document).ready(function() {
  setTimeout(function() {
    $('.ribbon').addClass('active');
  }, 500);
});



Mong bài viết giúp ích được các bạn phần nào trong thiết kế Web. Hãy nhấn nút để mọi người cùng học hỏi kiến thức mới nhé. Cảm ơn các bạn đã quan tâm Forum.