伪元素:focus的使用

介绍一篇关于伪元素的使用。:focus伪类选择器用于获得焦点的表单元素,焦点即光标,一般情况下只有类表单元素才能获取。

简单的类百度的搜索页面。

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        div{
            margin: 100px auto;
            text-align: center;
        }
        .sousuo{
            /* display: block; */
            width: 420px;
            height: 32px;
            /* border: 1px solid yellow; */
        }
        .btn{
            height: 38px;
            background-color: skyblue;
            color: #ffffff;
        }
        .sousuo:focus{
            outline: none;
            border: 1px solid red;
            background-color: skyblue;
        }
        .btn:focus{
            color: red;
        }
    </style>
</head>
<body>
    <div>
        <input type="text" class="sousuo">
        <input type="button" value="搜索" class="btn">
    </div>
</body>
</html>

提示:使用outline来干掉input的默认边框。

posted @ 2020-07-14 19:11  mingshen123  阅读(564)  评论(0)    收藏  举报