css中文本显示易混淆的属性

总结几个CSS文本显示易混淆的属性。

1、文字的空白:letter-spacing,word-spacing

  • letter-spacing: normal | length | inherit;

增加或减少字符间的空白(字符间距),对中文有效

<html>
<head>
<style>
.h1 {letter-spacing: 1em}
</style>
</head>

<body>
<h1>This is header 1  这是主标题</h1>
<h1 class="h1">This is header 1  这是主标题</h1>
</body>
</html>

效果: 

  • word-spacing: normal | length | inherit;

增加 / 减少单词间的固定空间,对中文无效。

...
<style>
p
{ 
	word-spacing:30px;
}
</style>
...
<p>
This is some text. 
这是一段文字
</p>
...

效果: 

2、换行:word-wrap,word-break,white-space

  • word-wrap: normal | break-word;

word-wrap: break-word;  //允许在长单词或 URL 地址内部进行换行。

 

  • word-break: normal | break-all | keep-all;

word-break: break-all;  //允许在单词内换行

word-break: keep-all;  //只能在半角空格或连字符处换行。

...
<style> 
p{
	width:11em; 
	border:1px solid #000000;
}
.word{
	word-wrap: break-word;
}
.all{
	word-break: break-all;
}
</style>
</head>

<body>
<p class="word"> word-wrap:<br/> This paragraph contains a very long word: thisisaveryveryveryveryveryverylongword. The long word will break and wrap to the next line.</p>
<p class="all"> word-break:<br/> This paragraph contains a very long word: thisisaveryveryveryveryveryverylongword. The long word will break and wrap to the next line.</p>
...

效果:

 

  • white-space: normal | pre | nowrap | pre-wrap | pre-line | inherit;

white-space: pre;    // 空白会被浏览器保留。其行为方式类似 HTML 中的 <pre> 标签。
white-space: nowrap;    // 文本不会换行,文本会在在同一行上继续,直到遇到 <br> 标签为止。
white-space: pre-wrap;   // 保留空白符序列,但是正常地进行换行。
white-space: pre-line;   // 合并空白符序列,即多个空格合并成一个,保留换行符。

...
<style>
.wrap{
	white-space:pre-wrap;
}
.line{
	white-space:pre-line;
}
</style>
...
<h3>wrap:</h3>
<p class="wrap">
This        is some text.<br/>
 This is some text. 
</p>
<h3>line:</h3>
<p class="line">
This        is some text.<br/>
 This is some text. 
</p>
...

效果: 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值