Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CSS Auto hide elements after 5 seconds

Is it possible to hide element 5 seconds after the page load? I know there is a jQuery solution.

I want to do exactly same thing, but hoping to get the same result with CSS transition.

Any innovative idea? Or am I asking beyond the limit of css transition/animation?

like image 808
Alfred Avatar asked Feb 24 '14 16:02

Alfred


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.

How do you hide a div in 5 seconds?

Approach: Select the div element. Use delay function (setTimeOut(), delay()) to provide the delay to hide() the div element.

How do you make an element disappear in CSS?

You can hide an element in CSS using the CSS properties display: none or visibility: hidden . display: none removes the entire element from the page and mat affect the layout of the page. visibility: hidden hides the element while keeping the space the same.


1 Answers

YES!

But you can't do it in the way you may immediately think, because you cant animate or create a transition around the properties you'd otherwise rely on (e.g. display, or changing dimensions and setting to overflow:hidden) in order to correctly hide the element and prevent it from taking up visible space.

Therefore, create an animation for the elements in question, and simply toggle visibility:hidden; after 5 seconds, whilst also setting height and width to zero to prevent the element from still occupying space in the DOM flow.

FIDDLE

CSS

html, body {     height:100%;     width:100%;     margin:0;     padding:0; } #hideMe {     -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;     } } 

HTML

<div id='hideMe'>Wait for it...</div> 
like image 174
SW4 Avatar answered Sep 23 '22 02:09

SW4