【47-4】text-decorationショートハンドプロパティでまとめて指定
最終更新日:2019年07月03日 (初回投稿日:2019年04月12日)
text-decoration ショートハンドプロパティは、
text-decoration-line
text-decoration-color
text-decoration-style
の値をまとめて指定することができます。
上記3つのプロパティの記事はこちらです。
- 【47-1】テキストのライン装飾の種類を決める text-decoration-line
- 【47-2】テキストのライン装飾の色を決める text-decoration-color
- 【47-3】テキストのライン装飾を波線にもできる text-decoration-style
- 【47-4】text-decorationショートハンドプロパティでまとめて指定 ←今日はココ
text-decorationプロパティは CSS 2まではショートハンドではありませんでした。
値は text-decoration-line の値(none、underline、overline、line-through、blink)のみ。
それが CSS 3(Text Decoration Module Level 3 )から、新しくtext-decoration-line、text-decoration-color、text-decoration-styleプロパティができて、text-decorationプロパティはショートハンドプロパティになりました。
text-decorationショートハンドプロパティは、Chrome, Firefox, Opera は対応。
Safari(iOS Safari も含む)は、ベンダープレフィックス「-webkit-」付きで対応。ただし text-decoration-styleの一部の値には未対応です。
IE, Edge は、CSS 2 での text-decorationプロパティ(ショートハンドになる前)に対応しています。(参考:Can I use 2019年4月記)
参考:
・CSS Text Decoration Module Level 3 | W3C Candidate Recommendation
・text-decoration - CSS | MDN
text-decorationショートハンドのルール
どのショートハンドでも同じですが、ショートハンドで省略された値は「デフォルト値」になります。
その他の注意点は以下の2点です。
text-decoration は伝播し、指定は追加される
親要素に指定された text-decorationは、子要素のインライン要素では外すことができません。
例えば、下のようなソースコードで、
<p>アンダーライン <span>デコレーション無し</span></p>
<style>
p {text-decoration: underline;}
span {text-decoration: none;}
</style>
プレビューはこのように、<span>要素のアンダーラインは無くなりません。
アンダーライン デコレーション無し
<span>要素に新しいラインを指定すれば、
p {text-decoration: underline;}
span {text-decoration: overline;}
プレビューはこのように、<span>要素のラインが追加されます。
アンダーライン オーバーライン
CSS 2 の書き方も併用する
CSS2 での text-decorationプロパティ(ショートハンドになる前)に対応しているブラウザは、text-decoration-line の値(none、underline、overline、line-through、blink)のみが text-decorationプロパティで指定できます。
CSS 3 での書き方(複数の値を「半角スペース」で区切って指定)をすると、CSS 2 対応のブラウザでは無視されます。
ですので、下記のように text-decorationショートハンドプロパティの記述の前に、CSS 2 での text-decorationプロパティの記述もしておくのがベストな指定だそうです。
a {
color: #0ff;
text-decoration: underline; /*css2での指定*/
text-decoration: red dotted underline; /*css3での新しい指定(CSS2対応ブラウザは無視)*/
}
text-decorationショートハンドの指定サンプル
ショートハンドでの指定サンプルです。
サンプルのソースコードはこちら。
<div class="mihon">
<p><a href="#pt2" class="sample1"><a>要素の underline の指定</a></p>
<p><ins class="sample2"><ins>要素の underline の指定</ins></p>
<p><del class="sample3"><del>要素の line-through の指定</del></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 {
text-decoration:underline;
-webkit-text-decoration:underline skyblue solid;
text-decoration:underline skyblue solid}
ins.sample2 {
text-decoration:underline;
-webkit-text-decoration:underline overline #b8e600 wavy;
text-decoration:underline overline #b8e600 wavy}
del.sample3 {
text-decoration:line-through;
-webkit-text-decoration:line-through hsla(0,100%,45%,0.5) double;
text-decoration:line-through hsla(0,100%,45%,0.5) double}
</style>
次回予告
テキストデコレーションに関するプロパティは、まだいくつか残っているのですが、ここで一旦区切ります。
で、次回から2回ほど HTMLの要素について書きます。
HTML5.1 から実装された <picture>要素を放置しているので、これを書きたいのですが、その前に <img>要素について まとめておきたいと思います。
次回は <img>要素について。
HTML5.1で追加された「srcset属性」を使って複数の画像ファイルを指定し、条件に合わせてブラウザに画像を選ばせることができるようになったので、とても便利です。
その後で、また CSS に戻ります。
その時はテキストデコレーション繋がりで text-decoration-skipプロパティをやる予定です。
- 関連記事
-
- 【51】テキストの強調マークの位置を決める text-emphasis-position
- 【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
初心者にも使いやすい(と思う)レンタルサーバー
「初心者ですがレンタルサーバーはどこがいい?」というご質問をよくいただきます。
自由にファイルをアップロードできる自分のサーバがあると便利ですよね。ローカル環境じゃなくサーバ上で試してみたい時がありますからね。
私が使っているのは、
スターサーバーや ロリポップ!
です。どちらも管理画面がわかりやすく、マニュアルも充実していて、料金も安い。どちらもライトプラン以上で WordPress が使えます。
初心者が始めやすいサーバだと思います。
ちょっと料金は高いけど、さくらのレンタルサーバや、エックスサーバー
は、やはり老舗なのでおすすめです。
両方とも高スペックでコスパが良く、老舗でユーザーが多いので、質問する場がたくさんあります。初心者だけど仕事でサーバが欲しい場合は、安心なのではないかと思います。
スポンサーリンク