CSS Marquees

by trkli

HTML

<div class="marquee">
    <span class="marquee__inner">Surface Book is the first of its kind.</span>
</div>

CSS

/* Sets up our marquee, and inner content */
.marquee {
    overflow: hidden;
    position: relative;
    padding-left: 100%;
    /* Some browsers may require -webkit-animation */
    animation: reduce 20s linear infinite;
}

        .marquee__inner {
            white-space: nowrap;
            display: inline-block;
            /* Some browsers may require -webkit-animation */
            animation: scroll 20s linear infinite;
        }

/* Creates two white-to-transparent gradients at the ends of the marquee */
.marquee::before, .marquee::after {
    z-index: 1;
    top: 0; left: 0;
    position: absolute;
    width: 50px; height: 100%;
    content: ""; display: block;
    background: linear-gradient( to right, white, transparent );
}

.marquee::after {
    left: auto; right: 0;
    transform: rotate(180deg);
}

/* Pauses the animations when we hover the marquee */
.marquee:hover, .marquee:hover .marquee__inner {
    /* Some browsers may require -webkit-animation-play-state */
    animation-play-state: paused;
}

/* Some browsers may require @-webkit-keyframes */
@keyframes reduce {
    to {
        padding-left: 0;
    }
}

@keyframes scroll {
    to {
        transform: translateX( -100% );
    }
}