Font Awesomeでラジオボタンをデザインしてみる
公開日 更新日
前回の「Font Awesomeでcheckboxをデザインしてみる」の記事の続きの内容になります。
ラジオボタンのデザインも「Font Awesome」を利用すると、簡単にいい感じのものが作れます。
Font Awesomeを使ったラジオボタンのデザインをいくつか紹介していきます。
Font Awesomeの読み込み
読み込み方は、前回の記事と同じです。<head>内に次の1行を追加します。(この記事では、バージョン7.3.1で動作を確認しています。)
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/7.3.1/css/all.min.css">
CSSのfont-familyには"Font Awesome 7 Free"を指定します。
Font Awesomeを使ったラジオボタンのデザイン
基本デザイン
<label>
<input type="radio" name="radio1" class="radiobutton">
<span class="radio-fontas"></span>ラジオボタン1
</label>
<label>
<input type="radio" name="radio1" class="radiobutton">
<span class="radio-fontas"></span>ラジオボタン2
</label>
.radiobutton {
display: none;
}
label {
display:block;
}
.radio-fontas {
vertical-align: middle;
font-size: 22px;
}
.radiobutton + .radio-fontas:before {
font-weight: 900;
font-family: "Font Awesome 7 Free";
color: #ccc;
content: '\f192';
}
.radiobutton:checked + .radio-fontas:before {
color: #2db29c;
}
デザイン2
基本デザインのcontent: '\f192';の部分をcontent: '\f111';に変更するだけです。
デザイン3
content: '\f1ce';に変更します。
デザイン4
content: '\f2bd';に変更します。
以上がFont Awesomeの主要なラジオボタンのデザインでした。Font AwesomeのPROならもっと多くのデザインがありますよ。