首頁  >  文章  >  web前端  >  css中button按鈕的狀態有哪些?

css中button按鈕的狀態有哪些?

藏色散人
藏色散人原創
2018-08-15 15:45:066485瀏覽

本篇文章主要介紹關於css button按鈕的多種狀態。希望對有需要的朋友有幫助。

先給大家舉一段button按鈕的狀態碼範例如下:

<!DOCTYPE html>
<html>
<head lang="en">
    <meta charset="UTF-8">
    <title>button按钮的状态代码不同效果示例</title>
    <style>
        .btn{
            appearance: none;
            background: #026aa7;
            color: #fff;
            font-size: 20px;
            padding: 0.65em 1em;
            border-radius: 4px;
            box-shadow: inset 0 -4px 0 0 rgba(0,0,0,0.2);
            margin-right: 1em;
            cursor: pointer;
            border:0;
        }
        .btn1:hover{
            box-shadow: inset 0 -4px 0 0 rgba(0,0,0,0.6), 0 0 8px 0 rgba(0,0,0,0.5);
        }
        .btn1:focus{
            position: relative;
            top: 4px;
            box-shadow: inset 0 3px 5px 0 rgba(0,0,0, 0.2);
            outline: 0;
        }
        .btn2:hover{
            box-shadow: inset 0 -4px 0 0 rgba(0,0,0,0.6), 0 0 8px 0 rgba(0,0,0,0.5);
        }
        .btn2:active{
            position: relative;
            top: 4px;
            box-shadow: inset 0 3px 5px 0 rgba(0,0,0,0.2);
            outline: 0;
        }
        .btn2:focus{
            outline: 0;
        }
    </style>
</head>
<body>
<button class="btn btn1">点击不会弹起</button>
<button class="btn btn2">点击会弹起</button>
</body></html>

以上程式碼可直接複製貼上在本機測試,效果如下圖:

css中button按鈕的狀態有哪些?

綜上所述,請為大家總結關於button按鈕的幾個狀態:

  1. 普通狀態

  2.  hover 滑鼠懸停狀態

  3. #active 點選狀態

  4. focus 取得焦點狀態

註:.btn:focus{outline:0;} 可以移除按鈕或a標籤點擊後的藍色邊框

cursor 屬性規定要顯示的遊標的類型(形狀)。此屬性定義了滑鼠指標放在一個元素邊界範圍內時所使用的遊標形狀

:active 選擇器用於選擇活動連結。當您在一個連結上點擊時,它就會成為活動的(已啟動的)。

希望這篇關於button狀態的不同情況介紹,對有需要的朋友有幫助。


#

以上是css中button按鈕的狀態有哪些?的詳細內容。更多資訊請關注PHP中文網其他相關文章!

陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn