{"id":2381,"date":"2017-04-19T19:37:48","date_gmt":"2017-04-19T19:37:48","guid":{"rendered":"http:\/\/cssreset.com\/?p=2381"},"modified":"2017-04-19T19:37:48","modified_gmt":"2017-04-19T19:37:48","slug":"css-animated-shatter-text-effect","status":"publish","type":"post","link":"https:\/\/cssdeck.com\/blog\/css-animated-shatter-text-effect\/","title":{"rendered":"CSS Animated Shatter Text Effect"},"content":{"rendered":"<p>Most of the time on this site when we give you text effect tutorials, it&#8217;s shadow and border properties that are used to create the effects. For this tutorial, we&#8217;re going to show you how to create a pure CSS text effect that&#8217;s actually animated. In the following tutorial, we&#8217;ll create &#8220;shattered&#8221; text. The text that we&#8217;re creating looks like it&#8217;s slightly shattered, and then when it&#8217;s hovered upon, it breaks apart with a smooth CSS transition to reveal just how shattered it is. This effect is adapted from a <a href=\"http:\/\/codepen.io\/pcameron\/pen\/rVmera\" target=\"_blank\">CodePen<\/a> tutorial.<\/p>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"size-large wp-image-2382 aligncenter\" alt=\"Screen Shot 2017-04-14 at 12.08.48 PM\" src=\"https:\/\/cssdeck.com\/blog\/\/wp-content\/uploads\/2017\/04\/Screen-Shot-2017-04-14-at-12.08.48-PM-1024x297.png\" width=\"1024\" height=\"297\" srcset=\"https:\/\/cssdeck.com\/blog\/wp-content\/uploads\/2017\/04\/Screen-Shot-2017-04-14-at-12.08.48-PM-1024x297.png 1024w, https:\/\/cssdeck.com\/blog\/wp-content\/uploads\/2017\/04\/Screen-Shot-2017-04-14-at-12.08.48-PM-300x87.png 300w, https:\/\/cssdeck.com\/blog\/wp-content\/uploads\/2017\/04\/Screen-Shot-2017-04-14-at-12.08.48-PM-180x52.png 180w, https:\/\/cssdeck.com\/blog\/wp-content\/uploads\/2017\/04\/Screen-Shot-2017-04-14-at-12.08.48-PM.png 1026w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/p>\n<p>To start, we&#8217;ll need some simple HTML. For this tutorial, we&#8217;ve put our text in a span tag inside a wrapper div, like this:<\/p>\n<pre>&lt;div class=\"wrapper\"&gt;\r\n &lt;h1&gt;&lt;span&gt;Shatter&lt;\/span&gt;&lt;\/h1&gt;\r\n&lt;\/div&gt;<\/pre>\n<p>Now we&#8217;ll need to add some CSS to create our animated shattering effect. To create the effect, we use a lot of instances of the :before and :after pseudo-selectors and we also take advantage of the clip-path property. For the hover effect, we use the :hover pseudo-selector in conjunction with the :before and :after pseudo-selectors, and we also use the CSS transition property to give the text its animated effect upon hover.<\/p>\n<p>Take a look at the excerpt below to see how your CSS should look:<\/p>\n<pre>body {\r\n background-color: #ff4040;\r\n}\r\n.wrapper {\r\n width: 500px;\r\n margin: 0 auto;\r\n position: relative;\r\n text-align: center;\r\n}\r\nh1 {\r\n text-transform: uppercase;\r\n font-weight: bold;\r\n font-size: 6rem;\r\n position: relative;\r\n color: transparent;\r\n margin-bottom: 0;\r\n}\r\nh1:before {\r\n content: \"Shatter\";\r\n position: absolute;\r\n top: 0px;\r\n left: 22px;\r\n color: white;\r\n -webkit-clip-path: inset(0px 298px 0px 0px);\r\n clip-path: inset(0px 298px 0px 0px);\r\n -webkit-transition: all 0.3s;\r\n transition: all 0.3s;\r\n}\r\nh1 span:before {\r\n content: \"Shatter\";\r\n position: absolute;\r\n top: 0px;\r\n left: 22px;\r\n color: white;\r\n -webkit-clip-path: inset(0px 200px 0px 154px);\r\n clip-path: inset(0px 200px 0px 154px);\r\n -webkit-transition: all 0.3s;\r\n transition: all 0.3s;\r\n}\r\nh1:after {\r\n content: \"Shatter\";\r\n position: absolute;\r\n right: 24px;\r\n top: 0px;\r\n color: white;\r\n -webkit-clip-path: inset(0px 100px 0px 250px);\r\n clip-path: inset(0px 100px 0px 250px);\r\n -webkit-transition: all 0.5s;\r\n transition: all 0.5s;\r\n}\r\nh1 span:after {\r\n content: \"Shatter\";\r\n position: absolute;\r\n right: 24px;\r\n top: 0px;\r\n color: white;\r\n -webkit-clip-path: inset(0px 0px 0px 353px);\r\n clip-path: inset(0px 0px 0px 353px);\r\n -webkit-transition: all 0.5s;\r\n transition: all 0.5s;\r\n}\r\nh1:hover:after {\r\n top: 10px;\r\n cursor: pointer;\r\n color: rgba(255, 255, 255, 0.6);\r\n}\r\nh1:hover:before {\r\n top: -10px;\r\n left: 0px;\r\n cursor: pointer;\r\n color: rgba(255, 255, 255, 0.6);\r\n}\r\nh1:hover span:before {\r\n top: 4px;\r\n cursor: pointer;\r\n}\r\nh1:hover span:after {\r\n top: -8px;\r\n left: 30px;\r\n cursor: pointer;\r\n}<\/pre>\n<p>The way that the CSS splits up the HTML into fragments is by using the :before and :after pseudo-selectors in conjunction with the content property to layer several different versions of the word &#8220;Shattered&#8221; on top of each other, then it clips them all so that they all appear as separate entities that don&#8217;t sit on top of one another and can be controlled individually using its own selector, like h1:before or h1 span:before.<\/p>\n<p>After you&#8217;ve applied this CSS to your HTML code, your shattered text should look like this when its hovered upon:<\/p>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"size-large wp-image-2383 aligncenter\" alt=\"Screen Shot 2017-04-14 at 12.08.53 PM\" src=\"https:\/\/cssdeck.com\/blog\/\/wp-content\/uploads\/2017\/04\/Screen-Shot-2017-04-14-at-12.08.53-PM-1024x269.png\" width=\"1024\" height=\"269\" srcset=\"https:\/\/cssdeck.com\/blog\/wp-content\/uploads\/2017\/04\/Screen-Shot-2017-04-14-at-12.08.53-PM-1024x269.png 1024w, https:\/\/cssdeck.com\/blog\/wp-content\/uploads\/2017\/04\/Screen-Shot-2017-04-14-at-12.08.53-PM-300x78.png 300w, https:\/\/cssdeck.com\/blog\/wp-content\/uploads\/2017\/04\/Screen-Shot-2017-04-14-at-12.08.53-PM-180x47.png 180w, https:\/\/cssdeck.com\/blog\/wp-content\/uploads\/2017\/04\/Screen-Shot-2017-04-14-at-12.08.53-PM.png 1094w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/p>\n<p>As you can see, the text has shifted in position, and the color of different fragments of the text has changed. Achieving this effect is actually fairly simple &#8212; if you take a look at the CSS, you&#8217;ll see that the effect is created by using the top and left property to shift around the positions of the letters.<\/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>Most of the time on this site when we give you text effect tutorials, it&#8217;s shadow and border properties that are used to create the effects. For this tutorial, we&#8217;re going to show you how to create a pure CSS [&#8230;]<\/p>\n<p><a class=\"more-link article\" href=\"https:\/\/cssdeck.com\/blog\/css-animated-shatter-text-effect\/\" title=\"Click to read 'CSS Animated Shatter Text Effect'\">Read Article<\/a><\/p>\n","protected":false},"author":18,"featured_media":2383,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[6],"tags":[],"_links":{"self":[{"href":"https:\/\/cssdeck.com\/blog\/wp-json\/wp\/v2\/posts\/2381"}],"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=2381"}],"version-history":[{"count":1,"href":"https:\/\/cssdeck.com\/blog\/wp-json\/wp\/v2\/posts\/2381\/revisions"}],"predecessor-version":[{"id":2384,"href":"https:\/\/cssdeck.com\/blog\/wp-json\/wp\/v2\/posts\/2381\/revisions\/2384"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/cssdeck.com\/blog\/wp-json\/wp\/v2\/media\/2383"}],"wp:attachment":[{"href":"https:\/\/cssdeck.com\/blog\/wp-json\/wp\/v2\/media?parent=2381"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/cssdeck.com\/blog\/wp-json\/wp\/v2\/categories?post=2381"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/cssdeck.com\/blog\/wp-json\/wp\/v2\/tags?post=2381"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}