Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CSS hide element, after 5 seconds show it [duplicate]

Tags:

css

I found this question CSS Auto hide elements after 5 seconds

and I need to know how to do the oposite of this. Basically:

-Page loads with element hidden

-Wait 5 seconds

-Show element

I'm not very good with CSS so Any help would be nice!

#thingtohide {
    -moz-animation: cssAnimation 0s ease-in 5s forwards;
    /* Firefox */
    -webkit-animation: cssAnimation 0s ease-in 5s forwards;
    /* Safari and Chrome */
    -o-animation: cssAnimation 0s ease-in 5s forwards;
    /* Opera */
    animation: cssAnimation 0s ease-in 5s forwards;
    -webkit-animation-fill-mode: forwards;
    animation-fill-mode: forwards;
}

@keyframes cssAnimation {
    to {
        width:0;
        height:0;
        overflow:hidden;
    }
}
@-webkit-keyframes cssAnimation {
    to {
        width:0;
        height:0;
        visibility:hidden;
    }
}
like image 389
Dylan Grove Avatar asked Oct 17 '17 20:10

Dylan Grove


People also ask

How do you make elements disappear after a few seconds CSS?

To hide an HTML element after certain seconds using CSS, you can use the @keyframes CSS rule and set the CSS property called visibility to value hidden for that particular element in CSS.

Which CSS property is used to hide an element?

The visibility CSS property shows or hides an element without changing the layout of a document.

What are the different ways to hide the element using CSS?

Completely hiding elements can be done in 3 ways: via the CSS property display , e.g. display: none; via the CSS property visibility , e.g. visibility: hidden; via the HTML5 attribute hidden , e.g. <span hidden>


Video Answer


1 Answers

You can run something like this. This sets the opacity to 0 and after a few seconds, it ramps it back to 100%. This option allows you to fine tune how quickly you want it to appear, giving you control over how much opacity the element would have and when in the timeframe it would have it.

#showMe {
    opacity: 0;
    -moz-animation: cssAnimation 5s;
    /* Firefox */
    -webkit-animation: cssAnimation 5s;
    /* Safari and Chrome */
    -o-animation: cssAnimation 5s;
    /* Opera */
    animation: cssAnimation 5s;
    -webkit-animation-fill-mode: forwards;
    animation-fill-mode: forwards;
}
@keyframes cssAnimation {
    99% {
        opacity: 0;
    }
    100% {
        opacity: 1;
    }
}
@-webkit-keyframes cssAnimation {
    99% {
        opacity: 0;
    }
    100% {
        opacity: 1;
    }
}
<div id='showMe'>Wait for it...</div>
like image 116
yohohosilver Avatar answered Nov 13 '22 10:11

yohohosilver