The shadow of CSS3 knowledge Box-shadow

Source: Internet
Author: User

I. Definition and usage

The Box-shadow property adds one or more shadows to the box.

Box-shadow:h-shadow v-shadow blur spread color inset;
    • H-shadow required. The position of the horizontal shadow. Negative values are allowed.

    • V-shadow required. The position of the vertical shadow. Negative values are allowed.

    • Blur is optional. Blur distance.

    • spread is optional. The size of the shadow.

    • color is optional. The color of the shadow.

    • inset is optional. Changes the outer shadow (outset) to an inner shadow.

Note:Box-shadow adds one or more shadows to the box.

This property is a comma-delimited list of shadows, each of which is specified by a 2-4-length value, an optional color value, and an optional inset keyword. The value of the omitted length is 0.

second, browser support
    • ie9+, Firefox 4, Chrome, Opera, and Safari 5.1.1 support Box-shadow properties.

Third, examples

<!DOCTYPE HTML><HTMLLang= "en"><Head>    <MetaCharSet= "UTF-8">    <title>The shadow of CSS3 knowledge Box-shadow</title>    <style>        *{margin:0;padding:0; }Body{Background-color:#f0f0f0; }Div{width:200px;Height:200px;margin:60px 30px;Background-color:#35b091;float: Left;Border-radius:16px;text-align:Center;Line-height:200px; }        /*Bottom Shadow*/. Div1{Box-shadow:0 6px 3px-3px rgba (0,0,0, 0.8); }        /*shadow on both sides*/. Div2{Box-shadow:6px 0px 3px-3px rgba (0,0,0, 0.8), -6px 0px 3px-3px rgba (0,0,0, 0.8); }        /*Inner Shadow*/. Div3{Box-shadow:0px 0px 6px rgba (0,0,0, 0.8) Inset; }        /*Medial unilateral shadow*/. Div4{Box-shadow:0px-6px 6px-6px Rgba (0,0,0, 0.8) Inset; }                /*Medial Bilateral Shadow*/. DIV5{Box-shadow:-6px 0px 6px-6px rgba (0,0,0, 0.8) inset, 0px 6px 6px-6px rgba (0,0,0, 0.8) Inset; }    </style></Head><Body>    <Divclass= "Div1">Div1</Div>    <Divclass= "Div2">Div2</Div>    <Divclass= "Div3">Div3</Div>    <Divclass= "Div4">Div4</Div>    <Divclass= "DIV5">Div5</Div></Body></HTML>
iv. Extension: Box-shadow shadow effect in 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{Filter:Progid:DXImageTransform.Microsoft.Shadow (color= ' #969696 ', direction=135, strength=5);/*For ie6,7,8*/Background-color:#ccc;-moz-box-shadow:2px 2px 5px #969696;/*Firefox*/-webkit-box-shadow:2px 2px 5px #969696;/*WebKit*/Box-shadow:2px 2px 5px #969696;/*Opera or IE9*/}

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 uses: Download it and put it in your server directory, and write the following code in your

{    -moz-box-shadow: 10px 10px 20px #000;         -webkit-box-shadow: 10px 10px 20px #000;      box-shadow: 10px 10px 20px #000;     behavior: url (ie-css3.htc);            }

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 the jQuery plugin jquery.boxshadow.js

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

<script type= "Text/javascript" >      $ (document). Ready (function() {          if  ($.browser.msie) {               $ (///obj element used Box-shadow           }      });   </script>  

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

CSS3 Shadow presentation tool http://www.css88.com/tool/css3Preview/Box-Shadow.html

Reference: http://blog.csdn.net/freshlover/article/details/7610269

The shadow of CSS3 knowledge 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.