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

จัดสไตล์ <p> ที่มี Attribute lang ด้วย CSS :lang Selector

ใช้ :lang() เพื่อจัดสไตล์ Element ที่มี Attribute lang ตรงกับภาษาที่ระบุ

ตัวอย่าง

<!DOCTYPE html>
<html>
<head>
    <style>
        p:lang(fr) {
            background: green;
        }
    </style>
</head>
<body>
    <p>This is my country</p>
    <p lang="fr">C'est mon pays</p>
    <p>French is the language of France</p>
</body>
</html>

ผลลัพธ์: เฉพาะ <p lang="fr"> เท่านั้นที่มีพื้นหลังสีเขียว