【47-3】テキストのライン装飾を波線にもできる text-decoration-style
最終更新日:2019年04月12日 (初回投稿日:2019年03月29日)text-decoration-styleプロパティは、そのまんま「テキストをデコレーションするためのラインのスタイル」を指定します。
ブラウザデフォルトでは、テキストのライン装飾の「スタイル」は 実線(solid) です。これを 波線(wavy) やら 点線(dotted) に変えたりできるってやつです。
text-decoration-styleプロパティは、Chrome, Firefox, Opera は対応。
Safari(iOS Safari も含む)は一部の値に未対応。そしてベンダープレフィックス「-webkit-」が必要です。
IE, Edge は、CSS2 の text-decorationプロパティ(ショートハンドになる前)に対応しており、text-decoration-styleには未対応です。
(参考:Can I use 2019年3月記)
テキストデコレーション関連のプロパティは text-decoration ショートハンドプロパティでまとめて指定することができます。今回も含めてテキスト デコレーション関連のプロパティの記事が続き、最後にショートハンドでの書き方をまとめます。
- 【47-1】テキストのライン装飾の種類を決める text-decoration-line
- 【47-2】テキストのライン装飾の色を決める text-decoration-color
- 【47-3】テキストのライン装飾を波線にもできる text-decoration-style ←今日はココ
- 【47-4】text-decorationショートハンドプロパティでまとめて指定
参考:
・CSS Text Decoration Module Level 3 | W3C Candidate Recommendation
・text-decoration-style - CSS | MDN
text-decoration-styleプロパティの値
text-decoration-styleプロパティの値は以下のものがあります。
text-decoration-styleプロパティの値 | |
---|---|
キーワード | solidがデフォルト値。 double、dotted、dashed、wavy |
グローバル値 | text-decoration-style: inherit; 親の値を継承(コレ書かなくても継承するけど) text-decoration-style: initial; 継承した親の値を解消しデフォルト値に戻す text-decoration-style: unset; 値を解除。親から継承されてるなら inherit、継承されてないなら initial と同じ動作 |
値の継承 | しない ただし「継承」ではなく ボックスツリーによる 「伝播(propagated)」はします。 親要素に指定すれば、子要素にも装飾は付きます。 |
適用できる要素 | すべての要素 |
---|
text-decoration-styleプロパティの指定サンプル
text-decoration-styleプロパティの値「solid、double、dotted、dashed、wavy」を使ってみます。
最初のほうにも書いたけど、IE, Edge, Safari 以外のブラウザで見てみてください。
<a>要素の underline のスタイル変更(double)
<ins>要素のブラウザデフォルトスタイル
<ins>要素の underline のスタイル変更(wavy)
<del>要素のブラウザデフォルトスタイル
<del>要素の line-through のスタイル変更(dashed)
<s>要素のブラウザデフォルトスタイル
<s>要素の line-through のスタイル変更(dotted)
サンプルのコードはこちら。
<div class="mihon">
<p><a href="#pt2"><a>要素のブラウザデフォルトスタイル</a></p>
<p><a href="#pt2" class="sample1"><a>要素の underline のスタイル変更(double)</a></p>
<p><ins><ins>要素のブラウザデフォルトスタイル</ins></p>
<p><ins class="sample2"><ins>要素の underline のスタイル変更(wavy)</ins></p>
<p><del><del>要素のブラウザデフォルトスタイル</del></p>
<p><del class="sample3"><del>要素の line-through のスタイル変更(dashed)</del></p>
<p><s><s>要素のブラウザデフォルトスタイル</s></p>
<p><s class="sample4"><s>要素の line-through のスタイル変更(dotted)</s></p>
</div>
<style>
.mihon {
color:black;
margin:1em 0;
border:solid 1px #ccc;
padding:.6em 1.4em;
}
.mihon p {
font-size:1rem;
line-height:2.8;
margin:0}
a.sample1 {
-webkit-text-decoration-style:double;
text-decoration-style:double}
ins.sample2 {
-webkit-text-decoration-style:wavy;
text-decoration-style:wavy}
del.sample3 {
-webkit-text-decoration-style:dashed;
text-decoration-style:dashed}
s.sample4 {
-webkit-text-decoration-style:dotted;
text-decoration-style:dotted}
</style>
ベンダープレフィックス「-webkit-」を付けた text-decoration-style の指定もしています。(24,27,30,33行目)
Safari はdouble(二重線)や wavy(波線)は「-webkit-」を付けることで反応するようです。dashed(破線)dotted(点線)はダメみたい。
Safari では、対応できない値は デフォルトの実線で表示されます。
IE, Edge は CSS2 での text-decorationプロパティ(ショートハンドになる前)にのみ反応します。
ですので、未対応のブラウザには実線とデフォルトカラーでライン装飾を表示できるように指定を工夫する必要があります。
その書き方は次回の text-decorationショートハンドプロパティでまとめます。
次回予告
ということで次回は ショートハンドプロパティになった text-decoration を使って、これまでの「line」「color」「style」の値をまとめて指定しましょう。
- 関連記事
-
- 【50-3】テキスト強調マークの種類と色のショートハンド text-emphasis
- 【50-2】テキストの強調マークの色を決める text-emphasis-color
- 【50-1】テキストの強調マークの種類を決める text-emphasis-style
- 【49】アンダーラインの位置を決める text-underline-position
- 【48-2】ライン装飾が文字を横切るかを決める text-decoration-skip-ink
- 【48-1】ライン装飾をしない対象を決める text-decoration-skip
- 【47-4】text-decorationショートハンドプロパティでまとめて指定
- 【47-3】テキストのライン装飾を波線にもできる text-decoration-style
- 【47-2】テキストのライン装飾の色を決める text-decoration-color
- 【47-1】テキストのライン装飾の種類を決める text-decoration-line
- 【46】テキストの方向性を操作する unicode-bidi と direction
- (ちょっとメモ)縦書きでの字下げ・下線・リストなどを試してみた
- 【45-3】縦書きで「縦中横」ができる text-combine-upright
- 【45-2】縦書きでの文字の向きを決める text-orientation
- 【45-1】日本語の縦書きもできちゃう writing-modeプロパティ
初心者にも使いやすい(と思う)レンタルサーバー
「初心者ですがレンタルサーバーはどこがいい?」というご質問をよくいただきます。
自由にファイルをアップロードできる自分のサーバがあると便利ですよね。ローカル環境じゃなくサーバ上で試してみたい時がありますからね。
私が使っているのは、
スターサーバーや ロリポップ!
です。どちらも管理画面がわかりやすく、マニュアルも充実していて、料金も安い。どちらもライトプラン以上で WordPress が使えます。
初心者が始めやすいサーバだと思います。
ちょっと料金は高いけど、さくらのレンタルサーバや、エックスサーバー
は、やはり老舗なのでおすすめです。
両方とも高スペックでコスパが良く、老舗でユーザーが多いので、質問する場がたくさんあります。初心者だけど仕事でサーバが欲しい場合は、安心なのではないかと思います。
スポンサーリンク