text-strokeプロパティ
プロパティtext-strokeは、テキストの文字の輪郭(ストローク)の色と太さを設定します。
値として、ストロークの太さとスペースを挟んでストロークの色を指定する必要があります。
構文
セレクタ {
text-stroke: ストロークの太さ ストロークの色;
}
基本的な例
シンプルなテキストの輪郭:
<div class="stroked-text">
Lorem ipsum dolor sit amet
</div>
.stroked-text {
font-size: 48px;
font-weight: bold;
-webkit-text-stroke: 2px red;
text-stroke: 2px red;
}
:
輪郭のみ
次に、テキストの色を背景色(この場合は白)と同じにしてみましょう。 結果として、輪郭のみが残ります:
<div class="stroked-text">
Lorem ipsum dolor sit amet
</div>
.stroked-text {
font-size: 48px;
font-weight: bold;
color: white;
-webkit-text-stroke: 2px black;
text-stroke: 2px black;
}
:
グラデーションの輪郭
プロパティbackground-clipを使用して、
グラデーションの輪郭を作成します:
<div class="gradient-stroke">
Lorem ipsum dolor sit amet
</div>
.gradient-stroke {
font-size: 42px;
font-weight: bold;
background: linear-gradient(to right, #ff8a00, #e52e71);
-webkit-background-clip: text;
background-clip: text;
color: transparent;
-webkit-text-stroke: 1px #333;
text-stroke: 1px #333;
}
:
多重輪郭
text-shadowを使用した二重輪郭の効果:
<div class="double-stroke">
Lorem ipsum dolor sit amet
</div>
.double-stroke {
font-size: 40px;
color: white;
-webkit-text-stroke: 3px #000;
text-stroke: 3px #000;
text-shadow:
0 0 5px #000,
0 0 10px #000;
}
:
アニメーション付き輪郭
輪郭が変化するアニメーションを追加します:
<div class="animated-stroke">
Lorem ipsum dolor sit amet
</div>
.animated-stroke {
font-size: 38px;
color: white;
-webkit-text-stroke: 1px #ff0000;
text-stroke: 1px #ff0000;
animation: pulse 2s infinite;
}
@keyframes pulse {
0% { -webkit-text-stroke: 1px #ff0000; text-stroke: 1px #ff0000; }
50% { -webkit-text-stroke: 3px #ff0000; text-stroke: 3px #ff0000; }
100% { -webkit-text-stroke: 1px #ff0000; text-stroke: 1px #ff0000; }
}
:
関連項目
-
テキストの文字の塗りつぶし色を設定するプロパティ
text-fill-color -
テキストの輪郭の色を設定するプロパティ
text-stroke-color -
テキストの輪郭の太さを設定するプロパティ
text-stroke-width