LoginSignup
7

More than 5 years have passed since last update.

アイコンフォントをCSSで細くする(webkit限定)

Last updated at Posted at 2016-11-01

CSSのみでアイコンフォントの太さを変えたいけど、font-weightが効かないときの対応。
(Chromeで動作確認してます)

方法

→ 以下を付与する。

-webkit-text-stroke: 2px white
  • 2px … この幅だけ細くなる
  • white … 背景色に合わせる

縁取り用のwebkit-text-strokeが内部に食い込むことを利用して、色を背景と合わせることで、細くなったように見せる。

サンプル

<!DOCTYPE html>
<html>
<head>
  <link rel="stylesheet" href="https://fonts.googleapis.com/icon?family=Material+Icons">
  <style type="text/css">
    .material-icons {
      font-size: 5rem;
    }
    .material-icons.slim {
      -webkit-text-stroke: 0.2rem white;
    }
  </style>
</head>
<body>
  <i class="material-icons">language</i>
  <i class="material-icons slim">language</i>
</body>
</html>

見え方
キャプチャ.PNG

参考: https://codepen.io/mackdoyle/pen/yrgEH

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
7