如何在HTML中插入空格

方法 1

方法 1 的 4:在单词之间添加额外的空格

WH.shared.addScrollLoadItem(‘b6173b8e3339659f7f46a428bf24897a’)

WH.performance.clearMarks(‘image1_rendered’); WH.performance.mark(‘image1_rendered’);{“smallUrl”:”https://www.wikihow.com/images_en/thumb/1/11/593311-1.jpg/v4-460px-593311-1.jpg”,”bigUrl”:”https://www.wikihow.com/images/thumb/1/11/593311-1.jpg/v4-728px-593311-1.jpg”,”smallWidth”:460,”smallHeight”:345,”bigWidth”:728,”bigHeight”:546,”licensing”:”

“}
1
在文本编辑器中打开HTML代码。你可以使用任何文本编辑器,比如Windows的记事本,或者MacOS的TextEdit,这些编辑器都能用来编辑代码。就算按再多次空格键在单词或字符之间添加额外的空格,你都不会在网页上看到这些额外的空格——HTML会自动将多个空格转换成一个空格。你可以用不间断的空格符而不是通过按空格键的方式来解决这个问题。
WH.performance.mark(‘step1_rendered’);

WH.shared.addScrollLoadItem(‘ad13bca418f4f9294d5659dca385dc19’)

{“smallUrl”:”https://www.wikihow.com/images_en/thumb/3/3d/593311-2.jpg/v4-460px-593311-2.jpg”,”bigUrl”:”https://www.wikihow.com/images/thumb/3/3d/593311-2.jpg/v4-728px-593311-2.jpg”,”smallWidth”:460,”smallHeight”:345,”bigWidth”:728,”bigHeight”:546,”licensing”:”

“}
2
在要插入额外空格的地方输入 。要添加一个空格,你就得输入一个不间断的空格符。与在HTML代码中反复按空格键不同,你输入了多少个 就会显示多少个空格。
X
研究来源

比如,假设你想在“What will you learn”和“today? ”之间出现三个空格。你可以直接在它们之间输入   ,而不是按三次空格键。示例如下:

wikiHow: How-to instructions you can trust.

What will you learn   today?

基本上, 在HTML中都会被直接理解为“一个空格”。

WH.shared.addScrollLoadItem(‘a387dcdfa92e0b5291a65f5308fb81a2’)

{“smallUrl”:”https://www.wikihow.com/images_en/thumb/c/ce/593311-3.jpg/v4-460px-593311-3.jpg”,”bigUrl”:”https://www.wikihow.com/images/thumb/c/ce/593311-3.jpg/v4-728px-593311-3.jpg”,”smallWidth”:460,”smallHeight”:345,”bigWidth”:728,”bigHeight”:546,”licensing”:”

“}
3
更便捷的方式是使用其他空格符。比如说,你想插入两个空格、四个空格或者缩进一行的开头,那也不一定非得反复输入 :

两个空格:输入 

四个空格:输入 

WH.ads.addBodyAd(‘method_ad_1’)

广告

WH.ads.addBodyAd(‘mobilemethod_ad_1’)

方法 2

方法 2 的 4:保留粘贴文本中的空格

WH.shared.addScrollLoadItem(‘ad0bc63b7b169fdcf791bec757cfdeec’)

{“smallUrl”:”https://www.wikihow.com/images_en/thumb/5/5f/593311-4.jpg/v4-460px-593311-4.jpg”,”bigUrl”:”https://www.wikihow.com/images/thumb/5/5f/593311-4.jpg/v4-728px-593311-4.jpg”,”smallWidth”:460,”smallHeight”:345,”bigWidth”:728,”bigHeight”:546,”licensing”:”

“}
1
打开HTML代码。另一种在代码中添加更多空格的方法是使用HTML

标记。这个标记基本上会按照你输入或粘贴的文本来显示,包括空格和所有的内容。首先在文本编辑器中打开代码文件,比如Windows的记事本或MacOS的TextEdit。






WH.shared.addScrollLoadItem('0a66c39f5947f1ea52b284c9102be438')

{"smallUrl":"https://www.wikihow.com/images_en/thumb/2/2d/593311-5.jpg/v4-460px-593311-5.jpg","bigUrl":"https://www.wikihow.com/images/thumb/2/2d/593311-5.jpg/v4-728px-593311-5.jpg","smallWidth":460,"smallHeight":345,"bigWidth":728,"bigHeight":546,"licensing":"
"} 2 在文档正文中输入
 

标记。你想用特定数量的空格和/或换行符来保持预先格式化的任何文本都将放在这些标记之间:

wikiHow: How-to instructions you can trust.

  

WH.shared.addScrollLoadItem('7f583c168db74c13ae003babbedea43b')

{"smallUrl":"https://www.wikihow.com/images_en/thumb/2/22/593311-6.jpg/v4-460px-593311-6.jpg","bigUrl":"https://www.wikihow.com/images/thumb/2/22/593311-6.jpg/v4-728px-593311-6.jpg","smallWidth":460,"smallHeight":345,"bigWidth":728,"bigHeight":546,"licensing":"

"}
3
在"

"和''
''标记之间输入或粘贴文本。在本例中,我们要在单词之间保留三个空格以及一个换行符。在预设文本格式时,单词之间的任何空格,以及通过按“Enter”或“Return”键输入的换行都会显示在网页上。[2]
	X
		研究来源
		
				






wikiHow: How-to instructions you can trust.
What   will   you   
learn   today?

广告

WH.ads.addBodyAd('mobilemethod_ad_2')

方法 3

方法 3 的 4:插入空行(换行符)

WH.shared.addScrollLoadItem('1f0a4b26c27e46185ce852edb0537d74')

{"smallUrl":"https://www.wikihow.com/images_en/thumb/0/0c/593311-7.jpg/v4-460px-593311-7.jpg","bigUrl":"https://www.wikihow.com/images/thumb/0/0c/593311-7.jpg/v4-728px-593311-7.jpg","smallWidth":460,"smallHeight":345,"bigWidth":728,"bigHeight":546,"licensing":"

"}
1
在文本编辑器中打开HTML代码。想在页面上的段落或其他元素之间添加额外的空格吗?在代码中反复按Enter或Return并不会起作用,但添加一个换行标记
就能达到你想要的效果。首先打开你要编辑的页面的HTML代码。

WH.shared.addScrollLoadItem('bde0d6b40f160fd6a43be12f9ae497be')

{"smallUrl":"https://www.wikihow.com/images_en/thumb/0/09/593311-8.jpg/v4-460px-593311-8.jpg","bigUrl":"https://www.wikihow.com/images/thumb/0/09/593311-8.jpg/v4-728px-593311-8.jpg","smallWidth":460,"smallHeight":345,"bigWidth":728,"bigHeight":546,"licensing":"

"}
2
在你想留空的每一行输入
。比如,你想在两个段落之间插入一个额外的空行,那就只用输入一次
。但要是想添加三个换行符,那就输入三次:

.
在本例中,我们要在句子之间添加两个额外的空行:

wikiHow: How-to instructions you can trust.

What   will   you  
learn   today?

You will learn a lot!

广告

WH.ads.addBodyAd('mobilemethod_ad_3')

方法 4

方法 4 的 4:段落缩进

WH.shared.addScrollLoadItem('79c51a472902c836a5af99bb902bc8b8')

{"smallUrl":"https://www.wikihow.com/images_en/thumb/a/ae/593311-9.jpg/v4-460px-593311-9.jpg","bigUrl":"https://www.wikihow.com/images/thumb/a/ae/593311-9.jpg/v4-728px-593311-9.jpg","smallWidth":460,"smallHeight":345,"bigWidth":728,"bigHeight":546,"licensing":"

"}
1
打开一个HTML文件。假设你想让段落开头缩进一些位置,比方说10个像素,那么一种最好的方法是使用CSS(层叠样式表)。我们会介绍两种方法,一种是手动缩进每个段落,而另一种是一次性缩进所有段落。首先,在文本编辑器中打开HTML文件。

WH.shared.addScrollLoadItem('b5d51ef0d3c12058917949a41452458f')

{"smallUrl":"https://www.wikihow.com/images_en/thumb/c/cb/593311-10.jpg/v4-460px-593311-10.jpg","bigUrl":"https://www.wikihow.com/images/thumb/c/cb/593311-10.jpg/v4-728px-593311-10.jpg","smallWidth":460,"smallHeight":345,"bigWidth":728,"bigHeight":546,"licensing":"

"}
2
缩进一个段落。如果要让我们示例中的段落缩进,可以通过在它的

标记中添加text-indent属性来实现。在本例中,我们要把段落缩进10个像素:

wikiHow: How-to instructions you can trust.

Welcome to wikiHow, the most trusted how-to site on the internet. wikiHow is where trusted research and expert knowledge come together.

Since 2005, wikiHow has helped billions of people learn how to solve problems large and small. We work with credentialed experts, a team of trained researchers, and a devoted community to create the most reliable, comprehensive and delightful how-to content on the Internet.

由于只为第一段添加了text-indent属性,所以只有这一段会被缩进。继续阅读本文,了解如何以同样的方式缩进页面上的所有段落,而不只是一个段落。

WH.shared.addScrollLoadItem('19184cd809259fc3bb1f551007667034')

{"smallUrl":"https://www.wikihow.com/images_en/thumb/e/e2/593311-11.jpg/v4-460px-593311-11.jpg","bigUrl":"https://www.wikihow.com/images/thumb/e/e2/593311-11.jpg/v4-728px-593311-11.jpg","smallWidth":460,"smallHeight":345,"bigWidth":728,"bigHeight":546,"licensing":"

"}
3
为CSS创建一个样式部分。如果要缩进页面上的所有段落,可以通过在CSS中定义段落样式来实现。样式部分要放在HTML代码的标头中,或者放在单独的样式表中。我们要把样式部分添加到标头中,也就是和标记之间:

wikiHow: How-to instructions you can trust.

Welcome to wikiHow, the most trusted how-to site on the internet. wikiHow is where trusted research and expert knowledge come together.

Since 2005, wikiHow has helped billions of people learn how to solve problems large and small. We work with credentialed experts, a team of trained researchers, and a devoted community to create the most reliable, comprehensive and delightful how-to content on the Internet.

WH.shared.addScrollLoadItem('c18f86218f3450f7f0423d8328d4c2e9')

{"smallUrl":"https://www.wikihow.com/images_en/thumb/f/fb/593311-12.jpg/v4-460px-593311-12.jpg","bigUrl":"https://www.wikihow.com/images/thumb/f/fb/593311-12.jpg/v4-728px-593311-12.jpg","smallWidth":460,"smallHeight":345,"bigWidth":728,"bigHeight":546,"licensing":"

"}
4
在样式区域中输入缩进代码。我们要在每个段落的开头都缩进10个像素,而不是只在一个段落缩进。这意味着我们要为段落标记(

)创建一个样式,从而在每个段落的第一个单词的开头自动添加10个像素的空位。我们得从原先的示例中删掉text-indent属性,因为现在用不着它了。属性看起来是这样的:

wikiHow: How-to instructions you can trust.
p {
text:indent: 10px;

Welcome to wikiHow, the most trusted how-to site on the internet. wikiHow is where trusted research and expert knowledge come together.

Since 2005, wikiHow has helped billions of people learn how to solve problems large and small. We work with credentialed experts, a team of trained researchers, and a devoted community to create the most reliable, comprehensive and delightful how-to content on the Internet.

你可以在"text-indent: "后面输入一个不同的数字来调整空格数量。
你也可以用像素之外的其他单位来定义缩进的大小,比如百分比(例如"text-indent: 15%;")或尺寸单位(例如"text-indent: 3mm;")。

WH.shared.addScrollLoadItem('5b67d65bfe9094950461a02691cfd368')

{"smallUrl":"https://www.wikihow.com/images_en/thumb/b/b2/593311-13.jpg/v4-460px-593311-13.jpg","bigUrl":"https://www.wikihow.com/images/thumb/b/b2/593311-13.jpg/v4-728px-593311-13.jpg","smallWidth":460,"smallHeight":345,"bigWidth":728,"bigHeight":546,"licensing":"

"}
5
在每个段落的开头输入

。由于我们已经添加了具体的指令来缩进

标记,所以页面上的每个段落都会缩进2.5em。这不仅会应用到现有的段落,还会应用到在页面上后续添加的任何新段落。

广告

WH.ads.addBodyAd('mobilemethod_ad_4')

发表评论

您的电子邮箱地址不会被公开。 必填项已用*标注