In the process of learning the basic code of html, I believe it will involve how to write the space code of html. We usually use spaces when editing programs. The character entity of the html space code is a non-breaking space . This is the space code in html. Of course, there are space symbols, space characters, blank lines, etc. The following article will explain these contents related to spaces one by one.
1. You can first take a look at "HTML/CSS Quick Start" Introduction to spaces in the tutorial
1. Introduction to spaces in HTML character entities
Multiple spaces in html will be shortened into one by the browser, so We need to use to achieve the purpose of multiple spaces. nbsp is non-breaking space, which is different from ordinary spaces, that is, it does not break white spaces. That is to say, is used in HTML code to generate a blank and prevent the browser from wrapping lines in this blank. For example, using in two tags can prevent line wrapping caused by the image being too wide to exceed the width of the browser. That is to say, if you use normal spaces, when the browser width is not enough, the second img will be folded to the next line, and with the two img will be displayed on the same line.
2. Sharing about space characters and space symbols in HTML
1. About the summary of space character entities in HTML Share
Non-breaking space (non-breaking space) character encoding: In HTML, generated by pressing the space key, spaces do not accumulate (only count as 1) , you need to use html entity representation to be able to accumulate.
Full-width space (Em Space) character encoding: em is the unit of measurement for typography. It is equivalent to the currently specified point number. For example, 1em in a 16px font is 16px. This space has a very robust characteristic, and the width it occupies is exactly 1 Chinese width.
Half-width space (En Space) character encoding: en is the unit of measurement for typography. It is half the width of em. For example, 1en is 16px in a 16px font, which is nominally the width of the lowercase letter n. This space has a very robust characteristic, and the width it occupies is exactly 1/2 the Chinese width.
Character usage skills:
1) Character output in HTML uses with charCode value;
2) In JavaScript files, to prevent garbled escaping, \u is paired with charCode Value;
3) In the CSS file, such as the content attribute of the CSS pseudo-element, use \ directly with the charCode value.
3. Introduction and usage instructions of spaces in HTML
1. Detailed introduction on how to insert spaces in HTML
Normally, we use the space bar to type multiple spaces, and When writing code, spaces typed by the space bar, Tab key and Enter key will be automatically ignored by HTML (Hypertext Markup Language). HTML treats such keys as whitespace characters and displays them as a single whitespace interval. Although CSS provides various styles of spacing and indentation, there are also tools in HTML that allow you to define spacing yourself.
2. HTML 6 types of spaces description
Non-line breaking spaces ( ) are the width of regular spaces and can run in all major browsers. Several other spaces ( , , , , ) have different widths in different browsers.
It is called No-Break Space. It is the most common and most used space. Most people may only be exposed to . It is a space generated by pressing the space key. In HTML, if you use the space bar to generate this space, the spaces will not accumulate (only count as 1). It can only be accumulated using html entity representation. The width occupied by this space is obviously and strongly affected by the font.
3. A brief discussion on spaces and empty lines in HTML code
Method 1: We can use the pre-formatted tag
, whether it is a space or an empty line Applicable to all lines. <p>Method 2: We can use the space entity character to replace spaces, and the newline tag <br> to replace blank lines. Although this method can get the display effect we want, it is not the most friendly to search engines because and <br> have no semantics in HTML. So it is recommended to use it as little as possible. Also note that must be lowercase, and the semicolon at the end cannot be omitted. </p><p>Method three: (suitable for spaces) Use full-width spaces</p><p><span style="color: rgb(255, 0, 0); font-size: 16px;"><strong>Questions and answers about spaces in HTML</strong></span></p>##1. <p>HTML document </p><p> tag, how to remove spaces within a paragraph. <a href="http://www.php.cn/wenda/71975.html" target="_self"></a></p>2. <p>li How to remove the default space in front of it? <a href="http://www.php.cn/wenda/70826.html" target="_self"></a></p>3. Why are the spaces entered in <p>html not displayed? <a href="http://www.php.cn/wenda/2785.html" target="_self"></a></p>【Related recommendations】<p></p>1. <p>Summary of space symbols and space character entities in html<a href="http://www.php.cn/div-tutorial-363813.html" target="_self"></a></p>
The above is the detailed content of Summarize various methods of how to use spaces in html. For more information, please follow other related articles on the PHP Chinese website!