zoukankan      html  css  js  c++  java
  • CSS3创意样式按钮实现

    <!DOCTYPE html>
    <html>
    <head>
    <meta charset="UTF-8">
    <link href="style/css.css" rel="stylesheet" type="text/css">
    </head>
    <body>
    
    <button class="btn btn-1 btn-1a">Button</button>
    <button class="btn btn-1 btn-1b">Button</button>
    <button class="btn btn-1 btn-1c">Button</button>
    <button class="btn btn-1 btn-1d">Button</button>
    <button class="btn btn-1 btn-1e">Button</button>
    <button class="btn btn-1 btn-1f">Button</button>
    
    <button class="btn btn-2 btn-2g">Button</button>
    </body>
    </html>
    
    <style>
    body{background: #aaa}
    .btn{
        padding:25px 80px;
        transition: all .3s ease;
        background: none;
        cursor: pointer;
        color:#fff;
        display: inline-block;
        margin: 15px 30px;
        position: relative;
        outline: none;
        border: none;
    }
    .btn:after{
        content:'';
        position: absolute;
        transition: all .3s ease;
        z-index: -1;
    }
    .btn:before{
        content: '';
        position: relative;
        transition: all .3s ease;
    }
    .btn-1 {
        border: 3px solid #fff;
        color: #fff;
    }    
    .btn-1a:hover{
        background: #fff;
        color:blue;
    }
        
    .btn-1b:after{
        content: '';
        width: 100%;
        height: 0%;
        background: #000;
        left: 0;
        top:0;
    } 
    .btn-1b:hover:after{
        height: 100%;
    }
        
    .btn-1c:after{
        content: '';
        width: 0%;
        height: 100%;
        background: #000;
        left: 0;
        top:0;
    }
    .btn-1c:hover:after{
        width: 100%;
    }
    .btn-1d{overflow: hidden;}
    .btn-1d:after{
        content: '';
        width: 0%;
        height: 105%;
        background: #000;
        transform: translate(-50%,-50%);
        left: 50%;
        top:50%;
        opacity: 0;
    }
    .btn-1d:hover:after{
        width: 90%;
        opacity: 1;
    }
    .btn-1d:active:after{
        width: 100%;
    }
    
        
    .btn-1e{overflow: hidden;}
    .btn-1e:after{
        content: '';
        height: 200%;
        width: 0;
        background: #000;
        left: 50%;
        top:50%;
        transform: translate(-50%,-50%) rotate(-45deg);
        opacity: 0.1;
    }
    .btn-1e:hover:after{
        width: 200%;
        opacity: 1;
    }
    .btn-1e:active:after{
        height: 300%;
    }
     
    .btn-2 {
        background: #cb4e4e;
        color: #fff;
        box-shadow: 0 6px #ab3c3c;
        -webkit-transition: none;
        -moz-transition: none;
        transition: none;
    }
    .btn-2g{
        border-radius: 40px;
    }
    .btn-2g:hover{
        box-shadow: 0px 4px #ab3c3c;
        top:2px;
    }
    .btn-2g:active{
        box-shadow: 0px 0px;
        top:6px;
    }
    </style>

    自己尝试实现了几个效果,总结下制作方法(如在不同浏览器下看不到效果请在css3属性上加上个浏览器的前缀):

    1:设置按钮的transition属性,做统一的过渡效果,包括按钮的:before,:after的过渡属性。

    2:设定不同变化效果。例如高度的变化,阴影的变化,top的属性。

    3:必须要设置:before,:after的content属性,即使设置为空。

    4::after的z-index须设置层级在按钮下。

    参考地址:http://www.jiawin.com/demos/creative-button-styles/index.html

  • 相关阅读:
    P5356 [Ynoi2017]由乃打扑克
    P4921 [MtOI2018]情侣?给我烧了!/P4931 [MtOI2018]情侣?给我烧了!(加强版)
    P2605 [ZJOI2010]基站选址
    CF1062E Company
    kd-tree
    扩展中国剩余定理(EXCRT)
    CF264C Choosing Balls
    CF1139D Steps to One
    P4655 [CEOI2017]Building Bridges
    P3311 [SDOI2014] 数数
  • 原文地址:https://www.cnblogs.com/sakura-Master/p/4054181.html
Copyright © 2011-2022 走看看