{"id":1657,"date":"2012-08-16T22:03:38","date_gmt":"2012-08-16T22:03:38","guid":{"rendered":"http:\/\/cssreset.com\/?p=1657"},"modified":"2015-04-17T18:17:24","modified_gmt":"2015-04-17T18:17:24","slug":"how-to-create-the-perfect-image-crossfade-with-css3-transitions","status":"publish","type":"post","link":"https:\/\/cssdeck.com\/blog\/how-to-create-the-perfect-image-crossfade-with-css3-transitions\/","title":{"rendered":"How to Create the Perfect Image Crossfade with CSS3 Transitions"},"content":{"rendered":"<p>This is a quick and easy lesson in how to set up an image crossfade using only CSS to accomplish the task. It&#8217;s a very nice aesthetic and it only takes a few minutes to set up.<!--more--><\/p>\n<p>The classic crossfade transition is a longtime favorite in the worlds of film, video and photography. And now it can be something that is easily added through CSS to any website or app. First, you need at least two images to crossfade between and then the rest is just simple coding.<\/p>\n<pre class=\"prettyprint linenums\">&lt;div id=\"crossfade\"&gt;\r\n    &lt;img class=\"bottom\" src=\"images\/YourImage.jpg\" \/&gt;\r\n    &lt;img class=\"top\" src=\"images\/YourImage.jpg\" \/&gt;\r\n&lt;\/div&gt;\r\n\r\n#crossfade {\r\n    position:relative;\r\n    height:250px;\r\n    width:400px;\r\n}\r\n#crossfade img {\r\n    position:absolute;\r\n    left:0;\r\n    opacity: 1;\r\n    -webkit-transition: opacity 1s ease-in-out;\r\n    -moz-transition: opacity 1s ease-in-out;\r\n    -o-transition: opacity 1s ease-in-out;\r\n    -ms-transition: opacity 1s ease-in-out;    \r\n    transition: opacity 1s ease-in-out;\r\n}\r\n\r\n#crossfade img.top:hover {\r\n    opacity:0;\r\n}<\/pre>\n<p>As you can see, first two images were identified under a &lt;div id&gt;&lt;\/div&gt; and then the #crossfade selector is used to endure the proper layout. A second selector of #crossfade image then sets the opacity to 100% and also adresses browser compatibility and support of the transitions. The last bit of code needed is the #crossfade img. top: hover declaration setting the opacity to 0% upon hover.<\/p>\n<p>And there you have it. A nice image crossfade every time. You may also find interest in this CSS Basics tutorial on using selectors properly. If you have a tutorial request or wish to share one of your own, please send us a message letting us know.<\/p>\n<div class=\"wp-socializer wpsr-share-icons \" data-lg-action=\"show\" data-sm-action=\"show\" data-sm-width=\"768\" ><h3>Share and Enjoy !<\/h3><div class=\"wpsr-si-inner\"><div class=\"wpsr-counter wpsrc-sz-32px\" style=\"color:#000\"><span class=\"scount\"><span data-wpsrs=\"\" data-wpsrs-svcs=\"facebook,twitter,linkedin,pinterest,print,pdf\">0<\/span><\/span><small class=\"stext\">Shares<\/small><\/div><div class=\"socializer sr-popup sr-32px sr-circle sr-opacity sr-pad sr-count-1 sr-count-1\"><span class=\"sr-facebook\"><a rel=\"nofollow\" href=\"https:\/\/www.facebook.com\/share.php?u=\" target=\"_blank\"  title=\"Share this on Facebook\"  style=\"color: #ffffff\" ><i class=\"fab fa-facebook-f\"><\/i><span class=\"ctext\"><span data-wpsrs=\"\" data-wpsrs-svcs=\"facebook\">0<\/span><\/span><\/a><\/span>\n<span class=\"sr-twitter\"><a rel=\"nofollow\" href=\"https:\/\/twitter.com\/intent\/tweet?text=%20-%20%20\" target=\"_blank\"  title=\"Tweet this !\"  style=\"color: #ffffff\" ><i class=\"fab fa-twitter\"><\/i><\/a><\/span>\n<span class=\"sr-linkedin\"><a rel=\"nofollow\" href=\"https:\/\/www.linkedin.com\/sharing\/share-offsite\/?url=\" target=\"_blank\"  title=\"Add this to LinkedIn\"  style=\"color: #ffffff\" ><i class=\"fab fa-linkedin-in\"><\/i><\/a><\/span>\n<span class=\"sr-pinterest\"><a rel=\"nofollow\" href=\"https:\/\/www.pinterest.com\/pin\/create\/button\/?url=&amp;media=&amp;description=\" target=\"_blank\"  title=\"Submit this to Pinterest\"  style=\"color: #ffffff\" data-pin-custom=\"true\"><i class=\"fab fa-pinterest\"><\/i><span class=\"ctext\"><span data-wpsrs=\"\" data-wpsrs-svcs=\"pinterest\">0<\/span><\/span><\/a><\/span>\n<span class=\"sr-print\"><a rel=\"nofollow\" href=\"https:\/\/www.printfriendly.com\/print?url=\" target=\"_blank\"  title=\"Print this article \"  style=\"color: #ffffff\" ><i class=\"fa fa-print\"><\/i><\/a><\/span>\n<span class=\"sr-pdf\"><a rel=\"nofollow\" href=\"https:\/\/www.printfriendly.com\/print?url=\" target=\"_blank\"  title=\"Convert to PDF\"  style=\"color: #ffffff\" ><i class=\"fa fa-file-pdf\"><\/i><\/a><\/span><\/div><\/div><\/div>","protected":false},"excerpt":{"rendered":"<p>This is a quick and easy lesson in how to set up an image crossfade using only CSS to accomplish the task. It&#8217;s a very nice aesthetic and it only takes a few minutes to set up.<\/p>\n<p>Share and Enjoy !0Shares0<\/p>\n<p>0<\/p>\n<p> [&#8230;]<\/p>\n<p><a class=\"more-link article\" href=\"https:\/\/cssdeck.com\/blog\/how-to-create-the-perfect-image-crossfade-with-css3-transitions\/\" title=\"Click to read 'How to Create the Perfect Image Crossfade with CSS3 Transitions'\">Read Article<\/a><\/p>\n","protected":false},"author":18,"featured_media":1659,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[6],"tags":[67,64,46,82,63,85,73],"_links":{"self":[{"href":"https:\/\/cssdeck.com\/blog\/wp-json\/wp\/v2\/posts\/1657"}],"collection":[{"href":"https:\/\/cssdeck.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/cssdeck.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/cssdeck.com\/blog\/wp-json\/wp\/v2\/users\/18"}],"replies":[{"embeddable":true,"href":"https:\/\/cssdeck.com\/blog\/wp-json\/wp\/v2\/comments?post=1657"}],"version-history":[{"count":3,"href":"https:\/\/cssdeck.com\/blog\/wp-json\/wp\/v2\/posts\/1657\/revisions"}],"predecessor-version":[{"id":1718,"href":"https:\/\/cssdeck.com\/blog\/wp-json\/wp\/v2\/posts\/1657\/revisions\/1718"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/cssdeck.com\/blog\/wp-json\/wp\/v2\/media\/1659"}],"wp:attachment":[{"href":"https:\/\/cssdeck.com\/blog\/wp-json\/wp\/v2\/media?parent=1657"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/cssdeck.com\/blog\/wp-json\/wp\/v2\/categories?post=1657"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/cssdeck.com\/blog\/wp-json\/wp\/v2\/tags?post=1657"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}