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


<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
Orbital Mechanics (or How I Optimized a CSS Keyframes Animation)Orbital Mechanics (or How I Optimized a CSS Keyframes Animation)May 09, 2025 am 09:57 AM

What does it look like to refactor your own code? John Rhea picks apart an old CSS animation he wrote and walks through the thought process of optimizing it.

CSS Animations: Is it hard to create them?CSS Animations: Is it hard to create them?May 09, 2025 am 12:03 AM

CSSanimationsarenotinherentlyhardbutrequirepracticeandunderstandingofCSSpropertiesandtimingfunctions.1)Startwithsimpleanimationslikescalingabuttononhoverusingkeyframes.2)Useeasingfunctionslikecubic-bezierfornaturaleffects,suchasabounceanimation.3)For

@keyframes CSS: The most used tricks@keyframes CSS: The most used tricksMay 08, 2025 am 12:13 AM

@keyframesispopularduetoitsversatilityandpowerincreatingsmoothCSSanimations.Keytricksinclude:1)Definingsmoothtransitionsbetweenstates,2)Animatingmultiplepropertiessimultaneously,3)Usingvendorprefixesforbrowsercompatibility,4)CombiningwithJavaScriptfo

CSS Counters: A Comprehensive Guide to Automatic NumberingCSS Counters: A Comprehensive Guide to Automatic NumberingMay 07, 2025 pm 03:45 PM

CSSCountersareusedtomanageautomaticnumberinginwebdesigns.1)Theycanbeusedfortablesofcontents,listitems,andcustomnumbering.2)Advancedusesincludenestednumberingsystems.3)Challengesincludebrowsercompatibilityandperformanceissues.4)Creativeusesinvolvecust

Modern Scroll Shadows Using Scroll-Driven AnimationsModern Scroll Shadows Using Scroll-Driven AnimationsMay 07, 2025 am 10:34 AM

Using scroll shadows, especially for mobile devices, is a subtle bit of UX that Chris has covered before. Geoff covered a newer approach that uses the animation-timeline property. Here’s yet another way.

Revisiting Image MapsRevisiting Image MapsMay 07, 2025 am 09:40 AM

Let’s run through a quick refresher. Image maps date all the way back to HTML 3.2, where, first, server-side maps and then client-side maps defined clickable regions over an image using map and area elements.

State of Devs: A Survey for Every DeveloperState of Devs: A Survey for Every DeveloperMay 07, 2025 am 09:30 AM

The State of Devs survey is now open to participation, and unlike previous surveys it covers everything except code: career, workplace, but also health, hobbies, and more. 

What is CSS Grid?What is CSS Grid?Apr 30, 2025 pm 03:21 PM

CSS Grid is a powerful tool for creating complex, responsive web layouts. It simplifies design, improves accessibility, and offers more control than older methods.

See all articles

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

Atom editor mac version download

Atom editor mac version download

The most popular open source editor

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Integrate Eclipse with SAP NetWeaver application server.

PhpStorm Mac version

PhpStorm Mac version

The latest (2018.2.1) professional PHP integrated development tool

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

SublimeText3 Linux new version

SublimeText3 Linux new version

SublimeText3 Linux latest version