码迷,mamicode.com
首页 > 其他好文 > 详细

一些新的伪选择器

时间:2017-11-18 17:33:36      阅读:147      评论:0      收藏:0      [点我收藏+]

标签:round   max   输入   har   显示   lang   order   meta   ace   

作为一些还未被浏览器完全支持的伪选择器,作为渐进增强还是不错的。

 

placeholder-show:placeholder显示出来的时候

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>placeholder-shown</title>
    <style>
        form{
            position: relative;
            padding-top: 30px;
        }
        label{
            position: absolute;
            top: 0;
            left: 0;
            font-size: var(--font-size-small);
            opacity: 1;
            transform: translateY(0);
            transition: .2s;
        }
        input:placeholder-shown + label{
            opacity: 0;
            transform: translateY(1em);
        }
    </style>
</head>
<body>
    <form action="">
        <input type="text" name="" id="" placeholder="Enter some text">
        <label for="">enter some text</label>
    </form>
</body>
</html>

 

required:必填的输入框

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>required</title>
    <style>
        span{
            opacity: 0
        }
        input:required + span{
            opacity: 1
        }
    </style>
</head>
<body>
    <form action="">
        <input type="text" name="" id="" placeholder="Enter some text" required>
        <span>required</span><br>

        <input type="text" name="" id="" placeholder="Enter some text">
        <span>required</span>
    </form>
</body>
</html>

 

 

disabled:禁止输入

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>disabled</title>
    <style>
        span{
            opacity: 0
        }
        input:disabled{
            border: 1px solid #ccc;
        }
    </style>
</head>
<body>
    <form action="">
        <input type="text" name="" id="" placeholder="Enter some text" disabled>
    </form>
</body>
</html>

 

read-only:只读

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>read-only</title>
    <style>
        span{
            opacity: 0
        }
        input:read-only{
            background-color: var(--gray-lighter);
        }
    </style>
</head>
<body>
    <form action="">
        <input type="text" name="" id="" placeholder="Enter some text" readonly>
    </form>
</body>
</html>

 

out-of-range:number类型的输入框超过了限定值

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>out-of-range</title>
    <style>
        span{
            opacity: 0
        }
        input:out-of-range + span{
            opacity: 1
        }
    </style>
</head>
<body>
    <form action="">
        <input type="number" name="" id="" placeholder="Enter some text" min="0" max="10">
        <span>out of range</span>
    </form>
</body>
</html>

 

一些新的伪选择器

标签:round   max   输入   har   显示   lang   order   meta   ace   

原文地址:http://www.cnblogs.com/11lang/p/7857140.html

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