Home  >  Article  >  Web Front-end  >  Share a detailed explanation of how to write spaces in CSS

Share a detailed explanation of how to write spaces in CSS

黄舟
黄舟Original
2017-07-22 09:26:482788browse
This is the space we use most, which is the 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). To be accumulated, you need to use html entity representation. In order to make it easier to remember, I always call this space "nb space (sp - space)", although it is not actually awesome. The width occupied by this space is significantly and strongly affected by the font. It will cause some minor damage in the inline-block layout, but it is an indispensable element in the aligned layout. He is a little thing that people love and hate. transparencydrops! This space also has a very robust feature, that is, the width occupied by
Characters and HTML entities Description and instructions


## 


## 

The scientific name of this space is unknown. To make it easier to remember, we might as well call it "e n-ian space". This space inherits the consistent characteristics of the space family:
drops! This space has a very robust feature, that is, the width occupied by its is exactly 1/2 the Chinese width , and it is basically not affected by the font.

##  

The scientific name of this space is unknown. To make it easier to remember, we might as well call it "Devil (em-o) Space". This space also inherits the consistent characteristics of the space family:

transparency
is exactly 1 Chinese width , and it is basically not affected by the font.


## 

The scientific name of this space is unknown. We might as well call it a "skinny space", which means that the space is relatively thin, has a thin body, and occupies a relatively small width. I haven't used this thing yet, so I showed it here to let it go through the addiction of an extra.

其中的,由于具有某一超赞的特性,使其可以登上web届的舞台!什么特性呢?如上表加粗展示,1. 透明; 2. 宽度正好跟中文正好是1:21:1的关系,于是,一些中文排版对齐什么的,直接就可以使用这两个空格调节,如:


<ul>
    <li class="li">姓&emsp;&emsp;名:<input type="text" /></li>
    <li class="li">手&ensp;机&ensp;号:<input type="text" /></li>
    <li class="li">电子邮箱:<input type="text" /></li>
</ul>

Share a detailed explanation of how to write spaces in CSS

当中文和英文混杂的时候,使用, 等空格实现冒号的完美对齐还是有些困难的,除非英文使用的是等宽字体,于是乎,我们就可以使用普通的 空格做英文字符的宽度调节。

 

 

「叉三千」指什么呢?哈哈,其实是全角空格。

中文字体都是等宽的,一个全角空格的宽度就是一个普通中文的宽度。所以,上面的demo中空格换成全角空格也是可以滴!

但是,我们不能直接在页面中打全角空格,因为在大多数编辑器中空格是透明滴,很容易就被删掉;另外,HTML压缩时候,空格很可能被干掉!咋办?需要转换书写形式。

在web页面上,一般有3种书写:

  1. 直接,例如搜狗输入法输入“版权” – ©.

  2. web字符,©

  3. charCode表示:©

而上面的, 就是具有特定名称的web字符。但是,恕我寡闻,我并不清楚全角空格是否有对应& + 关键字示意,所以,就使用工具转成了charCode字符表示,也就是这里的 ,又称「叉三千」!

稍等,你刚说了工具,什么工具!?

哈,这位同学好敏锐,我是有一个私藏的小工具,可以把任意字符转换成HTML识别格式,若有兴趣,您可以狠狠地点击这里:任意字符转换成HTML识别格式工具页面

Share a detailed explanation of how to write spaces in CSS

使用了这个工具,你会发现, 原来是相邻兄弟关系:

 

再科普点关于字符的实用知识吧:
1. HTML中字符输出使用配上charCode值;
2. 在JavaScript文件中为防止乱码转义,则是\u配上charCode值;
3. 而在CSS文件中,如CSS伪元素的content属性,直接使用\配上charCode值。

因此,想在HTML/JS/CSS中转义“我”这个汉字,分别是:

  1. \u6211, 如console.log('\u6211');

  2. \6211, 如.xxx:before { content: '\6211'; }

考虑到直接 这种形式暴露在HTML中,可能会让屏幕阅读器等辅助设备读取,从而影响正常阅读流,因此,我们可以进一步优化下,使用标签,利用伪元素,例如:


.half:before { content: &#39;\2002&#39;; speak: none; }
.full:before { content: &#39;\2003&#39;; speak: none; }

这样,占位的空格字符即不能读,也不能选了。

The above is the detailed content of Share a detailed explanation of how to write spaces in CSS. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn