ใช้ตัวเลือก CSS :empty เพื่อจัดรูปแบบทุก
องค์ประกอบที่ไม่มีลูกที่มี CSS คุณสามารถลองเรียกใช้โค้ดต่อไปนี้เพื่อใช้งาน :empty selector -
ตัวอย่าง
<!DOCTYPE html>
<html>
<head>
<style>
p.demo {
width: 300px;
height: 20px;
background: gray;
}
p:empty {
width: 150px;
height: 20px;
background: orange;
}
</style>
</head>
<body>
<p class = "demo">This is demo text. Below is empty text.</p>
<p></p>
</body>
</html>