Computer >> Hướng Dẫn Máy Tính >  >> Lập Trình >> CSS

Tạo kiểu cho phần tử được focus với CSS (:focus)

Giới thiệu

Để chọn phần tử đang được focus, sử dụng bộ chọn :focus.

Ví dụ

<!DOCTYPE html>
<html>
<head>
    <style>
        input:focus {
            background-color: green;
        }
    </style>
</head>
<body>
    <form action="">
        Môn học <input type="text" name="subject"><br>
        Học sinh: <input type="text" name="student"><br>
        Tuổi: <input type="number" name="age"><br>
        <input type="submit" value="Gửi">
    </form>
</body>
</html>