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

ตัวเลือก Universal Selector ใน CSS


ตัวเลือก * ใน CSS เป็นตัวเลือกสากล (universal selector) ซึ่งใช้เลือกองค์ประกอบทั้งหมดของ HTML DOM

ไวยากรณ์

ไวยากรณ์สำหรับตัวเลือกสากล CSS ดังนี้:

* {    /*declarations*/ }

ตัวอย่างต่อไปนี้แสดงตัวเลือกสากล CSS:

ตัวอย่าง

<!DOCTYPE html> <html> <head> <style> * {    margin: 15px;    padding: 5px;    border: 2px solid black;    box-shadow: inset 30px 0 8px lightblue; } </style> </head> <body> <table> <tr> <td></td> <td></td> </tr> <tr> <td></td> <td></td> <td></td> <td></td> </tr> </table> </body> </html>

ผลลัพธ์

ตัวเลือก Universal Selector ใน CSS

ตัวอย่างเพิ่มเติม

<!DOCTYPE html> <html> <head> <style> * {    margin: 15px;    padding: 5px;    width: 200px;    border: 2px solid black; } html::before {    content: "one"; } </style> </head> <body> two <div>three <div>four <div>five</div> </div> </div> </body> </html>

ผลลัพธ์

ตัวเลือก Universal Selector ใน CSS