CSS3 には、いくつかの新しいテキスト機能が含まれています。
この章では、次のテキストプロパティについて説明します:
text-overflow
word-wrap
word-break
表中の数字は、完全にプロパティをサポートした最初のブラウザのバージョンです。
数字の後に続く -o- は、接頭辞付きで動作した最初のバージョンです。
プロパティ | |||||
---|---|---|---|---|---|
text-overflow | 4.0 | 6.0 | 7.0 | 3.1 | 11.0 9.0 -o- |
word-wrap | 23.0 | 5.5 | 3.5 | 6.1 | 12.1 |
word-break | 4.0 | 5.5 | 15.0 | 3.1 | 15.0 |
CSS3 text-overflow
プロパティは、表示されないオーバフローしたコンテンツをどのように表すべきかを指定します。
切り取ることができます:
It can be clipped:
This is some long text that will not fit in the box
または、省略記号(...)としてレンダリングすることができます:
This is some long text that will not fit in the box
CSS コードは次の通りです:
p.test1 {
white-space: nowrap;
width: 200px;
border: 1px solid #000000;
overflow: hidden;
text-overflow: clip;
}
p.test2 {
white-space: nowrap;
width: 200px;
border: 1px solid #000000;
overflow: hidden;
text-overflow: ellipsis;
}
Try it Yourself ❯
次の例は、要素の上にマウスを移動したとき、オーバフローしたコンテンツを表示する方法を示しています:
CSS3 word-wrap
プロパティは、長い単語を分割して、次の行に折り返すことができるようにします。
エリア内に収まりきれないほど単語が長すぎる場合、外側にはみ出してしまいます:
This paragraph contains a very long word: thisisaveryveryveryveryveryverylongword. The long word will break and wrap to the next line.
word-wrap プロパティは、強制的にテキストの折り返しを可能にします - これは、単語の中央であっても分割することを意味します:
This paragraph contains a very long word: thisisaveryveryveryveryveryverylongword. The long word will break and wrap to the next line.
CSS コードは次の通り:
CSS3 word-break
プロパティは、改行規則を指定します。
This paragraph contains some text. This line will-break-at-hyphens.
This paragraph contains some text. The lines will break at any character.
CSS コードは次の通り:
Exercise 1 ❯ Exercise 2 ❯ Exercise 3 ❯
次の表は、新しい CSS3 テキストプロパティのリストです:
プロパティ | 説明 |
---|---|
text-align-last | テキストの最終行の配置方法を指定する |
text-emphasis | 1 回の宣言で text-emphasis-style と text-emphasis-color を設定するためのショートハンドプロパティ |
text-justify | 均等割付のテキストをどのように配置し、間隔を置くかを指定する |
text-overflow | 表示されないオーバフロー・コンテンツをどう表すべきかを指定する |
word-break | 非-CJK スクリプトへ改行ルールを指定する |
word-wrap | 長い単語を改行して、次の行に折り返すことを可能にする |