6

Material Design Icons

(Icon fonts not sized correctly)


I know I can fix them w/ css (I've done that below in the code snippet). But why? Is there a CSS technique I can add to the style sheet so this won't happen?

Google recommends that you set your Material Design icons to these sizes:

    .material-icons.md-18 { font-size: 18px; }
    .material-icons.md-24 { font-size: 24px; }
    .material-icons.md-36 { font-size: 36px; }
    .material-icons.md-48 { font-size: 48px; }

But when doing so, the material icons are distorted on 'Desktop' screens. 'Mobile' screens have no problem because of the DPI resolution is better. This problem of course, doesn't only exist with font-icons but other web fonts as well (Roboto, being one of the more popular ones).

Am I doing something wrong here? What's the best way to approach this?

Here's an image of what I'm seeing on my screen

(you'll have to open it up in new window to see full resolution):


enter image description here

Here's my code:

/* Reset */
*, *:after, *:before, *:focus { margin: 0; padding: 0; box-sizing: border-box; outline: 0; }
html { font-family: "Arial"; }
body { padding: 2rem; }
h1 { padding: 0 0 1rem; }
h3 { padding: 0 0 1rem; }
ul { list-style: none; }
section { padding: 1rem; margin: 0 0 1rem; }


/* Material Design Icons */
@font-face {
  font-family: 'Material Icons';
  font-style: normal;
  font-weight: 400;
  src: local('Material Icons'), local('MaterialIcons-Regular'), url(https://fonts.gstatic.com/s/materialicons/v14/2fcrYFNaTjcS6g4U3t-Y5ZjZjT5FdEJ140U2DJYC3mY.woff2) format('woff2');
}


.material-icons {
  font-family: 'Material Icons';
  font-weight: normal;
  font-style: normal;
  font-size: 24px;
  line-height: 1;
  letter-spacing: normal;
  text-transform: none;
  display: inline-block;
  white-space: nowrap;
  word-wrap: normal;
  direction: ltr;
  -webkit-font-feature-settings: 'liga';
  -webkit-font-smoothing: antialiased;
}


/* Icon Sizes (BAD) */    
.md-18 { font-size: 18px; } 
.md-24 { font-size: 24px; } 
.md-36 { font-size: 36px; } 
.md-48 { font-size: 48px; }


/* Icon Sizes (GOOD) */    
.md-14 { font-size: 14px; }
.md-29 { font-size: 29px; } 
.md-34 { font-size: 34px; }
.md-44 { font-size: 44px; }
.md-48 { font-size: 48px; }

/* Bad - Good */
.bad { background: rgba(235, 90, 70, .47); }
.good { background: rgba(81, 232, 152, .47); }
<h1>Material Design Icons</h1>

<section class="bad">
  <h3>Bad (Google reccommends)</h3>
  <ul>
    <li>
      <span>Font Size: 18px</span> <i>(.md-18)</i>
      <i class="material-icons md-18">dehaze</i>
    </li>
    <li>
      <span>Font Size: 24px</span> <i>(.md-24)</i>
      <i class="material-icons md-24">dehaze</i>
    </li>
    <li>
      <span>Font Size: 36px</span> <i>(.md-36)</i>
      <i class="material-icons md-36">dehaze</i>
    </li>
    <li>
      <span>Font Size: 48px</span> <i>(.md-48)</i>
      <i class="material-icons md-48">dehaze</i>
    </li>
  </ul>
</section>

<section class="good">
  <h3>Good</h3>
  <ul>
    <li>
      <span>Font Size: 14px</span> <i>(.md-14)</i>
      <i class="material-icons md-14">dehaze</i>
    </li>
    <li>
      <span>Font Size: 29px</span> <i>(.md-29)</i>
      <i class="material-icons md-29">dehaze</i>
    </li>    
    <li>
      <span>Font Size: 34px</span> <i>(.md-34)</i>
      <i class="material-icons md-34">dehaze</i>
    </li>
    <li>
      <span>Font Size: 44px</span> <i>(.md-44)</i>
      <i class="material-icons md-44">dehaze</i>
    </li>
    <li>
      <span>Font Size: 48px</span> <i>(.md-48)</i>
      <i class="material-icons md-48">dehaze</i>
    </li>
  </ul>
</section>
Oneezy
  • 4,881
  • 7
  • 44
  • 73
  • Just you. Both of your examples in the snippet show up totally fine on my screen. – ArtOfCode Mar 31 '16 at 20:16
  • They work for me as well on Chrome, 1920x1080. – Steven Scott Mar 31 '16 at 21:42
  • 3
    It's not just you dude, I see what you mean on mine so +1 there. That is interesting, will have to look into resolution/PPI of the hardware if these other guys are saying it looks fine for them. – Chris W. Mar 31 '16 at 22:03
  • That's why I provided the image, you should be able to see the problem there. I know it's a vector scaling down problem..but I was hoping for a possible css 'smoothing' solution. .I'm running Windows 10 OS btw.. 1920x1080 as well – Oneezy Apr 01 '16 at 00:27

0 Answers0