Table of Contents
 
Home Web Front-end CSS Tutorial Share a detailed explanation of how to write spaces in CSS

Share a detailed explanation of how to write spaces in CSS

Jul 22, 2017 am 09:26 AM
css Detailed explanation

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的关系,于是,一些中文排版对齐什么的,直接就可以使用这两个空格调节,如:


1

2

3

4

5

<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>

Copy after login

Share a detailed explanation of how to write spaces in CSS

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

&#x3000;

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

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

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

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

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

  2. web字符,&copy;

  3. charCode表示:&#xa9;

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

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

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

Share a detailed explanation of how to write spaces in CSS

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

  • &ensp;&#x2002;

  • &emsp;&#x2003;

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

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

  1. &#x6211;

  2. \u6211, 如console.log(&#39;\u6211&#39;);

  3. \6211, 如.xxx:before { content: &#39;\6211&#39;; }

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


1

2

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

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

Copy after login

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

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 of this Website
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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

How to use bootstrap in vue How to use bootstrap in vue Apr 07, 2025 pm 11:33 PM

Using Bootstrap in Vue.js is divided into five steps: Install Bootstrap. Import Bootstrap in main.js. Use the Bootstrap component directly in the template. Optional: Custom style. Optional: Use plug-ins.

The Roles of HTML, CSS, and JavaScript: Core Responsibilities The Roles of HTML, CSS, and JavaScript: Core Responsibilities Apr 08, 2025 pm 07:05 PM

HTML defines the web structure, CSS is responsible for style and layout, and JavaScript gives dynamic interaction. The three perform their duties in web development and jointly build a colorful website.

How to write split lines on bootstrap How to write split lines on bootstrap Apr 07, 2025 pm 03:12 PM

There are two ways to create a Bootstrap split line: using the tag, which creates a horizontal split line. Use the CSS border property to create custom style split lines.

Understanding HTML, CSS, and JavaScript: A Beginner's Guide Understanding HTML, CSS, and JavaScript: A Beginner's Guide Apr 12, 2025 am 12:02 AM

WebdevelopmentreliesonHTML,CSS,andJavaScript:1)HTMLstructurescontent,2)CSSstylesit,and3)JavaScriptaddsinteractivity,formingthebasisofmodernwebexperiences.

How to use bootstrap button How to use bootstrap button Apr 07, 2025 pm 03:09 PM

How to use the Bootstrap button? Introduce Bootstrap CSS to create button elements and add Bootstrap button class to add button text

How to resize bootstrap How to resize bootstrap Apr 07, 2025 pm 03:18 PM

To adjust the size of elements in Bootstrap, you can use the dimension class, which includes: adjusting width: .col-, .w-, .mw-adjust height: .h-, .min-h-, .max-h-

How to set up the framework for bootstrap How to set up the framework for bootstrap Apr 07, 2025 pm 03:27 PM

To set up the Bootstrap framework, you need to follow these steps: 1. Reference the Bootstrap file via CDN; 2. Download and host the file on your own server; 3. Include the Bootstrap file in HTML; 4. Compile Sass/Less as needed; 5. Import a custom file (optional). Once setup is complete, you can use Bootstrap's grid systems, components, and styles to create responsive websites and applications.

How to insert pictures on bootstrap How to insert pictures on bootstrap Apr 07, 2025 pm 03:30 PM

There are several ways to insert images in Bootstrap: insert images directly, using the HTML img tag. With the Bootstrap image component, you can provide responsive images and more styles. Set the image size, use the img-fluid class to make the image adaptable. Set the border, using the img-bordered class. Set the rounded corners and use the img-rounded class. Set the shadow, use the shadow class. Resize and position the image, using CSS style. Using the background image, use the background-image CSS property.

See all articles