UI元素状态伪类选择器

2018-01-23  本文已影响0人  挥剑斩浮云
CSS3 UI元素状态伪类选择器

:focus选择器

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Document</title>
    <style type="text/css">
        input:focus
        {
            outline:1px solid red;
        }
    </style>
</head>
<body>
    <p><label for="name">姓名:</label><input type="text" name="name"/></p>
    <p><label for="email">邮箱:</label><input type="text" name="email"/></p>
</body>
</html>
浏览器效果

:checked选择器

::selection选择器

<style type="text/css">
    div::selection
    {
        background-color:red;
        color:white;
    }
    p::selection
    {
        background-color:orange;
        color:white;
    }
</style>
<body>
    <div>11122222222</div>
    <p>22222222222222</p>
</body>

:enabled与:disabled选择器

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Document</title>
    <style type="text/css">
    input[type="text"]:enabled {
        outline: 1px solid #63E3FF;
    }
    input[type="text"]:disabled {
        background-color: #FFD572;
    }
    </style>
</head>
<body>
    <form>
        <p>
            <label for="enabled">可用:</label>
            <input type="text" name="enabled" />
        </p>
        <p>
            <label for="disabled">禁用:</label>
            <input type="text" name="disabled" disabled="disabled" />
        </p>
    </form>
</body>
</html>
在浏览器预览效果

:read-write与:read-only选择器

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Document</title>
    <style type="text/css">
    input[type="text"]:read-write {
        outline: 1px solid #63E3FF;
    }
    input[type="text"]:read-only {
        background-color: #EEEEEE;
    }
    </style>
</head>
<body>
    <form>
        <p>
            <label for="text1">读写:</label>
            <input type="text" name="text1" />
        </p>
        <p>
            <label for="text2">只读:</label>
            <input type="text" name="text2" readonly="readonly" />
        </p>
    </form>
</body>
</html>
在浏览器预览效果

::before和::after选择器

::before    在元素之前插入内容
::after     在元素之后插入内容'
上一篇 下一篇

猜你喜欢

热点阅读