Thuộc tính khoảng trắng CSS
Ví dụ
Chứng minh các giá trị khác nhau của thuộc tính khoảng trắng:
p.a {
white-space: nowrap;
}
p.b {
white-space: normal;
}
p.c {
white-space:
pre;
}
Hãy tự mình thử »Định nghĩa và cách sử dụng
Thuộc tính white-space
chỉ định cách xử lý khoảng trắng bên trong một phần tử.
Giá trị mặc định: | Bình thường |
---|---|
Thừa hưởng: | Đúng |
Hoạt hình: | KHÔNG. Đọc về hoạt hình |
Phiên bản: | CSS1 |
Cú pháp JavaScript: | object .style.whiteSpace="nowrap" Hãy dùng 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 | |||||
---|---|---|---|---|---|
white-space | 1.0 | 8.0 | 3.5 | 3.0 | 9.5 |
Cú pháp CSS
white-space: normal|nowrap|pre|pre-line|pre-wrap|initial|inherit;
Giá trị tài sản
Value | Description | Demo |
---|---|---|
normal | Sequences of whitespace will collapse into a single whitespace. Text will wrap when necessary. This is default | Demo ❯ |
nowrap | Sequences of whitespace will collapse into a single whitespace. Text will never wrap to the next line. The text continues on the same line until a <br> tag is encountered | Demo ❯ |
pre | Whitespace is preserved by the browser. Text will only wrap on line breaks. Acts like the <pre> tag in HTML | Demo ❯ |
pre-line | Sequences of whitespace will collapse into a single whitespace. Text will wrap when necessary, and on line breaks | Demo ❯ |
pre-wrap | Whitespace is preserved by the browser. Text will wrap when necessary, and on line breaks | Demo ❯ |
initial | Sets this property to its default value. Read about initial | |
inherit | Inherits this property from its parent element. Read about inherit |
Trang liên quan
Hướng dẫn CSS: Khoảng cách văn bản CSS
Tham chiếu DOM HTML: thuộc tính whiteSpace