text-shadow

3 位贡献者:

概述

The text-shadow property adds shadows to text. It accepts a comma-separated list of shadows to be applied to the text and text-decorations of the element.

Each shadow is specified as an offset from the text, along with optional color and blur radius values.

Multiple shadows are applied front-to-back, with the first-specified shadow on top.

This property applies to both ::first-line and ::first-letter pseudo-elements.

text-shadow 为文字添加阴影。可以为文字与  text-decorations  添加多个阴影,阴影值之间用逗号隔开。

每个阴影指定相对文字的偏移量,可选的颜色及模糊半径。

多个阴影从前往后叠加,第一个阴影在最前面。

语法

/* offset-x | offset-y | blur-radius | color */
text-shadow: 1px 1px 2px black; 

/* color | offset-x | offset-y | blur-radius */
text-shadow: #CCC 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;

text-shadow: inherit;

取值

<color>
Optional. Can be specified either before or after the offset values. If the color is not specified, a UA-chosen color will be used.
Note: If you want to ensure consistency across browsers, explicitly specify a color.
<offset-x> <offset-y>
Required. These <length> values specify the shadow's offset from the text. <offset-x> specifies the horizontal distance; a negative value places the shadow to the left of the text.<offset-y> specifies the vertical distance; a negative value places the shadow above the text. If both values are 0, then the shadow is placed behind the text (and may generate a blur effect when <blur-radius> is set).
To find out what units you can use, see <length>.
<blur-radius>
Optional. This is a <length> value. If not specified, it defaults to 0. The higher this value, the bigger the blur; the shadow becomes wider and lighter.
<color>
可选。位于偏移量前面或后面。如果没有指定颜色,则UA(用户代理)自行选择。
Note: 如果想让各浏览器保持一致,则应指定颜色
<offset-x> <offset-y>
必选。这些长度值指定阴影相对文字的偏移量。<offset-x> 指定水平偏移量,若是负值则阴影位于文字左边。 <offset-y> 指定垂直偏移量,若是负值则阴影位于文字上面。如果两者均为0,则阴影位于文字后面(如果设定了<blur-radius> 则会有模糊效果)。
单位查看 <length>
<blur-radius>
可选。这是 <length> 值。如果没有指定则为0。值越大,模糊半径越大,阴影也就越大越淡。

形式化语法

none | <shadow-t>#

例子

.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>
 
 
 
 

.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>
 
 
 
 

.gold-on-gold {
   text-shadow: rgba(0,0,0,0.1) -1px 0, rgba(0,0,0,0.1) 0 -1px,
   rgba(255,255,255,0.1) 1px 0, rgba(255,255,255,0.1) 0 1px,
   rgba(0,0,0,0.1) -1px -1px, rgba(255,255,255,0.1) 1px 1px; 
   color: gold;
   background: gold;
}
 
 
 
 
 
 
 
<p class="gold-on-gold">
   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>
 
 
 
 

规范

Specification Status Comment
CSS Transitions
text-shadow
Working Draft Lists text-shadow as animatable.
Unknown
text-shadow
Unknown  

The CSS property text-shadow was improperly defined in CSS2and dropped in CSS2 (Level 1). The CSS Text Module Level 3 spec improved and precised the syntax. Later it was moved to new working draft CSS Text Decoration Module Level 3.

浏览器兼容性

Feature Chrome Firefox (Gecko) Internet Explorer Opera Safari (WebKit)
Basic support 2.0.158.0 3.5 (1.9.1) 10 9.5 1.1 (100)
Feature Android Firefox Mobile (Gecko) IE Phone Opera Mobile Safari Mobile
Basic support ? ? ? ? ?
  • Gecko (Firefox) theoretically supports infinite text-shadows (don't try it).
    Gecko 2 and later cap the blur radius at 300 for performance reasons.
    If the <color> value is unspecified, then Gecko uses the value of the element's color property.
  • Opera supports a maximum of 6-9 text-shadows for performance reasons. The blur radius is limited to 100px.
    Opera 9.5-10.1 adheres to the old, reverse painting order (CSS2, the first specified shadow is on the bottom).
  • Internet Explorer 5.5 supports Microsoft's Shadow andDropShadow Filter.
  • Safari: Any shadows that do not explicitly specify a color are transparent.
    Safari 1.1-3.2 only supports one text-shadow (displays the first shadow of a comma-separated list and ignores the rest).
    Safari 4.0 (WebKit 528) and later support multiple text-shadows.
  • Konqueror supports text-shadow starting with version 3.4.

参见

 

文档标签和贡献者

向此页面作出贡献: FredWe, teoli, yan
最后编辑者: FredWe,