用事件與CSS改變按鈕不同狀態下的顏色


目標效果:

    表單的群發按鈕,在鼠標懸停時為深藍色,鼠標離開時為淡藍色。

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;
}

    

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM