The word-wrap property specifies whether or not to wrap long words that do not fit the width of the specified area.
brief information
Designations
Description | Example | |
---|---|---|
<тип> | Indicates the type of the value. | <размер> |
A && B | The values must be output in the order specified. | <размер> && <цвет> |
A | B | Indicates that you need to select only one value from the proposed ones (A or B). | normal | small-caps |
A || B | Each value can be used independently or together with others in any order. | width || count |
Groups values. | [ crop || cross ] | |
* | Repeat zero or more times. | [,<время>]* |
+ | Repeat one or more times. | <число>+ |
? | The specified type, word, or group is optional. | inset? |
(A, B) | Repeat at least A, but no more than B times. | <радиус>{1,4} |
# | Repeat one or more times separated by commas. | <время># |
Values
normal Lines are not wrapped or are wrapped in places where wrapping is explicitly specified (for example, using
). break-word Line breaks are added automatically to ensure the word fits within the specified block width.
Example
Noun
Excellency
Animate noun
eleventh grader
Chemical substance
methoxychlorodiethylaminomethylbutylaminoacridine
The result of this example is shown in Fig. 1.
Rice. 1. Wrapping long words
Object Model
An object.style.wordWrap
Specification
Each specification goes through several stages of approval.
- Recommendation - The specification has been approved by the W3C and is recommended as a standard.
- Candidate Recommendation ( Possible recommendation) - the group responsible for the standard is satisfied that it meets its goals, but requires help from the development community to implement the standard.
- Proposed Recommendation Suggested Recommendation) - at this stage the document is submitted to the W3C Advisory Council for final approval.
- Working Draft - A more mature version of a draft that has been discussed and amended for community review.
- Editor's draft ( Editorial draft) - a draft version of the standard after changes were made by the project editors.
- Draft ( Draft specification) - the first draft version of the standard.
brief information
CSS versions
CSS 1 | CSS 2 | CSS 2.1 | CSS 3 |
---|---|---|---|
Description
The white-space property specifies how to display spaces between words. IN normal conditions Any number of spaces in HTML code appear as one on a web page. The exception is the tag
Text placed in this container is output with all spaces as it was formatted by the user. So white-space imitates the way the tag worksBut unlike it, it does not change the font to monospace.Syntax
white-space: normal | nowrap | pre | pre-line | pre-wrap | inherit
Values
normal The text in the browser window is displayed as usual, line breaks are set automatically. nowrap Spaces are not taken into account, line breaks in HTML code are ignored, all text is displayed on one line; at the same time, adding a tag
wraps the text on a new line. pre The text is shown taking into account all spaces and hyphens as they were added by the developer in the HTML code. If the line is too long and does not fit in the browser window, a horizontal scroll bar will be added. pre-line Spaces are not taken into account in the text, the text is automatically transferred to next line, if it does not fit into the specified area. pre-wrap All spaces and breaks are preserved in the text, but if the width of the line does not fit into the specified area, the text will automatically be wrapped to the next line. inherit Inherits the value of the parent.The effect of values on text is presented in table. 1.
HTML5 CSS2.1 IE Cr Op Sa Fx
white-space Example
Fermat's Last Theorem
X n+ Y n= Z n
where n is an integer > 2
The result of this example is shown in Fig. 1.
Rice. 1. Applying the white-space property
Object Model
document.getElementById("elementID ").style.whiteSpace
Browsers
Browser Internet Explorer up to version 7.0 inclusive does not support the values pre-line , pre-wrap and inherit . For
Opera before version 9.5 does not support the pre-line value. For
Safari before version 3.0 and iOS do not support pre-wrap and pre-line values.
Firefox up to and including version 2.0 does not support pre-line and pre-wrap values. For
The Internet is made up of content, content is made up of words, and words can be very, very long. And sooner or later the webmaster is faced with the problem of hyphenating long words. This problem is especially relevant for responsive design, and for small blocks of content. So how do you deal with this problem?
Hyphen
The first solution for hyphenating long words is to use a hyphen.
Defisi ( -webkit-hyphens: auto; -moz-hyphens: auto; -ms-hyphens: auto; hyphens: auto; )
Browser support: CSS hyphens are supported by almost all modern browsers, with the exception of Chrome, Opera, Android. Also, very often a hyphen is inserted in places that are grammatically incorrect.
Word break
Word break is CSS property, indicating whether lines should be broken within words.
Obriv-slova ( -ms-word-break: break-all; word-break: break-all; word-break: break-word; )
Browser support: Word breaks are supported in all browsers except Opera Mini and older versions of Opera.
Overflow wrapper
The next solution is to use an overflow-wrap.
Obertka-perepolneniya ( word-wrap: break-word; overflow-wrap: break-word; )
Browser support: Supported in almost all browsers. Note: Some browsers require the use of "word-wrap" instead of "overflow-wrap".
Ellipsis
Another option is to use ellipses.
Mnogotochiye ( overflow: hidden; white-space: nowrap; text-overflow: ellipsis; )
Browser support: Supported by all modern browsers.
This method works, but is far from ideal.
Final solution: Using the Overflow and Hyphen Wrapper.
Finalnoye-resheniye ( overflow-wrap: break-word; word-wrap: break-word; -webkit-hyphens: auto; -ms-hyphens: auto; -moz-hyphens: auto; hyphens: auto; )
This solution will allow a browser that supports it to insert a hyphen, and for browsers that do not support it to insert a line break.