ひとりCSS Advent Calendar 2022 1日目です。
text-decoration関連のプロパティを学び直します。
text-decoration プロパティ
-
text-decorationとはテキストを装飾するプロパティ- a 要素(リンク)にアンダーラインをつけるかつけないかといった指定をすることが多い
- もちろん他の要素にも使える
- a 要素(リンク)にアンダーラインをつけるかつけないかといった指定をすることが多い
-
text-decorationはショートハンドだった- (知らなかった)
- 以下をまとめて指定できる
-
text-decoration-line- 線の位置-
none(なし) -
underline(下線) -
overline(上の線) -
line-through(文字の中央) -
underline overlineのように空白スペースで区切ることで複数設定も可能
-
-
text-decoration-color- 線の色 -
text-decoration-style- 線の種類-
solid(単独線) -
double(二重線) -
dotted(点線) -
dashed(破線) -
wavy(波線)
-
-
text-decoration-thickness太さ
-
text-underline-offsetプロパティ
-
text-decoration: underlineを設定した場合、text-underline-offset線と文字の距離を広げることが可能- 今まで
text-decorationではなく、padding-bottomborder-bottomの両方を設定することで調整していた- このような設定をしなくて済む
- 今まで
Codepen
text-decoration で遊んでみた。
See the Pen text-decoration by Beco (@becolomochi) on CodePen.
感想
- ショートハンドなの知らなかった
- 波線かわいい
- 線の色もショートハンド内で変えられて便利
- 複数の線は設定できるが、色や形状は線それぞれに指定できない様子だった
