--- title: text-shadow slug: Web/CSS/text-shadow tags: - CSS - CSS Styles - CSS Text Decoration translation_of: Web/CSS/text-shadow ---
text-shadow
为文字添加阴影。可以为文字与 {{ cssxref("text-decoration","text-decorations") }} 添加多个阴影,阴影值之间用逗号隔开。每个阴影值由元素在X和Y方向的偏移量、模糊半径和颜色值组成。
{{EmbedInteractiveExample("pages/css/text-shadow.html")}}
/* offset-x | offset-y | blur-radius | color */ text-shadow: 1px 1px 2px black; /* color | offset-x | offset-y | blur-radius */ text-shadow: #fc0 1px 0 10px; /* offset-x | offset-y | color */ text-shadow: 5px 5px #558abb; /* color | offset-x | offset-y */ text-shadow: white 2px 5px; /* offset-x | offset-y /* Use defaults for color and blur-radius */ text-shadow: 5px 10px; /* Global values */ text-shadow: inherit; text-shadow: initial; text-shadow: unset;
当阴影大于一个时要用逗号区别开阴影之间的参数
每个阴影都有两到三个<length>
参数 , 以及一个与阴影颜色相关的<color>
参数 。 前两个<length>
参数,是以“文字中心”为原点的坐标轴,分别为x轴 <offset-x>
和y轴 <offset-y>
的值; 如果有第三个<length>
参数,则第三个数值为形成阴影效果的半径的数值 <blur-radius>
。
当所给的阴影大于一个时,阴影应用的顺序为从前到后, 第一个指定的阴影在顶部.
这个属性同时适用于{{cssxref("::first-line")}} 以及 {{cssxref("::first-letter")}} 伪元素.
<offset-x> <offset-y>
<offset-x>
指定水平偏移量,若是负值则阴影位于文字左边。 <offset-y>
指定垂直偏移量,若是负值则阴影位于文字上面。如果两者均为0,则阴影位于文字正后方(如果设置了<blur-radius>
则会产生模糊效果)。<blur-radius>
.red-text-shadow { text-shadow: red 0 -2px; }
<p class="red-text-shadow"> Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium, totam rem aperiam, eaque ipsa quae ab illo inventore veritatis et quasi architecto beatae vitae dicta sunt explicabo. </p>
{{EmbedLiveSample('Simple_shadow', '689px', '90px')}}
.white-with-blue-shadow { text-shadow: 1px 1px 2px black, 0 0 1em blue, 0 0 0.2em blue; color: white; font: 1.5em Georgia, "Bitstream Charter", "URW Bookman L", "Century Schoolbook L", serif; }
<p class="white-with-blue-shadow"> Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium, totam rem aperiam, eaque ipsa quae ab illo inventore veritatis et quasi architecto beatae vitae dicta sunt explicabo. </p>
{{EmbedLiveSample('Multiple_shadows', '689px', '180px')}}
Specification | Status | Comment |
---|---|---|
{{SpecName('CSS3 Transitions', '#animatable-css', 'text-shadow')}} | {{Spec2('CSS3 Transitions')}} | Specifies text-shadow as animatable. |
{{SpecName('CSS3 Text Decoration', '#text-shadow', 'text-shadow')}} | {{Spec2('CSS3 Text Decoration')}} | The CSS property text-shadow was improperly defined in CSS2 and dropped in CSS2 (Level 1). The CSS Text Module Level 3 spec refined the syntax. Later it was moved to CSS Text Decoration Module Level 3. |
{{cssinfo}}
{{Compat("css.properties.text-shadow")}}