Thuộc tính style whiteSpace
Thí dụ
Chỉ định rằng văn bản trong phần tử <div> sẽ không bao giờ quấn:
document.getElementById("myDIV").style.whiteSpace = "nowrap";
Định nghĩa và Cách sử dụng
Thuộc tính whiteSpace đặt hoặc trả về cách xử lý các tab, ngắt dòng và khoảng trắng trong văn bản.
Hỗ trợ trình duyệt
Property | |||||
---|---|---|---|---|---|
whiteSpace | Yes | Yes | Yes | Yes | Yes |
Cú pháp
Trả về thuộc tính whiteSpace:
object.style.whiteSpace
Đặt thuộc tính whiteSpace:
object.style.whiteSpace = "normal|nowrap|pre|initial|inherit"
Giá trị tài sản
Value | Description |
---|---|
normal | Sequences of whitespace will collapse into a single whitespace. Text will wrap when necessary. This is default |
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 |
pre | Whitespace is preserved by the browser. Text will only wrap on line breaks. Acts like the <pre> tag in HTML |
pre-line | Sequences of whitespace will collapse into a single whitespace. Text will wrap when necessary, and on line breaks |
pre-wrap | Whitespace is preserved by the browser. Text will wrap when necessary, and on line breaks |
initial | Sets this property to its default value. Read about initial |
inherit | Inherits this property from its parent element. Read about inherit |
Chi tiết kỹ thuật
Giá trị mặc định: | thông thường |
---|---|
Giá trị trả lại: | Một chuỗi, đại diện cho cách xử lý khoảng trắng bên trong một phần tử |
Phiên bản CSS | CSS1 |
Các ví dụ khác
Thí dụ
Trả về thuộc tính whiteSpace
alert(document.getElementById("myDiv").style.whiteSpace);
Các trang liên quan
Hướng dẫn CSS: Văn bản CSS
Tham chiếu CSS: thuộc tính khoảng trắng
❮ Đối tượng phong cách