Html space-interesting experiment-beidan first, let's take a look at a group of demos.
1 2
Display Effect:
Why is there a space? Isn't input a row element? Change the code and check the effect.
If there is no gap between two inputs, the following space disappears.
Test A group of row elements:
1Line Element2Line Element3Line Element4Line Element5Line Element
The results are as follows:
To make the spacing between the elements in the row disappear, we manually delete the extra gaps generated between the elements in the row. The Code is as follows:
1Line ElementLine ElementLine ElementLine ElementLine Element
As follows:
Using this method can indeed remove the spacing between elements in the row, but the code is heap into a piece and it seems uncomfortable. How can this problem be solved?
I. Use font-size: 0
Principle:The spacing of elements in a row is caused by line breaks, tabs, spaces, and other characters. The character size is controlled by defining the font size. Therefore, to remove the interval, you can start by changing the font size.That is, set the font-size of the parent element of the current row: 0;
12Line Element3Line Element4Line Element5Line Element6Line Element7
1 p{2 font-size: 0px;3 }4 span{5 font-size: 14px;6 }
As follows: Hey, the spacing between elements in the row is gone
This method basically solves the gap between inline and inline-block elements in most browsers (ie 7 and other browsers sometimes have 1 pixel spacing ). But there is a browser, that isChrome, ItsThe minimum font size limit is available by default.Because, considering compatibility, we also need to add:
1 p {2 font-size: 0; 3-webkit-text-size-adjust: none;/* use the private attributes of webkit to prevent the font size from being adjusted by the device terminal, it can be defined that the font size is smaller than 12px */4 * word-spacing:-1px;/* use word-spacing to fix the 1px gap that always exists in IE6 and 7, reduce the gap between words (that is, the word interval) */5}
--------------------------------Correction----------------------------------
After chrome is updated to the official version 27,-Webkit-text-size-adjust is no longer supported-Webkit-text-size-adjust is invalid.
Solution reference this link -- http://www.zhihu.com/question/21093147? Rf = 1, 21339583
--------------------------------Correction----------------------------------
In general, we may want to use the following code to achieve some results.
1Line Element
2Line Element
However, this is because, by default, when the browser parses html,HThe blank characters in the TML source code are displayed as spaces, and multiple consecutive blank characters are considered as one.
In HTML, "Blank space" includes space, tab, and line feed (CR/LF.
This cannot be difficult. We should use a space replacement symbol.
1Line Element
2Line Element
:
| Name |
No. |
Description |
| |
|
Blank row (1 character width) |
| |
^ |
Half blank (1 character width) |
| |
|
Blank (2 Characters in width) |
| |
|
Narrow white space (less than 1 character width)
|
- Usage:The name or number can be used as an alternative symbol for spaces. The name must be in lowercase and the ";" at the end cannot be omitted. Generally, we use (that is, the space Generated by pressing the space key .)
1. white-space
However, if we want to achieve the following effect? Is there a certain degree of indentation? Do you want to use margin and padding? And so on?
1 2 function sum(x,y){3 var sum = x + y;4 return sum;5 }6
When the value of the white-space attribute is pre, the browser retains spaces and line breaks in the text, so that you can use spaces and press enter directly in the text.
2. letter-spacing
Setting textBetween charactersIt can be a length value with a unit. The browser will set a blank length between words.
1Welcome!
3. word-spacing
Setting textBetween wordsIt can be a length value with units.
1 Happy new year!
4. text-indent
Sometimes, each section of the article needs to be indented to achieve that effect?
UseText-indentSetFirst line indentIt can be a length value with units,
1Welcome!