---
title: "css3的阴影、透明和动画"
author: "angowang"
date: "2014-09-17T22:42:37Z"
tags: []
categories: ["Web前端"]
slug: "css3"
draft: false
lastmod: "2014-09-17T22:42:37Z"
id: 2115059
url: "https://angowang.iteye.com/blog/2115059"
---

**阴影效果：**

&lt;!DOCTYPE html&gt;  
&lt;html&gt;  
    &lt;head&gt;  
        &lt;meta charset="utf-8" /&gt;  
        &lt;title&gt;xxx&lt;/title&gt;  
        &lt;style type="text/css"&gt;  
            .box {  
                width: 400px;  
                height: 400px;  
                background: pink;  
                //box-shadow:默认外阴影或inset内阴影，水平偏移，垂直偏移，模糊半径，扩展半径;  
                box-shadow:3px 3px 15px 3px gray;  
            }  
        &lt;/style&gt;  
    &lt;/head&gt;  
    &lt;body&gt;  
        &lt;div class="box"&gt;&lt;/div&gt;  
    &lt;/body&gt;  
&lt;/html&gt;

**透明效果：**

&lt;!DOCTYPE html&gt;  
&lt;html&gt;  
    &lt;head&gt;  
        &lt;meta charset="utf-8" /&gt;  
        &lt;title&gt;xxx&lt;/title&gt;  
        &lt;style type="text/css"&gt;  
            .boxOutside {  
                width: 410px;  
                height: 410px;  
                position: relative;  
                background: rgba(200, 200, 200, 0.3);  
            }  
            .boxInside {  
                width: 400px;  
                height: 400px;  
                position: absolute;  
                background: pink;  
                top: 0;  
                right: 0;  
                bottom: 0;  
                left: 0;  
                margin: auto;  
            }  
        &lt;/style&gt;  
    &lt;/head&gt;  
    &lt;body&gt;  
        &lt;div class="boxOutside"&gt;  
            &lt;div class="boxInside"&gt;&lt;div&gt;  
        &lt;/div&gt;  
    &lt;/body&gt;  
&lt;/html&gt;

**动画效果：**

 1.transition

&lt;!DOCTYPE html&gt;  
&lt;html&gt;  
    &lt;head&gt;  
        &lt;meta charset="utf-8" /&gt;  
        &lt;title&gt;xxx&lt;/title&gt;  
        &lt;style type="text/css"&gt;  
            .boxOutside {  
                width: 500px;  
                height: 500px;  
                position: relative;  
                background: rgba(200, 200, 200, 0.3);  
            }  
            .boxInside {  
                width: 400px;  
                height: 400px;  
                position: absolute;  
                background: pink;  
                top: 0;  
                right: 0;  
                bottom: 0;  
                left: 0;  
                margin: auto;  
                transition: 1s width ease, 1s 1s height ease;  
            }  
            .boxInside:hover {  
                width: 500px;  
                height: 500px;  
            }  
        &lt;/style&gt;  
    &lt;/head&gt;  
    &lt;body&gt;  
        &lt;div class="boxOutside"&gt;  
            &lt;div class="boxInside"&gt;&lt;div&gt;  
        &lt;/div&gt;  
    &lt;/body&gt;  
&lt;/html&gt;

2.animation

&lt;!DOCTYPE html&gt;  
&lt;html&gt;  
    &lt;head&gt;  
        &lt;meta charset="utf-8" /&gt;  
        &lt;title&gt;xxx&lt;/title&gt;  
        &lt;style type="text/css"&gt;  
            .boxOutside {  
                width: 500px;  
                height: 500px;  
                position: relative;  
                background: rgba(200, 200, 200, 0.3);  
            }  
            .boxInside {  
                width: 400px;  
                height: 400px;  
                position: absolute;  
                background: #c00;  
                top: 0;  
                right: 0;  
                bottom: 0;  
                left: 0;  
                margin: auto;  
                 
            }  
            .boxInside:hover {  
                -webkit-animation: 1s 1s rainbow 3;  
                animation: 1s 1s rainbow 3;  
            }  
            @-webkit-keyframes rainbow {  
                0%{background: #c00;}  
                50%{background: orange;}  
                100%{background: yellowgreen;}  
            }  
            @keyframes rainbow {  
                0%{background: #c00;}  
                50%{background: orange;}  
                100%{background: yellowgreen;}  
            }  
        &lt;/style&gt;  
    &lt;/head&gt;  
    &lt;body&gt;  
        &lt;div class="boxOutside"&gt;  
            &lt;div class="boxInside"&gt;&lt;div&gt;  
        &lt;/div&gt;  
    &lt;/body&gt;  
&lt;/html&gt;