Make background fade out/in

末鹿安然 提交于 2020-01-10 04:47:16

问题


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.


回答1:


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.




回答2:


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.




回答3:


You could have two divs in one container div. The first div contains the white background, the second one gets the content.

Then, use a CSS3 transform to animate the opacity of the first div to zero.



来源:https://stackoverflow.com/questions/7622822/make-background-fade-out-in

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!