Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Make background fade out/in

Is there any way I can use CSS3 to fade in and out a solid white background of a <div>? the content should remain visible so just the background should fade.

Any ideas using css3 transitions/transforms?

thank you for your help.

like image 728
cmplieger Avatar asked Oct 01 '11 20:10

cmplieger


People also ask

How do I fade-in and fade out in CSS?

The jQuery fadeToggle() method toggles between the fadeIn() and fadeOut() methods. If the elements are faded out, fadeToggle() will fade them in.

How do you make a fade effect in CSS?

Use animation and transition property to create a fade-in effect on page load using CSS. Method 1: Using CSS animation property: A CSS animation is defined with 2 keyframes. One with the opacity set to 0, the other with the opacity set to 1.

How do I make my whole background black?

To set the background color in HTML, use the style attribute. The style attribute specifies an inline style for an element. The attribute is used with the HTML <body> tag, with the CSS property background-color. HTML5 do not support the <body> tag bgcolor attribute, so the CSS style is used to add background color.


2 Answers

Sure, you can use the transition property directly on the background-color:

div {
   background-color: white;    

   /* transition the background-color over 1s with a linear animation */
   transition: background-color 1s linear;
}

/* the :hover that causes the background-color to change */
div:hover {
   background-color: transparent;      
}

Here's an example of a red background fading out on :hover.

like image 167
Pat Avatar answered Oct 19 '22 20:10

Pat


You may find this useful for examples of image and background color fades: - http://nettuts.s3.amazonaws.com/581_cssTransitions/demos.html

However using CSS 3 to do the transition will limit the effect to browsers that don't support it.

like image 3
KryptoniteDove Avatar answered Oct 19 '22 20:10

KryptoniteDove