--- title: box-shadow slug: Web/CSS/box-shadow tags: - CSS - CSS Backgrounds and Borders - CSS Property - CSS Styles - HTML Colors - Reference - Shadows - Styles - Styling HTML - box-shadow translation_of: Web/CSS/box-shadow ---
{{CSSRef}}
box-shadow
屬性為一個逗號分隔的列表描述一個或多個的陰影效果. 這使的你能夠從幾乎任何元素的框架放入陰影. 如果一個標記了 {{cssxref("border-radius")}} 的元素也標記了 box shadow, 這將使得他們有相同的圓邊. 多重 box shadows 的 z-index 排序跟多重 text shadows 一樣(第一個備標記的陰影在最上面).
{{cssinfo}}
Interactive tool 可以產生 box-shadow.
/* offset-x | offset-y | color */ box-shadow: 60px -16px teal; /* offset-x | offset-y | blur-radius | color */ box-shadow: 10px 5px 5px black; /* offset-x | offset-y | blur-radius | spread-radius | color */ box-shadow: 2px 2px 2px 1px rgba(0, 0, 0, 0.2); /* inset | offset-x | offset-y | color */ box-shadow: inset 5em 1em gold; /* Any number of shadows, separated by commas */ box-shadow: 3px 3px red, -1em 0 0.4em olive;
inset
<offset-x> <offset-y>
<blur-radius>
spread-radius
>color
>box-shadow: rgba(0, 0, 0, 0.35) 0px 5px 15px;
box-shadow: 60px -16px teal;
box-shadow: 10px 5px 5px black;
box-shadow: 3px 3px red, -1em 0 0.4em olive;
box-shadow: inset 5em 1em gold;
box-shadow: 0 0 1em gold;
box-shadow: inset 0 0 1em gold;
box-shadow: inset 0 0 1em gold, 0 0 1em red;
Specification | Status | Comment |
---|---|---|
{{SpecName('CSS3 Backgrounds', '#box-shadow', 'box-shadow')}} | {{Spec2('CSS3 Backgrounds')}} | Initial definition |
{{CompatibilityTable}}
Feature | Chrome | Firefox (Gecko) | Internet Explorer | Opera | Safari |
---|---|---|---|---|---|
Basic support | 10.0[1] 1.0{{property_prefix("-webkit")}} |
{{CompatGeckoDesktop("2.0")}}[3] {{CompatGeckoDesktop("1.9.1")}}{{property_prefix("-moz")}} |
9.0[2] | 10.5[1] | 5.1[1] 3.0 {{property_prefix("-webkit")}} |
Multiple shadows | 10.0 1.0{{property_prefix("-webkit")}} |
{{CompatGeckoDesktop("2.0")}} {{CompatGeckoDesktop("1.9.1")}}{{property_prefix("-moz")}} |
9.0 | 10.5 | 5.1 3.0 {{property_prefix("-webkit")}} |
inset keyword |
10.0 4.0{{property_prefix("-webkit")}} |
{{CompatGeckoDesktop("2.0")}} {{CompatGeckoDesktop("1.9.1")}}{{property_prefix("-moz")}} |
9.0 | 10.5 | 5.1 5.0 {{property_prefix("-webkit")}} |
Spread radius | 10.0 4.0{{property_prefix("-webkit")}} |
{{CompatGeckoDesktop("2.0")}} {{CompatGeckoDesktop("1.9.1")}}{{property_prefix("-moz")}} |
9.0 | 10.5 | 5.1 5.0 {{property_prefix("-webkit")}} |
Feature | Safari Mobile | Opera Mini | Opera Mobile | Android |
---|---|---|---|---|
Basic support |
5.0[1] |
{{CompatUnknown}} | {{CompatVersionUnknown }}[1] | {{CompatVersionUnknown }}{{property_prefix("-webkit")}}[1] |
Multiple shadows | 5.0 {{CompatVersionUnknown }}{{ property_prefix("-webkit")}} |
{{CompatUnknown}} | {{CompatUnknown}} | {{CompatUnknown}} |
inset keyword |
5.0 {{CompatVersionUnknown }}{{ property_prefix("-webkit")}} |
{{CompatUnknown}} | {{CompatUnknown}} | {{CompatUnknown}} |
Spread radius | 5.0 {{CompatVersionUnknown }}{{ property_prefix("-webkit")}} |
{{CompatUnknown}} | {{CompatUnknown}} | {{CompatUnknown}} |
[1] Shadows affect layout in older Gecko, Presto, and WebKit; e.g. if you cast an outer shadow to a box with a width
of 100%
, you'll see a scrollbar.
[2] Since version 5.5, Internet Explorer supports Microsoft's DropShadow and Shadow Filter. You can use this proprietary extension to cast a drop shadow (though the syntax and the effect are different from CSS3). In order to get box-shadow
in IE9 or later, you need to set {{cssxref("border-collapse")}} to separate
.
[3] Gecko 13 {{geckoRelease(13)}} removed support for -moz-box-shadow
. Since then, only the unprefixed version is supported. Shadows affect layout in older Gecko, Presto, and WebKit; e.g. if you cast an outer shadow to a box with a width
of 100%
, you'll see a scrollbar.