The white-space property specifies how to display spaces between words. Under normal circumstances, 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 works
But 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 moved to the 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
Internet Explorer versions up to and including 7.0 do not support pre-line , pre-wrap , or inherit values. 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
Line feed, line break, line break - it's all about the same thing. In HTML, newlines are often used. There are several ways: use a tag to break to a new line, or you can use CSS properties to break a line. Let's look at an example of using a line break tag:
In CSS, line breaks can be done in different ways, for example like this:
Br( float: left; width: 100%; margin: 0 0 20px 0; /* indent after line 20 pixels */ }
Divider line using HTML or CSS
In HTML, creating a dividing line is very simple. An unpaired tag is also used
- this is the dividing line. The dividing line starts on a new line and is indented after it. You can control the style of the horizontal line, and you can also create an alternative to it. Below is an example of a dividing line using a tag:
Now let's style (change the styles, change the appearance) our dividing line:
hr ( width: 80%; /* line width */ height: 4px; /* line height / thickness */ background: #333; /* background / line color */ border: 0; /* frame around the dividing line (remove it) */ margin: 5px 0 5px 0; /* padding above and below the line 5 pixels */ }
And let's create an alternative to our dividing line using the tag
and CSS.
When displaying text documents in a browser, the location of line breaks within a paragraph is determined automatically depending on the size of the fonts and the size of the viewing window. Line breaks can only be carried out using word separator characters (for example, spaces). Sometimes in documents you need to set a forced line feed, which is implemented regardless of the browser settings. This is done using the forced line feed tag. , which does not have a corresponding closing tag. Enabling a tag into the document text will ensure that subsequent text is placed at the beginning of a new line. For example, this approach can be used to create list-type structures without using special list markup tags. Or, for example, this tag cannot be used to display poems, etc.
Here is an example of using forced line feed (Fig. 1.8):
Using forced line feed
Over darkened Petrograd
November breathed the autumn chill.
Splashing with a noisy wave
To the edges of your slender fence,
Neva was tossing around like a sick person
Restless in my bed.
A.S. Pushkin. Bronze Horseman
Rice. 1.8. Tag can be used to force a line feed
Unlike the paragraph tag
When using the tag an empty string will not be generated.
Using a tag requires caution - it is possible that the browser has already made a line break one or two words before it encountered your tag . This happens if the reader's viewer window width is smaller than the same setting of the program with which you tested your document. In this case, it may turn out that only one word remains on a line in the middle of a paragraph, thereby ruining the beauty of the document layout.
Note
When using the tag To break text around an image or table, you can set the CLEAR parameter to stop text wrapping. You can read about this in chapters 3 and 4.
Tags u
There are situations when you need to perform the opposite operation - disable line feed. There is a container tag for this . Text marked with this tag is guaranteed to fit on one line, regardless of its length. If the resulting line extends beyond the browser's viewing window, a horizontal scroll bar will appear.
Note
To ensure the continuity of text located in table cells, there is a special parameter of the NOWRAP tag
. You can learn more about this in Chapter 4.
Marking up text with a non-breaking line tag you can get very long strings. To avoid this, you can indicate to the reader's browser the location of a possible line feed, which will be performed only when necessary (the so-called "soft" line feed). This can be done by placing a tag in the right place in the text (Word BReak), which is the same as the tag , does not need a closing tag.
Note
Tag is not supported at all by the Netscape browser. Microsoft Internet Explorer recognizes this tag only in tagged text .
It is often necessary to wrap text inside one Excel cell to a new line. That is, move the text along the lines inside one cell as indicated in the picture. If, after entering the first part of the text, you simply press the ENTER key, the cursor will be moved to the next line, but to a different cell, and we need a transfer in the same cell.
This is a very common task and it can be solved very simply - to move text to a new line inside one Excel cell, you need to click ALT+ENTER(hold down the ALT key, then without releasing it, press the ENTER key)
How to Wrap Text on a New Line in Excel Using a Formula
Sometimes you need to make a line break not just once, but using functions in Excel. Like in this example in the figure. We enter the first name, last name and patronymic and it is automatically collected in cell A6
In the window that opens, in the “Alignment” tab, you must check the box next to “Word wrap” as indicated in the picture, otherwise line wrapping in Excel will not be displayed correctly using formulas.
How to replace a hyphen in Excel with another character and back using a formula
Can change the hyphen symbol to any other character, for example on a space, using the text function SUBSTITUTE in Excel
Let's take an example of what is in the picture above. So, in cell B1 we write the SUBSTITUTE function:
SUBSTITUTE(A1,CHAR(10), " ")
A1 is our text with a line break; CHAR(10) is a line break (we looked at this a little higher in this article); " " is a space because we are changing the line break to a space
If you need to do the opposite operation - replace the space with a hyphen (symbol), then the function will look like this:
SUBSTITUTE(A1; " ";CHAR(10))
Let me remind you that in order for line breaks to be reflected correctly, you must specify “Wrap across lines” in the cell properties, in the “Alignment” section.
How to change the hyphen to a space and back in Excel using SEARCH - REPLACE
There are times when formulas are inconvenient to use and replacements need to be made quickly. To do this, we will use Search and Replace. Select our text and press CTRL+H, the following window will appear.
If we need to change the line break to a space, then in the “Find” line we need to enter a line break, for this stand in the “Find” field, then press the ALT key, without releasing it, type 010 on the keyboard - this is a line break code, it will not be visible in this field.
After that, in the “Replace with” field, enter a space or any other character that you need to change to and click “Replace” or “Replace All”.
By the way, this is implemented more clearly in Word.
If you need to change the line break character to a space, then in the “Find” field you need to indicate a special “Line Break” code, which is denoted as ^l In the “Replace with:” field, you just need to make a space and click on “Replace” or “Replace All”.
You can change not only line breaks, but also other special characters, to get their corresponding code, you need to click on the “More >>”, “Special” button and select the code you need. Let me remind you that this function is only available in Word; these symbols will not work in Excel.
How to change line break to space or vice versa in Excel using VBA
Let's look at an example for selected cells. That is, we select the required cells and run the macro
1. Change spaces to hyphens in selected cells using VBA
Sub SpacesToHyphens() For Each cell In Selection cell.Value = Replace(cell.Value, Chr(32) , Chr(10) ) Next End Sub
2. Change hyphens to spaces in selected cells using VBA
Sub WrapsToSpaces() For Each cell In Selection cell.Value = Replace(cell.Value, Chr(10) , Chr(32) ) Next End Sub
The code is very simple: Chr (10) is a line break, Chr (32) is a space. If you need to change to any other symbol, then simply replace the code number corresponding to the required symbol.
Character codes for Excel
The picture below shows various symbols and their corresponding codes; several columns represent different fonts. To enlarge the image, click on the picture.