CSS @importกฎ
ตัวอย่าง
นำเข้าสไตล์ชีต "navigation.css" ลงในสไตล์ชีตปัจจุบัน:
@import
"navigation.css"; /* Using a string */
or
@import
url("navigation.css"); /* Using a url */
ตัวอย่างเพิ่มเติมด้านล่าง
ความหมายและการใช้งาน
กฎ@import
อนุญาตให้คุณนำเข้าสไตล์ชีตไปยังสไตล์ชีตอื่น
กฎ@import
ต้องอยู่ที่ด้านบนสุดของเอกสาร (แต่หลัง
การประกาศ @charset
)
กฎ@import
ยังรองรับคิวรีสื่อ ดังนั้นคุณจึงสามารถอนุญาตให้การนำเข้าขึ้นอยู่กับสื่อ
รองรับเบราว์เซอร์
ตัวเลขในตารางระบุเบราว์เซอร์รุ่นแรกที่สนับสนุนคุณสมบัติอย่างสมบูรณ์
Property | |||||
---|---|---|---|---|---|
@import | 1.0 | 5.5 | 1.0 | 1.0 | 3.5 |
ไวยากรณ์ CSS
@import url|string list-of-mediaqueries;
มูลค่าทรัพย์สิน
Value | Description |
---|---|
url|string | A url or a string representing the location of the resource to import. The url may be absolute or relative |
list-of-mediaqueries | A comma-separated list of media queries conditioning the application of the CSS rules defined in the linked URL |
ตัวอย่างเพิ่มเติม
ตัวอย่าง
นำเข้าสไตล์ชีต "printstyle.css" เฉพาะในกรณีที่สื่อพิมพ์:
@import
"printstyle.css" print;
ตัวอย่าง
นำเข้าสไตล์ชีต "mobstyle.css" เฉพาะเมื่อสื่อเป็นหน้าจอและวิวพอร์ตสูงสุด 768 พิกเซล:
@import
"mobstyle.css" screen and (max-width: 768px);