Computer >> บทช่วยสอนคอมพิวเตอร์ >  >> การเขียนโปรแกรม >> CSS

บทบาทของ CSS :read-only Selector

ใช้ :read-only เพื่อเลือก Element ที่เป็น Read-only (ไม่สามารถแก้ไขได้ เช่น Input ที่มี Attribute readonly)

ตัวอย่าง

<!DOCTYPE html>
<html>
<head>
    <style>
        input:read-only {
            background-color: blue;
            color: white;
        }
    </style>
</head>
<body>
    <form>
        Subject: <input type="text" name="subject" value="Maths"><br>
        Student: <input type="text" name="student" readonly value="Amit"><br>
    </form>
</body>
</html>

ผลลัพธ์: Input "Student" ที่มี readonly จะมีพื้นหลังสีน้ำเงิน ตัวอักษรสีขาว