CSS3 Box-shadow

Source: Internet
Author: User
Tags transparent color

  1. <! DOCTYPE HTML>
  2. <html>
  3. <head>
  4. <Meta content="text/html; Charset=utf-8 " http-equiv="content-type ">
  5. <title>CSS3 properties: Box-shadow test </title>
  6. <script type="Text/javascript" src="Js/jquery.min.js"></Script >
  7. <script type="Text/javascript" src="Js/jquery.boxshadow.js"></Script >
  8. <style type="Text/css">
  9. . box-shadow-1{
  10. -webkit-box-shadow:3px 3px 3px;
  11. -moz-box-shadow:3px 3px 3px;
  12. box-shadow:3px 3px 3px;
  13. }
  14. . box-shadow-2{
  15. -webkit-box-shadow:0 0 10px #0CC;
  16. -moz-box-shadow:0 0 10px #0CC;
  17. box-shadow:0 0 10px #0CC;
  18. }
  19. . box-shadow-3{
  20. -webkit-box-shadow:0 0 10px rgba (0, 204, 204,. 5);
  21. -moz-box-shadow:0 0 10px rgba (0, 204, 204,. 5);
  22. box-shadow:0 0 10px rgba (0, 204, 204,. 5);
  23. }
  24. . box-shadow-4{
  25. -webkit-box-shadow:0 0 10px 15px #0CC;
  26. -moz-box-shadow:0 0 10px 15px #0CC;
  27. box-shadow:0 0 10px 15px #0CC;
  28. }
  29. . box-shadow-5{
  30. -webkit-box-shadow:inset 0 0 10px #0CC;
  31. -moz-box-shadow:inset 0 0 10px #0CC;
  32. Box-shadow:inset 0 0 10px #0CC;
  33. }
  34. . box-shadow-6{
  35. box-shadow:-10px 0 10px Red,/* Left Shadow */
  36. 10px 0 10px Yellow,/* Right Shadow */
  37. 0-10px 10px Blue,/* top Shadow */
  38. 0 10px 10px Green; /* Bottom Shadow */
  39. }
  40. . box-shadow-7{
  41. box-shadow:0 0 10px 5px Black,
  42. 0 0 10px 20px Red;
  43. }
  44. . box-shadow-8{
  45. box-shadow:0 0 10px 20px Red,
  46. 0 0 10px 5px black;
  47. }
  48. . box-shadow-9{
  49. box-shadow:0 0 0 1px red;
  50. }
  51. . obj{
  52. width:100px;
  53. height:100px;
  54. margin:50px Auto;
  55. Background: #eee;
  56. }
  57. . outer{
  58. width:100px;
  59. height:100px;
  60. border:1px solid red;
  61. }
  62. . inner{
  63. width:60px;
  64. height:60px;
  65. background-color:red;
  66. -webkit-box-shadow:50px 50px Blue;
  67. -moz-box-shadow:50px 50px Blue;
  68. box-shadow:50px 50px Blue;
  69. }
  70. </style>
  71. </head>
  72. <body>
  73. <div class="obj box-shadow-1"></div>
  74. <div class="outer">
  75. <div class="inner"></div>
  76. </div>
  77. <div class="obj box-shadow-2" ></div>
  78. <div class="obj box-shadow-3" ></div>
  79. <div class="obj box-shadow-4" ></div>
  80. <div class="obj box-shadow-5" ></div>
  81. <div class="obj box-shadow-6" ></div>
  82. <div class="obj box-shadow-7" ></div>
  83. <div class="obj box-shadow-8" ></div>
  84. <div class="obj box-shadow-9" ></div>
  85. <script type="Text/javascript">
  86. $ (document). Ready (function () {
  87. if ($.browser.msie) {
  88. $ ('. obj '). Boxshadow ( -10,-10,5, "#0cc"); The obj element uses the Box-shadow
  89. }
  90. });
  91. </Script>
  92. </body>
  93. </html>



Conclusion:

1) from the effect of. Box-shadow-1 can be obtained without specifying the shadow color of the property, the shadow in Safari and Chrome under the WebKit kernel behaves as a transparent color, which behaves black under Firefox/opera.

2) from the comparison of the internal and external two div blocks inner and outer, all the mainstream browsers that support Box-shadow are represented as follows: The inner shadow bursting into the outer container renders the entire shadow effect. The principle and performance of Box-shadow is explained by the standard of the way of illustration:

We can see how the fillet Border-radius, the shadow extension radius, the shadow blur radius, and how padding affect the object's shadow: Border-radius with a value other than 0 will affect the shape of the shadow with the same effect, However, the border-image does not affect any shape of the object's shadow; The shadow of the object is the same as the hierarchy of the box model, and the outer shadow is below the background of the object and the inner shadow below the border. We know that the default background picture is above the background color. So the entire hierarchy is: Border > Inner shadow > Background picture > Background Color > Outer shadow.

3) from. Box-shadow-2 to. Box-shadow-5 effect, we can understand the function of Box-shadow value.

. Box-shadow-2 is XY has no offset, shadow size 10px, no expansion radius, color #0cc namely Rgba (0, 204,204, 1), here we use color hex value; effect

and. Box-shadow-3 is in. Based on the box-shadow-2 effect, the RGBA color value is applied, with the benefit of adding alpha transparency to the Box-shadow shadow. Effect:

. Box-shadow-4 in. The shadow extension radius of 15px is added based on the box-shadow-2 effect.

. Box-shadow-5 in. Based on the box-shadow-2 effect, the outer shadow is set to an inner shadow.

4). Box-shadow-6 one element uses multiple shadows, and multiple shadows are separated by commas. To set the shadow effect on the four sides of the object, we do this by changing the positive negative values of x-offset and Y-offset, where x-offset is negative, the left shadow is generated, the right shadow is generated for positive values, and the Y-offset is a positive value that generates a bottom shadow and a negative value when the top shadow is generated. and set the blur radius to 0, if not set to 0 then the other three sides will also have a shadow. This needs attention!

Note that the notation is wrong: {box-shadow:-10px 0 10px red, box-shadow:10px 0 10px blue,box-shadow:0 -10px 10px yellow,box-shadow:0 10px 10px Green}

And there's a multiple-shadow order problem. When you use multiple shadow properties for the same element, you need to be aware of its order, and the first-written shadow will be displayed at the top level, such as. Box-shadow-7 is set to a different fuzzy value:

. box-shadow-7{

box-shadow:0 0 10px 5px Black,

0 0 10px 20px Red;

}

You will be able to see the sequential effect of the Cascade:

If you adjust the two shadow effects, change to the following:

. box-shadow-8{

box-shadow:0 0 10px 20px Red,

0 0 10px 5px black;

}

Only the red shadow effect is displayed, because the Red shadow layer is above, the blur radius is large, and the black shadow behind is completely obscured.

The conclusion is that if the previous shadow blur value is less than the shadow blur value that follows, the front shadow will cover the shadow effect behind if the blur value of the front shadow is greater than the shadow blur value that follows.

4) class border border effect (only set shadow expansion radius and shadow color)

The effect of the. Box-shadow-9 is similar to boder:1px solid red, but the Box-shadow effect differs from the border effect on the object height, which is an extended radius greater than the border height. And the shadow does not affect any layout of the page, which can be confirmed by looking at the layout diagram under Firebug.

5) Box-shadow Shadow effect in the simulated CSS3 under IE

Method One: You can use IE's shadow filter

basic Syntax : Filter:progid:DXImageTransform.Microsoft.Shadow (color= ' color value ', direction= shadow Angle (value), strength= shadow radius (numeric) );

Note : The filter must be used with the background property, otherwise the filter will fail.

Box-shadow (shadow) code in analog CSS3 under IE:

[CSS]View PlainCopy
  1. . box-shadow{
  2. Filter:progid:DXImageTransform.Microsoft.Shadow (color=' #969696 ', direction=135, strength=5); /*for ie6,7,8*/
  3. Background-color: #ccc;
  4. -moz-box-shadow:2px 2px 5px #969696; /*firefox*/
  5. -webkit-box-shadow:2px 2px 5px #969696; /*webkit*/
  6. Box-shadow:2px 2px 5px #969696; /*opera or ie9*/
  7. }
  • Method Two: Some JS and. HTC's hack file can implement the shadow effect in IE.
  • IE-CSS3.HTC is an HTC file that allows IE browser to support partial CSS3 properties, not just box-shadow, it also allows your IE browser to support fillet properties Border-radius and Text Shadow properties Text-shadow.
  • It is used by downloading it and putting it in your server directory

    Write the following code in your

    The disadvantage of this script is that IE only supports part of the Box-shadow value. Need to note:

      • When you use this HTC file, in your CSS, as long as you write any kind of Box-shadow,-moz-box-shadow or-webkit-box-shadow, IE will render.
      • When using this HTC file, you cannot write box-shadow:0 0 10px red; And should be box-shadow:0px 0px 10px red; Otherwise, IE will fail.
      • Alpha Transparency in RGBA values is not supported.
      • Inset inner shadow is not supported.
      • Shadow extensions are not supported.
      • Shadows are only shown in black in IE, no matter what color you set.

    method Three: Use jquery plug-in jquery.boxshadow.js, plug-in is Http://www.hintzmann.dk/testcenter/js/jquery/boxshadow/jquery.boxshadow.js

    Using the method is simple, the file and the jquery repository into the head tag, insert the following JS effect code:

    [JavaScript]View PlainCopy
      1. <script type="Text/javascript" >
      2. $ (document). Ready (function () {
      3. if ($.browser.msie) {
      4. $ ('. obj '). Boxshadow ( -10,-10,5,"#0cc"); the//obj element uses the Box-shadow
      5. }
      6. });
      7. </script>


    Note: JS can be used: obj.style.webkitboxshadow= value (string); obj.style.mozboxshadow= value (string); obj.style.boxshadow= value (string);

    Supplemental Knowledge: Properties of CSS3

    Border-top-left-radius:[<length> | <percentage>] [<length> | <percentage>]?

    Default value: 0

    Value:

    <length>:

    Sets the upper-left corner (top-left) fillet radius length of the object with a length value. Negative values are not allowed

    <percentage>:

    Sets the upper-left corner (top-left) fillet radius length of the object in percent. Negative values are not allowed

    Description

    Sets or retrieves the upper-left corner rounded border of an object. Provides 2 parameters, 2 parameters are separated by a space, each parameter allows to set 1 parameter values, the 1th parameter represents the horizontal radius, and the 2nd parameter represents the vertical radius, as the 2nd parameter is omitted, the default equals the 1th parameter. If border-top-left-radius:5px10px is set, the horizontal fillet radius of the top-left angle is 5px and the vertical fillet radius is 10px. The corresponding script attribute is Bordertopleftradius.

CSS3 Box-shadow

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.