White space characters: spaces, tabs, newline characters
Note: When parsing HTML, the browser will combine all whitespace characters into one space
Poor structure causes unexpected results:
The tag is wrapped:
<span style="color: #008080">1</span> <span style="color: #008000"><!--</span><span style="color: #008000">文本域结束标签 换行导致placeholder无法正确表示</span><span style="color: #008000">--></span><span style="color: #008080">2</span> <span style="color: #0000ff"><</span><span style="color: #800000">textarea </span><span style="color: #ff0000">id</span><span style="color: #0000ff">="description"</span><span style="color: #ff0000"> name</span><span style="color: #0000ff">="description"</span><span style="color: #ff0000"> rows</span><span style="color: #0000ff">="5"</span><span style="color: #ff0000"> cols</span><span style="color: #0000ff">="30"</span><span style="color: #ff0000"> wrap</span><span style="color: #0000ff">="physical"</span><span style="color: #ff0000"> placeholder</span><span style="color: #0000ff">="这是一个多行输入框,输入您的个人描述"</span><span style="color: #0000ff">><br></</span><span style="color: #800000">textarea</span><span style="color: #0000ff">></span>
There are spaces between tags:
1 <!--文本域标签之间有空格,导致placeholder无法正确表示-->2 <textarea id="description" name="description" rows="5" cols="30" wrap="physical" placeholder="这是一个多行输入框,输入您的个人描述"> </textarea>
Result: blank
## Reason: Because the form area contains whitespace characters (spaces, tabs, newline characters), the whitespace characters in the textarea are considered content, preventing the display of placeholder text. Correct operation:1 <!--文本域开始标签与结束标签紧挨着,placeholder正确表示-->2 <textarea id="description" name="description" rows="5" cols="30" wrap="physical" placeholder="这是一个多行输入框,输入您的个人描述"></textarea>
1 <ul>2 <li>item1</li>3 <li>item2</li>4 <li>item3</li>5 <li>item4</li>6 <li>item5</li>7 </ul>
1 *{ 2 margin: 0; 3 padding: 0; 4 } 5 ul { 6 list-style: none outside none; 7 padding: 10px; 8 background: green; 9 text-align: center;10 }11 ul li {12 display: inline-block;13 *display: inline;14 zoom: 1;15 background: orange;16 padding: 5px;17 }
1 <ul>2 <li>item1</li3 ><li>item2</li4 ><li>item3</li5 ><li>item4</li6 ><li>item5</li>7 </ul>
<span style="color: #0000ff"><</span><span style="color: #800000">div</span><span style="color: #0000ff">></span><span style="color: #000000">They can stay 72-hours within the Shandong province after they have entered China via the Qingdao International Airport.</span><span style="color: #0000ff"></</span><span style="color: #800000">div</span><span style="color: #0000ff">><br></span>
结果:浏览器解析的时候只保留单词之间的空白符被合并为一个空格。 They can stay 72-hours within the Shandong province after they have entered China via the Qingdao International Airport.
normal: 合并空白符,允许自动换行 nowrap: 合并空白符,不允许自动换行 pre-line: 合并空白符(不包括换行符),允许自动换行 pre: 不合并空白符,不允许自动换行 pre-wrap: 不合并空白符,允许自动换行(在pre基础上,保留自动换行)
SupplementaryPoint: CSS3 has added two new line wrapping properties, word-wrap and word-break.
The above is the detailed content of What is whitespace? The impact of whitespace characters on HTML structure. For more information, please follow other related articles on the PHP Chinese website!