Pure CSS Alert Bar

by Josh Krauth-Harding

HTML

<div id="alert">
<p class="alert">
This is my essage
</p>

</div>

CSS

body {
    padding: 0;
}

/* Alert */

#alert {
    position: relative;
    z-index: 100;
}
#alert:hover:after {
    background: hsla(0,0%,0%,.8);
    border-radius: 3px;
    color: #f6f6f6;
    content: 'Click to Dismiss';
    font: bold 12px/30px sans-serif;
    height: 30px;
    left: 50%;
    margin-left: -60px;
    position: absolute;
    text-align: center;
    top: 50px;
    width: 120px;
}
#alert:hover:before {
    border-bottom: 10px solid hsla(0,0%,0%,.8);
    border-left: 10px solid transparent;
    border-right: 10px solid transparent;
    content: '';
    height: 0;
    left: 50%;
    margin-left: -10px;
    position: absolute;
    top: 40px;
    width: 0;
}
#alert:target {
    display: none;
}
.alert {
background: rgb(254,191,1);
    color: #444;
    display: block;
    height: auto;
    padding: 8px 0px;
    position: absolute;
    text-align: center;
    top: -45px;
    width: 100%;
            animation: alert 1s ease forwards;
}


/* Animation */

@-webkit-keyframes alert {
    0% { opacity: 0; }
    50% { opacity: 1; }
    100% { top: 0; }
}
@-moz-keyframes alert {
    0% { opacity: 0; }
    50% { opacity: 1; }
    100% { top: 0; }
}
@-ms-keyframes alert {
    0% { opacity: 0; }
    50% { opacity: 1; }
    100% { top: 0; }
}
@-o-keyframes alert {
    0% { opacity: 0; }
    50% { opacity: 1; }
    100% { top: 0; }
}
@keyframes alert {
    0% { opacity: 0; }
    50% { opacity: 1; }
    100% { top: 0; }
}

JavaScript

// Click run to start animation again.