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

บทบาทของ CSS :last-child Selector

ใช้ :last-child เพื่อจัดสไตล์ <p> ที่เป็นลูกคนสุดท้ายของ Parent

ตัวอย่าง

<!DOCTYPE html>
<html>
<head>
    <style>
        p:last-child {
            background: orange;
        }
    </style>
</head>
<body>
    <p>This is demo text1.</p>
    <p>This is demo text2.</p>
    <p>This is demo text3.</p>
</body>
</html>

ผลลัพธ์: <p> ตัวที่ 3 ("This is demo text3") จะมีพื้นหลังส้ม