<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Nick Noordijk on Medium]]></title>
        <description><![CDATA[Stories by Nick Noordijk on Medium]]></description>
        <link>https://medium.com/@nicknoordijk?source=rss-8dfa4072755a------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*U7_KCrN036GMv9q4marWog.jpeg</url>
            <title>Stories by Nick Noordijk on Medium</title>
            <link>https://medium.com/@nicknoordijk?source=rss-8dfa4072755a------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 22 Nov 2026 12:59:48 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@nicknoordijk/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Inline SVG hover states with CSS (<use> tag)]]></title>
            <link>https://medium.com/@nicknoordijk/inline-svg-hover-states-with-css-use-tag-4a336ed75062?source=rss-8dfa4072755a------2</link>
            <guid isPermaLink="false">https://medium.com/p/4a336ed75062</guid>
            <dc:creator><![CDATA[Nick Noordijk]]></dc:creator>
            <pubDate>Sat, 04 Oct 2014 14:29:25 GMT</pubDate>
            <atom:updated>2014-10-15T07:01:23.743Z</atom:updated>
            <content:encoded><![CDATA[<h2>Inline SVG hover states<br>with CSS (&lt;use&gt; tag)</h2><p>The article is about a <em>really, really, really! </em>simple hover states trick when you use SVG’s with the &lt;use&gt; tag.</p><h3>The problem</h3><p>At the time of creating this little trick I nearly hadn’t any knowledge of SVG’s. The project I was working on, was that big that it literally screamed to use icons like an icon font generated with <a href="https://www.icomoon.io/">IcoMoon</a>.</p><p>But something was bothering me about the icon fonts. At several projects some icons where, for an unknown reason, more blurry than other icons in that the generated font.</p><p><em>Arghhh! Why?</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/480/1*32xHIIj0ImQfln43Ru1mOA.gif" /></figure><p>I found <a href="http://css-tricks.com/icon-fonts-vs-svg/">an article</a> from <a href="https://twitter.com/chriscoyier">Chris Coyier</a> about Inline SVG’s versus Icon Fonts. Where he directly pointed out my problem.</p><blockquote>In a recent personal example, while converting some icons from fonts to SVG on CodePen, some of the font icons were noticeably less sharp than the ones I converted over.</blockquote><p>This article made me make the switch to inline SVG’s. Because there was a need of fully sharp icons in all situations. Keep in mind that inline SVG’s aren’t supported by IE8, but hey who is supporting this anyway?</p><h3>The Task</h3><p>But there was one more challenge. How could I simply create a hover effect on an SVG with the knowledge I had about it those days?<br>I needed <a href="http://nicknoordijk.me/blog/inline-svg-hover-states-css-tag/#states">4 kind of states</a>:</p><ul><li>Default</li><li>Hover</li><li>Active</li><li>Active - hover</li></ul><h4>Creating icons</h4><p>I generated the SVG sprite with IcoMoon which is making use of the &lt;use&gt; tag. The next step was combining some SVG’s to make a “like” button which, in this case, I was working on.</p><pre>&lt;svg class=&quot;icon&quot; viewBox=&quot;0 0 32 32&quot;&gt;<br>    &lt;use xlink:href=&quot;#icon-like-default&quot;&gt;&lt;/use&gt;<br>    &lt;use xlink:href=&quot;#icon-like-hover&quot;&gt;&lt;/use&gt;<br>    &lt;use xlink:href=&quot;#icon-like-active&quot;&gt;&lt;/use&gt;<br>    &lt;use xlink:href=&quot;#icon-like-active-hover&quot;&gt;&lt;/use&gt;<br>&lt;/svg&gt;</pre><p>As you can imagine the icons are all displayed on top of each other. <a href="http://nicknoordijk.me/blog/simple-svg-hover-states/#svg">Demo</a> Next I added the <a href="http://nicknoordijk.me/blog/simple-svg-hover-states/#states">states</a> as classnames, like:</p><pre>&lt;svg class=&quot;icon&quot; viewBox=&quot;0 0 32 32&quot;&gt;<br>    &lt;use class=&quot;default&quot; xlink:href=&quot;#icon-like-default&quot;&gt;&lt;/use&gt;<br>    &lt;use class=&quot;hover&quot; xlink:href=&quot;#icon-like-hover&quot;&gt;&lt;/use&gt;<br>    &lt;use class=&quot;active&quot; xlink:href=&quot;#icon-like-active&quot;&gt;&lt;/use&gt;<br>    &lt;use class=&quot;active-hover&quot; xlink:href=&quot;#icon-like-active-hover&quot;&gt;   &lt;/use&gt;<br>&lt;/svg&gt;</pre><h4>Hide and Seek</h4><p>Now CSS must help us do the trick. First I created 2 <a href="http://csswizardry.com/2014/01/extending-silent-classes-in-sass/">silent classes</a>. (SCSS)<br>This is just a opacity switch. You could also use display:none/block; but in this case I had to add opacity to create some awesome transitions. :’)</p><pre>%icon{<br>    &amp;-is-shy{<br>        opacity: 0;<br>    }<br>    &amp;-isnt-shy{<br>        opacity: 1;<br>    }<br>}</pre><p>After that I add the states as classnames in <a href="http://sass-lang.com/">SCSS</a> as children of the .icon class. Hide them by default except the default icon of course.</p><pre>.hover, .active, .active-hover{<br>    @extend %icon-is-shy;<br>}</pre><p>Followed up by adding the different states:</p><p><strong><em>:hover<br></em></strong>It says; Only trigger me when I don’t have the ‘active’ class.</p><pre>&amp;:not(.active):hover{<br>    <br>    .hover{<br>        @extend %icon-isnt-shy;<br>    }</pre><pre>    .default{<br>        @extend %icon-is-shy;<br>    }<br>}</pre><p><strong><em>Active</em></strong></p><pre>&amp;.active{<br>    .default{<br>        @extend %icon-is-shy;<br>    }</pre><pre>    .active{<br>        @extend %icon-isnt-shy;<br>    }<br>}</pre><p><strong><em>Active :hover</em></strong></p><pre>&amp;.active:hover{<br>    .active{<br>        @extend %icon-is-shy;<br>    }<br> <br>    .active-hover{<br>        @extend %icon-isnt-shy;<br>    }<br>}</pre><h4>Making it work</h4><p>The last part is a tiny part of <a href="http://nicknoordijk.me/blog/inline-svg-hover-states-css-tag/#javascript">JavaScript</a> that triggers a class on the SVG tag. Which will add the .active class.</p><pre>$(“.icon”).click( function() { <br>    var c = $(this).attr(‘class’);<br> <br>    if(c == “icon active”){<br>        $(this).attr(‘class’, ‘icon’);<br>        return true;<br>    }<br> <br>    $(this).attr(‘class’, ‘icon active’);<br>});</pre><h3>Demotime</h3><p>See that simplicity in action:<br><a href="http://nicknoordijk.me/blog/inline-svg-hover-states-css-tag/">nicknoordijk.me/blog/inline-svg-hover-states-css-tag/</a></p><p><strong>P.S. : </strong>This is my very first writing on the web, so tips are welcome!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4a336ed75062" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>