Fading after div content has been shown using CSS

I am trying to show a notification when a button is clicked. A click of a button actually verifies email authentication. I know to show a div with content with an error message. However, I would like to clear the error message, say, after 5 seconds. I would like to achieve this using CSS. Below is my attempt, it just hides everything. Please inform.

#signup-response{
    width: 50%;
    margin-left: auto;
    margin-right: auto;
    text-align: center;
    background-color: #FF0000;
    margin-top: 20px;
    -webkit-transition: opacity 5s ease-in-out;
    -moz-transition: opacity 35s ease-in-out;
    -ms-transition: opacity 5s ease-in-out;
    -o-transition: opacity 5s ease-in-out;
     opacity: 0;
} 
+4
source share
3 answers

You can use an example .animation

Set animation-delayat the right time. Make sure you use animation-fill-mode: forwardsto stop the animation.

#signup-response{
    width: 50%;
    margin-left: auto;
    margin-right: auto;
    text-align: center;
    background-color: #FF0000;
    margin-top: 20px;

     animation:signup-response 0.5s 1;
    -webkit-animation:signup-response 0.5s 1;
    animation-fill-mode: forwards;

    animation-delay:2s;
    -webkit-animation-delay:1s; /* Safari and Chrome */
    -webkit-animation-fill-mode: forwards;

} 

@keyframes signup-response{
    from {opacity :1;}
    to {opacity :0;}
}

@-webkit-keyframes signup-response{
    from {opacity :1;}
    to {opacity :0;}
}
+12
source

css3:

-webkit, -moz, -ms -o animation animation-delay .error-message keyframes.

.error-message {
    -webkit-animation: fadeOut 2s forwards;
    animation: fadeOut 2s forwards;
    -webkit-animation-delay: 5s;
    animation-delay: 5s;
    background: red;
    color: white;
    padding: 10px;
    text-align: center;
}

@-webkit-keyframes fadeOut {
    from {opacity: 1;}
    to {opacity: 0;}
}

@keyframes fadeOut {
    from {opacity: 1;}
    to {opacity: 0;}
}
<div class="error-message">
    <p>Some random text</p>
</div>
Hide result
+5

cross-browser hack (instead of using css3 animation keyframes):

transition-timing-function: cubic-bezier(1,1,1.0,0);}
-webkit-transition-timing-function: cubic-bezier(1,1,1.0,0);

http://www.w3schools.com/cssref/css3_pr_transition-timing-function.asp

+1
source

Source: https://habr.com/ru/post/1523939/


All Articles