美文网首页
CSS3 按钮

CSS3 按钮

作者: maskerII | 来源:发表于2019-05-12 14:33 被阅读0次
    
    <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <title>CSS3 按钮</title>
        <style>
           .button{
                background-color: #4CAF50;
                border: none;
                color: white;
                padding: 15px 32px;
                text-align: center;
                text-decoration: none;
                display: inline-block;
                font-size: 16px;
                margin: 4px 2px;
                cursor: pointer;
            }
    
           /*按钮颜色*/
           .button2 {background-color: #008CBA;} /* Blue */
           .button3 {background-color: #f44336;} /* Red */
           .button4 {background-color: #e7e7e7; color: black;} /* Gray */
           .button5 {background-color: #555555;} /* Black */
    
    
           /*按钮大小*/
           .button6 {font-size: 10px;}
           .button7 {font-size: 12px;}
           .button8 {font-size: 16px;}
           .button9 {font-size: 20px;}
           .button10 {font-size: 24px;}
    
    
    
           /*圆角按钮*/
           .button11 {border-radius: 2px;}
           .button12 {border-radius: 4px;}
           .button13 {border-radius: 8px;}
           .button14 {border-radius: 12px;}
           .button15 {border-radius: 50%;}
    
    
    
           /*按钮边框颜色*/
           .button16 {
               background-color: white;
               color: black;
               border: 2px solid #4CAF50;
           }
    
           .button17 {
               background-color: white;
               color: black;
               border: 2px solid #008CBA;
           }
    
           .button18 {
               background-color: white;
               color: black;
               border: 2px solid #f44336;
           }
    
           .button19 {
               background-color: white;
               color: black;
               border: 2px solid #e7e7e7;
           }
    
           .button20 {
               background-color: white;
               color: black;
               border: 2px solid #555555;
           }
    
    
    
    
           /*鼠标悬停按钮*/
    
           .button21 {
               background-color: white;
               color: black;
               border: 2px solid #4CAF50;
           }
    
           .button21:hover {
               background-color: #4CAF50;
               color: white;
           }
    
           .button22 {
               background-color: white;
               color: black;
               border: 2px solid #008CBA;
           }
    
           .button22:hover {
               background-color: #008CBA;
               color: white;
           }
    
           .button23 {
               background-color: white;
               color: black;
               border: 2px solid #f44336;
           }
    
           .button23:hover {
               background-color: #f44336;
               color: white;
           }
    
           .button24 {
               background-color: white;
               color: black;
               border: 2px solid #e7e7e7;
           }
    
           .button24:hover {background-color: #e7e7e7;}
    
           .button25 {
               background-color: white;
               color: black;
               border: 2px solid #555555;
           }
    
           .button25:hover {
               background-color: #555555;
               color: white;
           }
    
    
    
           /*按钮阴影*/
           .button26 {
               box-shadow: 0 8px 16px 0 rgba(0,0,0,0.2), 0 6px 20px 0 rgba(0,0,0,0.19);
           }
    
           .button27:hover {
               box-shadow: 0 12px 16px 0 rgba(0,0,0,0.24),0 17px 50px 0 rgba(0,0,0,0.19);
           }
    
    
           /*禁用按钮*/
           .disabled {
               opacity: 0.6;
               cursor: not-allowed;
           }
    
    
           /*按钮宽度*/
           .button31 {width: 250px;}
           .button32 {width: 50%;}
           .button33 {
               padding-left: 0;
               padding-right: 0;
               width: 100%;
           }
    
    
    
           /*按钮组*/
           .button34 {
               background-color: #4CAF50; /* Green */
               border: none;
               color: white;
               padding: 15px 32px;
               text-align: center;
               text-decoration: none;
               display: inline-block;
               font-size: 16px;
               cursor: pointer;
               float: left;
           }
    
           .button34:hover {
               background-color: #3e8e41;
           }
    
    
    
           /*带边框按钮组*/
           .button35 {
               background-color: #4CAF50; /* Green */
               border: 1px solid green;
               color: white;
               padding: 15px 32px;
               text-align: center;
               text-decoration: none;
               display: inline-block;
               font-size: 16px;
               cursor: pointer;
               float: left;
           }
    
           .button35:hover {
               background-color: #3e8e41;
           }
    
    
    
           /*按钮动画组*/
           .button36 {
               display: inline-block;
               border-radius: 4px;
               background-color: #f4511e;
               border: none;
               color: #FFFFFF;
               text-align: center;
               font-size: 28px;
               padding: 20px;
               width: 200px;
               transition: all 0.5s;
               cursor: pointer;
               margin: 5px;
           }
    
    
           .button36 span {
               cursor: pointer;
               display: inline-block;
               position: relative;
               transition: 0.5s;
           }
    
           .button36 span:after {
               content: '»';
               position: absolute;
               opacity: 0;
               top: 0;
               right: -20px;
               transition: 0.5s;
           }
    
           .button36:hover span {
               padding-right: 25px;
           }
    
           .button36:hover span:after {
               opacity: 1;
               right: 0;
           }
    
    
           /*按钮动画 波纹效果*/
           .button37 {
               position: relative;
               background-color: #4CAF50;
               border: none;
               font-size: 28px;
               color: #FFFFFF;
               padding: 20px;
               width: 200px;
               text-align: center;
               -webkit-transition-duration: 0.4s; /* Safari */
               transition-duration: 0.4s;
               text-decoration: none;
               overflow: hidden;
               cursor: pointer;
           }
    
           .button37:after {
               content: "";
               background: #90EE90;
               display: block;
               position: absolute;
               padding-top: 300%;
               padding-left: 350%;
               margin-left: -20px!important;
               margin-top: -120%;
               opacity: 0;
               transition: all 0.8s
           }
    
           .button37:active:after {
               padding: 0;
               margin: 0;
               opacity: 1;
               transition: 0s
           }
    
    
           /*按钮动画 按压动画*/
           .button38 {
               display: inline-block;
               padding: 15px 25px;
               font-size: 24px;
               cursor: pointer;
               text-align: center;
               text-decoration: none;
               outline: none;
               color: #fff;
               background-color: #4CAF50;
               border: none;
               border-radius: 15px;
               box-shadow: 0 9px #999;
           }
    
           .button38:hover {background-color: #3e8e41}
    
           .button38:active {
               background-color: #3e8e41;
               box-shadow: 0 5px #666;
               transform: translateY(4px);
           }
    
    
    
    
        </style>
        
    </head>
    <body>
    
    <h2>CSS 按钮</h2>
    <button>默认按钮</button>
    <a href="#" class="button">按钮</a>
    <button class="button">按钮</button>
    <input type="button" class="button" value="输入框按钮">
    
    <br><br>
    
    <h2>按钮颜色</h2>
    <p>我们可以使用 background-color 属性来设置按钮颜色:</p>
    
    <button class="button">Green</button>
    <button class="button button2">Blue</button>
    <button class="button button3">Red</button>
    <button class="button button4">Gray</button>
    <button class="button button5">Black</button>
    
    <br><br>
    
    
    
    <h2>按钮大小</h2>
    <p>我们可以使用 font-size 属性来设置按钮大小:</p>
    
    <button class="button button6">10px</button>
    <button class="button button7">12px</button>
    <button class="button button8">16px</button>
    <button class="button button9">20px</button>
    <button class="button button10">24px</button>
    
    <br><br>
    
    
    <h2>圆角按钮</h2>
    <p>我们可以使用 border-radius 属性来设置圆角按钮:</p>
    
    <button class="button button11">2px</button>
    <button class="button button12">4px</button>
    <button class="button button13">8px</button>
    <button class="button button14">12px</button>
    <button class="button button15">50%</button>
    
    <br><br>
    
    <h2>按钮边框颜色</h2>
    <p>我们可以使用 border 属性设置按钮边框颜色:</p>
    
    <button class="button button16">Green</button>
    <button class="button button17">Blue</button>
    <button class="button button18">Red</button>
    <button class="button button19">Gray</button>
    <button class="button button20">Black</button>
    
    <br><br>
    
    
    
    <h2>鼠标悬停按钮</h2>
    <p>我们可以使用 :hover 选择器来修改鼠标悬停在按钮上的样式。</p>
    <p><strong>提示:</strong> 我们可以使用 <code>transition-duration</code> 属性来设置 "hover" 效果的速度:</p>
    
    <button class="button button21">Green</button>
    <button class="button button22">Blue</button>
    <button class="button button23">Red</button>
    <button class="button button24">Gray</button>
    <button class="button button25">Black</button>
    
    <br><br>
    
    
    <h2>按钮阴影</h2>
    <p>我们可以使用 box-shadow 属性来为按钮添加阴影:</p>
    
    <button class="button button26">阴影按钮</button>
    <button class="button button27">鼠标悬停后出现阴影</button>
    
    <br><br>
    
    
    <h2>禁用按钮</h2>
    <p>我们可以使用 opacity 属性为按钮添加透明度 (看起来类似 "disabled" 属性效果)。</p>
    
    <button class="button">正常按钮</button>
    <button class="button disabled">禁用按钮</button>
    
    <br><br>
    
    
    <h2>按钮宽度</h2>
    <p>默认情况下,按钮的大小有按钮上的文本内容决定( 根据文本内容匹配长度 )。 我们可以使用 width 属性来设置按钮的宽度:</p>
    <p><strong>提示:</strong>  如果要设置固定宽度可以使用像素 (px) 为单位,如果要设置响应式的按钮可以设置为百分比。</p>
    
    <button class="button button31">250px</button><br>
    <button class="button button32">50%</button><br>
    <button class="button button33">100%</button>
    <br><br>
    
    
    
    <h2>按钮组</h2>
    <p>移除外边距并添加 float:left 来设置按钮组:</p>
    
    <button class="button34">Button</button>
    <button class="button34">Button</button>
    <button class="button34">Button</button>
    <button class="button34">Button</button>
    
    <p style="clear:both"><br>记住要清除浮动,否则下一个 p 元素的按钮也会显示在同一行。</p>
    
    <br><br>
    
    
    <h2>带边框按钮组</h2>
    <p>Add borders to create a bordered button group:</p>
    
    <button class="button35">Button</button>
    <button class="button35">Button</button>
    <button class="button35">Button</button>
    <button class="button35">Button</button>
    
    <p style="clear:both"><br>记住要清除浮动,否则下一个 p 元素的按钮也会显示在同一行。</p>
    
    <br><br>
    
    <h2>按钮动画</h2>
    
    <button class="button36" style="vertical-align:middle"><span>Hover </span></button>
    
    <br><br>
    
    <h2>按钮动画 - 波纹效果</h2>
    
    <button class="button37">Click Me</button>
    
    <br><br>
    
    <h2>按钮动画 - "按压效果"</h2>
    
    <button class="button38">Click Me</button>
    
    <br><br>
    
    
    </body>
    </html>
    
    
    <!--
    
    基本按钮样式
    默认按钮
    
    CSS 实例
    .button {
        background-color: #4CAF50; /* Green */
        border: none;
        color: white;
        padding: 15px 32px;
        text-align: center;
        text-decoration: none;
        display: inline-block;
        font-size: 16px;
    }
    
    
    -->
    
    
    <!--
    
    
    按钮颜色
    
    我们可以使用 background-color 属性来设置按钮颜色:
    
    CSS 实例
    .button1 {background-color: #4CAF50;} /* Green */
    .button2 {background-color: #008CBA;} /* Blue */
    .button3 {background-color: #f44336;} /* Red */
    .button4 {background-color: #e7e7e7; color: black;} /* Gray */
    .button5 {background-color: #555555;} /* Black */
    
    -->
    
    <!--
    
    按钮大小
    
    我们可以使用 font-size 属性来设置按钮大小:
    
    CSS 实例
    .button1 {font-size: 10px;}
    .button2 {font-size: 12px;}
    .button3 {font-size: 16px;}
    .button4 {font-size: 20px;}
    .button5 {font-size: 24px;}
    
    -->
    
    
    
    <!--
    
    
    圆角按钮
    
    我们可以使用 border-radius 属性来设置圆角按钮:
    
    CSS 实例
    .button1 {border-radius: 2px;}
    .button2 {border-radius: 4px;}
    .button3 {border-radius: 8px;}
    .button4 {border-radius: 12px;}
    .button5 {border-radius: 50%;}
    
    -->
    
    
    <!--
    
    按钮边框颜色
    
    我们可以使用 border 属性设置按钮边框颜色:
    
    CSS 实例
    .button1 {
        background-color: white;
        color: black;
        border: 2px solid #4CAF50; /* Green */
    }
    ...
    
    
    
    -->
    
    
    
    <!--
    
    
    鼠标悬停按钮
    
    
    我们可以使用 :hover 选择器来修改鼠标悬停在按钮上的样式。
    
    提示: 我们可以使用 transition-duration 属性来设置 "hover" 效果的速度:
    
    CSS 实例
    .button {
        -webkit-transition-duration: 0.4s; /* Safari */
        transition-duration: 0.4s;
    }
    
    .button:hover {
        background-color: #4CAF50; /* Green */
        color: white;
    }
    
    -->
    
    
    
    <!--
    
    按钮阴影
    
    我们可以使用 box-shadow 属性来为按钮添加阴影:
    
    CSS 实例
    .button1 {
        box-shadow: 0 8px 16px 0 rgba(0,0,0,0.2), 0 6px 20px 0 rgba(0,0,0,0.19);
    }
    
    .button2:hover {
        box-shadow: 0 12px 16px 0 rgba(0,0,0,0.24), 0 17px 50px 0 rgba(0,0,0,0.19);
    }
    
    
    -->
    
    
    
    

    相关文章

      网友评论

          本文标题:CSS3 按钮

          本文链接:https://www.haomeiwen.com/subject/zpxtaqtx.html