Thuộc tính nội dung CSS
Ví dụ
Ví dụ sau chèn giá trị của thuộc tính href vào dấu ngoặc đơn sau mỗi phần tử <a>:
a::after {
content: " (" attr(href) ")";
}
Hãy tự mình thử »Thêm ví dụ "Hãy tự mình thử" bên dưới.
Định nghĩa và cách sử dụng
Thuộc tính content
được sử dụng với các phần tử giả ::trước và ::after để chèn nội dung được tạo.
Giá trị mặc định: | Bình thường |
---|---|
Thừa hưởng: | KHÔNG |
Hoạt hình: | KHÔNG. Đọc về hoạt hình |
Phiên bản: | CSS2 |
Cú pháp JavaScript: | Bạn không thể gán cho một phần tử một lớp giả bằng cách sử dụng JavaScript, nhưng có nhiều cách khác để có được kết quả tương tự: Hãy thử |
Hỗ trợ trình duyệt
Các số trong bảng chỉ định phiên bản trình duyệt đầu tiên hỗ trợ đầy đủ thuộc tính.
Property | |||||
---|---|---|---|---|---|
content | 1.0 | 8.0 | 1.0 | 1.0 | 4.0 |
Cú pháp CSS
content: normal|none|counter|attr| string |open-quote|close-quote|no-open-quote|no-close-quote| url |initial|inherit;
Giá trị tài sản
Value | Description | Example |
---|---|---|
normal | Default value. Sets the content, if specified, to normal, which default is "none" (which is nothing) | Try it » |
none | Sets the content, if specified, to nothing | Try it » |
counter | Sets the content as a counter | Try it » |
attr (attribute) | Sets the content as one of the selector's attribute | Try it » |
string | Sets the content to the text you specify | Try it » |
open-quote | Sets the content to be an opening quote | Try it » |
close-quote | Sets the content to be a closing quote | Try it » |
no-open-quote | Removes the opening quote from the content, if specified | Try it » |
no-close-quote | Removes the closing quote from the content, if specified | Try it » |
url( url ) | Sets the content to be some kind of media (an image, a sound, a video, etc.) | Try it » |
initial | Sets this property to its default value. Read about initial | |
inherit | Inherits this property from its parent element. Read about inherit | Try it » |
Thêm ví dụ
Ví dụ
Cách thêm màu dấu đầu dòng cho <ul> hoặc <ol> bằng cách xóa dấu đầu dòng mặc định của chúng và thêm thực thể HTML trông giống dấu đầu dòng (•):
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 */
}
Hãy tự mình thử »Trang liên quan
Tham chiếu CSS: :: trước phần tử giả
Tham chiếu CSS: ::after phần tử giả