คุณสมบัติเนื้อหา CSS
ตัวอย่าง
ตัวอย่างต่อไปนี้จะแทรกค่าของแอตทริบิวต์ href ในวงเล็บหลังแต่ละองค์ประกอบ <a>:
a::after {
content: " (" attr(href) ")";
}
ตัวอย่าง "ลองใช้เอง" เพิ่มเติมด้านล่าง
ความหมายและการใช้งาน
คุณสมบัติcontent
นี้ใช้กับ
::beforeและ::after pseudo-elements เพื่อแทรกเนื้อหาที่สร้างขึ้น
ค่าเริ่มต้น: | ปกติ |
---|---|
รับการถ่ายทอด: | ไม่ |
เคลื่อนไหวได้: | ไม่. อ่านเกี่ยวกับแอนิเมชั่น |
รุ่น: | CSS2 |
ไวยากรณ์ JavaScript: | คุณไม่สามารถกำหนดคลาสหลอกให้กับองค์ประกอบได้โดยใช้ JavaScript แต่มีวิธีอื่นๆ เพื่อให้ได้ผลลัพธ์เช่นเดียวกัน: |
รองรับเบราว์เซอร์
ตัวเลขในตารางระบุเบราว์เซอร์รุ่นแรกที่สนับสนุนคุณสมบัติอย่างสมบูรณ์
Property | |||||
---|---|---|---|---|---|
content | 1.0 | 8.0 | 1.0 | 1.0 | 4.0 |
ไวยากรณ์ CSS
content: normal|none|counter|attr|string|open-quote|close-quote|no-open-quote|no-close-quote|url|initial|inherit;
มูลค่าทรัพย์สิน
Value | Description | Example |
---|---|---|
normal | Default value. Sets the content, if specified, to normal, which default is "none" (which is nothing) | |
none | Sets the content, if specified, to nothing | |
counter | Sets the content as a counter | |
attr(attribute) | Sets the content as one of the selector's attribute | |
string | Sets the content to the text you specify | |
open-quote | Sets the content to be an opening quote | |
close-quote | Sets the content to be a closing quote | |
no-open-quote | Removes the opening quote from the content, if specified | |
no-close-quote | Removes the closing quote from the content, if specified | |
url(url) | Sets the content to be some kind of media (an image, a sound, a video, etc.) | |
initial | Sets this property to its default value. Read about initial | |
inherit | Inherits this property from its parent element. Read about inherit |
ตัวอย่างเพิ่มเติม
ตัวอย่าง
วิธีเพิ่มสีสัญลักษณ์แสดงหัวข้อย่อยสำหรับ <ul> หรือ <ol> โดยการลบสัญลักษณ์แสดงหัวข้อย่อยเริ่มต้นและเพิ่มเอนทิตี HTML ที่ดูเหมือนสัญลักษณ์แสดงหัวข้อย่อย (•):
ul {
list-style: none; /* Remove HTML bullets */
padding: 0;
margin: 0;
}
li {
padding-left: 16px;
}
li::before {
content: "•"; /* Insert content that looks like bullets */
padding-right: 8px;
color: blue; /* Or a color you prefer */
}
หน้าที่เกี่ยวข้อง
การอ้างอิง CSS: ::before pseudo element
การอ้างอิง CSS: ::หลังจากองค์ประกอบหลอก