Home >Web Front-end >HTML Tutorial >Summary of CSS3 shadow box-shadow usage and techniques_html/css_WEB-ITnose
This article is excerpted from: http://blog.csdn.net/freshlover/article/details/7610269
text-shadow is to add a shadow effect to the text, and box-shadow is to add a surrounding shadow effect to the element block. With the popularity of html5 and CSS3, the use of this special effect is becoming more and more common.
The basic syntax is {box-shadow:[inset] x-offset y-offset blur-radius spread-radiuscolor}
Object selector {box-shadow: [Projection method] X-axis offset Y-axis offset shadow blur radius shadow extended radius shadow color}
The parameter setting value of the box-shadow attribute:
Shadow Type: This parameter is optional. If no value is set, the default projection method is outer shadow; if the unique value "inset" is taken, the projection is inner shadow;
X-offset: shadow horizontal offset, its value can be positive or negative . If the value is positive, the shadow is on the right side of the object. When the value is negative, the shadow is on the left side of the object;
Y-offset: vertical offset of the shadow, its value can also be positive or negative. . If it is a positive value, the shadow is at the bottom of the object. When its value is negative, the shadow is at the top of the object;
Shadow blur radius: This parameter is optional, but its value can only be positive. If its value is 0, it means that the shadow has no blurring effect. The larger the value, the blurr the edge of the shadow;
Shadow expansion radius: This parameter is optional, and its value can be positive or negative. If the value If it is positive, the entire shadow will be expanded, otherwise if the value is negative, it will be reduced;
Shadow color: This parameter is optional. If you do not set the color, the browser will use the default color, but the default color of each browser is inconsistent, especially the transparent color under the Safari and Chrome browsers under the webkit kernel, and the black color under Firefox/Opera (has been verification), it is recommended not to omit this parameter.
Browser compatibility:
In order to be compatible with various mainstream browsers and support lower versions of these mainstream browsers, based on Webkit When using the box-shadow attribute on browsers such as Chrome and Safari, we need to write the name of the attribute in the form -webkit-box-shadow. Firefox browser needs to be written in the form of -moz-box-shadow.
[css] view plain copy
[html]
view plain copy
Conclusion:
1) From .box The effect of -shadow-1 can be concluded that when the attribute shadow color is not specified, the shadow appears as a transparent color under the Safari and Chrome browsers under the webkit kernel, and appears as black under Firefox/Opera.
Burst the outer container to reveal the entire shadow effect. The W3C standard explains the principle and performance of box-shadow with diagrams:
From the picture we can understand: rounded border-radius , how shadow expansion radius, shadow blur radius and padding affect the object shadow: a non-zero value of border-radius will affect the shape of the shadow in the same way, but border-image will not affect any shape of the object shadow; object shadow Like the box model hierarchy, the outer shadow will be below the object's background, and the inner shadow will be below the border and above the background. We know that by default the background image is on top of the background color. So the entire hierarchy is: border>inner shadow>background image>background color>outer shadow.
3) From the effect of .box-shadow-2 to .box-shadow-5, we can understand the role of box-shadow value.
. box-shadow-2 is xy with no offset, shadow size 10px, no expansion radius, color #0CC is rgba(0, 204,204, 1), here we use the color HEX value; effect
And box-shadow-3 is based on the effect of box-shadow-2, applying rgba color value, the advantage is to give box-shadow shadow Added alpha transparency effect. Effect:
. box-shadow-4 adds a shadow expansion radius of 15px based on the box-shadow-2 effect.
. box-shadow-5 sets the outer shadow to the inner shadow based on the box-shadow-2 effect.
4). box-shadow-6 An element uses multiple shadows, separated by commas. To set the shadow effect on the four sides of the object, we achieve it by changing the positive and negative values of x-offset and y-offset. When x-offset is a negative value, the left shadow is generated. When it is a positive value, the right shadow is generated. The y-offset is Positive values produce a bottom shadow, negative values produce a top shadow. And set the blur radius to 0. If it is not set to 0, the other three sides will also have shadows. This needs attention!
And there is also a multi-shadow order issue involved here. When using multiple shadow attributes for the same element, you need to pay attention to their order. The shadow written first will be displayed at the top, such as box-shadow-7 is set to different blur values:
. box-shadow-7{
注意这样的写法是错误的:{box-shadow:-10px 0 10px red, box-shadow:10px 0 10px blue,box-shadow:0 -10px 10px yellow,box-shadow:0 10px 10px green}
box-shadow:0 0 10px 5px black,
0 0 10px 20px red;
}
will be visible Create the cascading sequence effect:
If you adjust the two shadow effects, change them to the following:
.box-shadow-8{
box-shadow:0 0 10px 20px red,
0 0 10px 5px black;
}
will only show the red shadow effect because The red shadow layer is on top, and the blur radius is large, completely blocking the black shadow behind it.
The conclusion is: if the blur value of the shadow in the front is less than the blur value of the shadow in the back, then the front one is displayed above the back. If the front shadow is If the blur value is greater than the blur value of the shadow behind, the shadow in the front will cover the shadow effect in the back.
4) Border-like border effect (only set shadow expansion radius and shadow color)
.box-shadow-9 is similar to boder:1px solid red, but box-shadow The effect is different from the border effect in the object height, which is exactly one expansion radius larger than the border height. And the shadow does not affect any layout of the page, which can be confirmed by viewing the layout diagram under firebug.
5) Simulate the box-shadow shadow effect in CSS3 under IE
Method 1: You can use IE’s Shadow filter
Basic syntax: filter:progid:DXImageTransform.Microsoft.Shadow(color='color value', Direction=Shadow angle (numeric value), Strength=Shadow radius (numeric value));
Note : This filter must be used together with the background attribute, otherwise the filter will be invalid.
Simulate box-shadow (shadow) code in css3 under IE:
[css] view plain copy
In the Children’s Day theme, I handled it like this:
[css ] view plain copy
ie-css3.htc is an htc file that allows the IE browser to support some CSS3 attributes, not just box-shadow, but also allows your IE browser to support the rounded corner attribute border -radius and text-shadow properties text-shadow.
How to use it is: download it and put it in your server directory Write the following code in your 93f0f5c25f18dab9d176bd4f6de5d30e9c3bca370b5104690d9ef395f2c5f8d1:
The disadvantage of this script is that IE only supports part of the box-shadow values. Note:
When you use this htc file, as long as box-shadow, -moz-box-shadow or -webkit-box-shadow is written in your CSS, IE will will render.
When using this htc file, you cannot write box-shadow: 0 0 10px red; but box-shadow: 0px 0px 10px red; otherwise it will fail in IE.
Alpha transparency in RGBA values is not supported.
[javascript]
view plain copy
Supplementary knowledge : CSS3 properties
: [d82af2074b26fcfe177e947839b5d381 | 42c97a047d75abc12b9b351eb8562711 ] [ d82af2074b26fcfe177e947839b5d381 | 42c97a047d75abc12b9b351eb8562711 ]?
Default value: 0 Value:
d82af2074b26fcfe177e947839b5d381: Use the length value to set the top-left corner of the object Corner radius length. Negative values are not allowed
42c97a047d75abc12b9b351eb8562711:
Use percentage to set the top-left corner radius length of the object. Negative values are not allowed
Description:
Sets or retrieves the upper left corner rounded border of the object. Provide 2 parameters, separated by spaces. Each parameter is allowed to set 1 parameter value. The first parameter represents the horizontal radius, and the second parameter represents the vertical radius. If the second parameter is omitted, it defaults to the 1st parameter. parameters. For example, setting border-top-left-radius:5px10px; means that the horizontal corner radius of the top-left corner is 5px and the vertical corner radius is 10px. The corresponding script feature is borderTopLeftRadius.
CSS3 Shadow Demonstration Toolhttp://www.css88.com/tool/css3Preview/Box-Shadow.html