CSS3 特效分解一

      先声明下,下面的特效不是我发明的,对CSS3的创造力还不够,只是看了别人demo的源码,一点一点分析出来的。整理出的笔记,分享给大家。因为源码是好,但是一头扎进去半天出不来。

      首先看个登陆框,如下,相信不少朋友见到过。

      这个上面有很多css3特效。边框阴影,内置斜纹的字体,login 下的横线等,我来一一分解。

      

     1.内外阴影画法:

     大家熟知box-shadow,这个比较简单。box-shadow最多有个参数,分别是x投影,y投影,模糊半径,扩展半径,颜色,inset。inset决定了是内阴影还是外阴影。

     PS:x为0,或者y为0 三边有阴影。x和y都为0 四边都有阴影。 内外阴影可以叠加。这样,第三幅图明显旧有质感了些,上图就好像有了厚度一样的感觉。

      

 .test1 {box-shadow: 0px 10px 10px gray;width: 200px;height: 200px;margin-left: 50px; background-color: #e0ffff}
.test2 { box-shadow: 0px 0px 10px gray;width: 200px;height: 200px;margin-left: 50px; background-color: #e0ffff}
.test3 { box-shadow: 0pt 2px 5px rgba(105, 108, 109, 0.7) ,0px 0px 8px 5px rgba(208, 223, 226, 0.4) inset;width: 200px;height: 200px;margin-left: 50px; background-color:white}

 2.两端渐变线条

    

  渐变线,当然用的是线性渐变再加伪元素。 这里用before和after一样。 content是不能少的,不然就看不见了。 伪元素的定位最好和父级元素形成relative和absolute的关系。

 .test {   800px;height: 50px;margin-left: 50px;background-color: #e0ffff;position: relative; }  
.test:before
{ content: ' '; width: 100%;height: 2px; position: absolute; bottom: -20px; background: -webkit-linear-gradient(left, rgba(147,184,189,0) 0%,rgba(147,184,189,0.8) 20%,rgba(147,184,189,1) 53%,rgba(147,184,189,0.8) 79%,rgba(147,184,189,0) 100%); background: -o-linear-gradient(left, rgba(147,184,189,0) 0%,rgba(147,184,189,0.8) 20%,rgba(147,184,189,1) 53%,rgba(147,184,189,0.8) 79%,rgba(147,184,189,0) 100%); }

线性渐变可以有多个参数,头个left 表示渐变是从左往右,也可以是top。还可以换成角度。然后每个颜色的百分比。 rgba写着麻烦,可以用#XXXX 但是前者便于条透明度。

再来个炫一点的:

.ctitle{ text-align: left;font-weight: bold;font-size: 2em;margin-left: 10%;margin-right: 10%; margin-top:40px;}
.ctitle:after{
    content: ' ';
    display: block;
    width: 100%;
    height: 5px;
    margin-top: 10px;
    background: -webkit-linear-gradient(left,#7fffd4 0%, #ee82ee 20%, rgba(147, 184, 189, 0) 100%);
} 

3.斜纹背景和字体:

 

  像上面这种斜纹,还是借助于线性渐变,而且是带有角度的。

  但是我发现,那个Login 的背景就是斜纹。

  

   关键代码: 黄色的部分,产生斜纹,而后面的两句让他成为字体的背景!

  background: -webkit-repeating-linear-gradient(-45deg, 
    rgb(18, 83, 93) , 
    rgb(18, 83, 93) 20px, 
    rgb(64, 111, 118) 20px, 
    rgb(64, 111, 118) 40px, 
    rgb(18, 83, 93) 40px);

 -webkit-text-fill-color: transparent;
    -webkit-background-clip: text; 

 而蓝白色条纹同理:

 

  background: -webkit-repeating-linear-gradient(-45deg, 
    rgb(247, 247, 247) , 
    rgb(247, 247, 247) 15px, 
    rgb(225, 234, 235) 15px, 
    rgb(225, 234, 235) 30px, 
    rgb(247, 247, 247) 30px
    );

  4. 字体阴影,这个和上面没有关系了。

 

text-shadow: 0 1px 0 #ccc,
               0 2px 0 #c9c9c9,
               0 3px 0 #bbb,
               0 4px 0 #b9b9b9,
               0 5px 0 #aaa,
               0 6px 1px rgba(0,0,0,.1),
               0 0 5px rgba(0,0,0,.1),
               0 1px 3px rgba(0,0,0,.3),
               0 3px 5px rgba(0,0,0,.2),
               0 5px 10px rgba(0,0,0,.25),
               0 10px 10px rgba(0,0,0,.2),
               0 20px 20px rgba(0,0,0,.15);

5. 叠加边框

 

box-shadow:0 1px 0 rgb(255,255,255), 0 2px 0 rgb(197,200,204), 0 3px 0 rgb(255,255,255), 0 4px 0 rgb(197,200,204); 
}

6.翘脚阴影

 

 在这两个大家见的多了。主要是伪元素的定位和旋转。 relative absolute content z-index 必不可少 

#demo{ position: relative;width: 400px;height: 100px;background: #fafafa;display: inline-block; box-shadow: 0 0 3px gray;
}
#demo::before, #demo::after{ position:absolute; content:"";
                              top:10px; bottom:15px; left:10px; width:50%; box-shadow:0 15px 10px rgba(0, 0, 0, 0.5);
                               -webkit-transform: rotate(-3deg); -moz-transform:rotate(-3deg); -o-transform:rotate(-3deg);
                                -ms-transform:rotate(-3deg); transform:rotate(-3deg); z-index:-1;}
#demo::after{ right:10px; left:auto; -webkit-transform:rotate(3deg);
                             -moz-transform:rotate(3deg); -o-transform:rotate(3deg);
                              -ms-transform:rotate(3deg); transform: rotate(3deg);}

不想干活的时候,写写博客 ~ ~ 

 希望对你有帮助!

原文地址:https://www.cnblogs.com/stoneniqiu/p/3425759.html