您的位置:

letter-spacing详解

letter-spacing,字母间距,是CSS中一个常用的属性,用于控制字符之间的距离。在排版时,如果希望字符之间有更大的间距,可以使用letter-spacing属性进行调整。

一、letter-spacing的基本用法

   /*将字母间距设为0.1em*/
   letter-spacing: 0.1em;

上述代码将字符之间的间距设为0.1em,em是相对于字体大小而言的单位,相当于字符宽度的倍数。因此,这个属性可以传入正负值,负值则表示字符之间紧凑一些。

二、letter-spacing的常见应用场景

1、太空字母风格

太空风格是指在设计中,以星际、外星等为背景,太空中各种无重量影响的科技、生命形态和艺术元素等作素材的设计风格,其中,字母风格是不可或缺的一部分。这种风格的字母通常具有较大的字母间距和流线型的外观,可以使用letter-spacing属性来控制字符之间的间距。

   /*太空字母风格*/
   letter-spacing: 0.3em;
   text-transform: uppercase; /*字母大写*/

2、艺术字体的排版

艺术字体是设计中用于表达情感、主题和风格等多种表现形式的字体,字母之间的距离可以影响到艺术字体的表现效果,可以使用letter-spacing进行微调。

   /*压缩间距,创造压迫感*/
   letter-spacing: -0.1em;

3、排版美文时字母的左右间距控制

在排版美文时,为了让排版更加美观,字母之间适当的间距是很重要的。letter-spacing属性可以达到这个目的。

   /*排版美文时,字母的左右间距控制*/
   letter-spacing: 0.05em;

三、注意事项

1、如何统计字符间距?

字符间距指的是字符之间的空白距离,包含字符本身的宽度和字符之间的间隙。如何统计字符间距?可以把字母放在一个盒子里,在盒子里面量出字符本身的宽度,再用线尺量出盒子中字符间的空白,就可以得到字符间的距离。

2、字母间距与中英文混排的问题

中英文混排的时候,中英文单词之间可能会出现过多的空格,这时候可以用letter-spacing来控制中英文之间的间距。

   /*设置中英文单词之间的间距*/
   letter-spacing: 0.1em;
   
   /*HTML实体化*/
   <p>这是一段中英文混排的文字测试:hello 你好 world!</p>

3、letter-spacing和word-spacing的区别

letter-spacing表示字符之间的距离,而word-spacing表示单词之间的距离。

   /*设置单词之间的距离*/
   word-spacing: 0.2em;

以上就是letter-spacing的详细说明。在使用时,需要根据具体排版需求进行调整,以达到最佳视觉效果。

CSS letter-spacing详解

2023-05-21
letter-spacing详解

2023-05-19
CSS Letter Spacing

2023-05-12
CSS Letter Spacing

2023-05-12
CSS Letter Spacing vs Microsof

2023-05-12
CSS Letter Spacing

2023-05-12
letter-spacing的妙用

2023-05-12
CSS LETTER SPACING WORD

2023-05-12
CSS Letter Spacing: 控制字间距,让文字更

2023-05-12
CSS Elements With Letter Words

2023-05-12
word-spacing的多面探究

2023-05-19
CSS word spacing用法

2023-05-12
CSS中字母间的间距调整

2023-05-12
CSS实现单词间距调整

2023-05-12
when-present<#else>when-missing. (These only cover the last step of the expression; to cover the whole expression, use parenthesis: (myOptionalVar.foo)!myDefault, (myOptionalVar.foo)?? ---- ---- FTL stack trace ("~" means nesting-related): - Failed at: ${item.id} [in template "article/detail/index.ftl" at line 48, column 106] ---- Java stack trace (for programmers): ---- freemarker.core.InvalidReferenceException: [... Exception message was already printed; see it above ...] at freemarker.core.InvalidReferenceException.getInstance(InvalidReferenceException.java:134) at freemarker.core.EvalUtil.coerceModelToTextualCommon(EvalUtil.java:481) at freemarker.core.EvalUtil.coerceModelToStringOrMarkup(EvalUtil.java:401) at freemarker.core.EvalUtil.coerceModelToStringOrMarkup(EvalUtil.java:370) at freemarker.core.DollarVariable.calculateInterpolatedStringOrMarkup(DollarVariable.java:104) at freemarker.core.DollarVariable.accept(DollarVariable.java:63) at freemarker.core.Environment.visit(Environment.java:371) at freemarker.core.IteratorBlock$IterationContext.executedNestedContentForCollOrSeqListing(IteratorBlock.java:321) at freemarker.core.IteratorBlock$IterationContext.executeNestedContent(IteratorBlock.java:271) at freemarker.core.IteratorBlock$IterationContext.accept(IteratorBlock.java:244) at freemarker.core.Environment.visitIteratorBlock(Environment.java:645) at freemarker.core.IteratorBlock.acceptWithResult(IteratorBlock.java:108) at freemarker.core.IteratorBlock.accept(IteratorBlock.java:94) at freemarker.core.Environment.visit(Environment.java:335) at freemarker.core.Environment.visit(Environment.java:341) at freemarker.core.Environment.visit(Environment.java:341) at freemarker.core.Environment.process(Environment.java:314) at freemarker.template.Template.process(Template.java:383) at org.springframework.web.servlet.view.freemarker.FreeMarkerView.processTemplate(FreeMarkerView.java:332) at org.springframework.web.servlet.view.freemarker.FreeMarkerView.doRender(FreeMarkerView.java:266) at org.springframework.web.servlet.view.freemarker.FreeMarkerView.renderMergedTemplateModel(FreeMarkerView.java:220) at org.springframework.web.servlet.view.AbstractTemplateView.renderMergedOutputModel(AbstractTemplateView.java:181) at org.springframework.web.servlet.view.AbstractView.render(AbstractView.java:314) at org.springframework.web.servlet.DispatcherServlet.render(DispatcherServlet.java:1431) at org.springframework.web.servlet.DispatcherServlet.processDispatchResult(DispatcherServlet.java:1167) at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:1106) at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:979) at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:1014) at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:903) at jakarta.servlet.http.HttpServlet.service(HttpServlet.java:564) at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:885) at jakarta.servlet.http.HttpServlet.service(HttpServlet.java:658) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:205) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:149) at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:51) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:174) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:149) at com.software.filter.HttpSpiderIdentifyFilter.doFilter(HttpSpiderIdentifyFilter.java:51) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:174) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:149) at org.springframework.web.filter.RequestContextFilter.doFilterInternal(RequestContextFilter.java:100) at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:116) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:174) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:149) at org.springframework.web.filter.FormContentFilter.doFilterInternal(FormContentFilter.java:93) at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:116) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:174) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:149) at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:201) at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:116) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:174) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:149) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:167) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:90) at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:482) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:115) at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:93) at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:74) at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:340) at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:391) at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:63) at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:896) at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1744) at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:52) at java.base/java.lang.VirtualThread.run(VirtualThread.java:309)