码迷,mamicode.com
首页 > Web开发 > 详细

用事件与CSS改变按钮不同状态下的颜色

时间:2016-04-11 20:33:18      阅读:245      评论:0      收藏:0      [点我收藏+]

标签:

目标效果:

    表单的群发按钮,在鼠标悬停时为深蓝色,鼠标离开时为淡蓝色。

HTML代码:

    <button id="submitBtn"  class="btn" onmouseover="this.className=‘input_move‘" onmouseout="this.className=‘input_out‘" type="submit" tabindex="6">群    发</button>
            <button id="previewBtn"  class="btn" onmouseover="this.className=‘input_move‘" onmouseout="this.className=‘input_out‘" type="submit" tabindex="6">预    览</button>

CSS代码:

.btn{
    color:#ffffff;
    background:#44b549;
    padding-top:3px;
    border-top: 1px solid #44b549;
    border-right: 1px solid #44b549;
    border-bottom: 1px solid #44b549;
    border-left: 1px solid #44b549;
    width:100px;
    height:30pt;
    font-size:15pt;
    border-radius:3em;
    background-image: linear-gradient(to bottom, #44b549 0px, #44b549 100%);
    -moz-border-radius: 5px;
}     注意一定不能少了这一段,此段定义打开页面时按钮的初始样式。若没有这段,页面打开时按钮不显示样式,直至有鼠标悬停。

 

.input_move{
    color:#ffffff;
    background:#006600;
    padding-top:3px;
    border-top: 1px solid #006600;
    border-right: 1px solid #006600;
    border-bottom: 1px solid #006600;
    border-left: 1px solid #006600;
    width:100px;
    height:30pt;
    font-size:15pt;
    border-radius:3em;
    background-image: linear-gradient(to bottom, #006600 0px, #006600 100%);
    -moz-border-radius: 5px;
}
.input_out{
    color:#ffffff;
    background:#44b549;
    padding-top:3px;
    border-top: 1px solid #44b549;
    border-right: 1px solid #44b549;
    border-bottom: 1px solid #44b549;
    border-left: 1px solid #44b549;
    width:100px;
    height:30pt;
    font-size:15pt;
    border-radius:3em;
    background-image: linear-gradient(to bottom, #44b549 0px, #44b549 100%);
    -moz-border-radius: 5px;
}

    

 

用事件与CSS改变按钮不同状态下的颜色

标签:

原文地址:http://www.cnblogs.com/canyu93/p/5379845.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!