p{text-indent:2em;} 开头空两格
p{line-height:1.5em;} 行距1.5em
h1{ letter-spacing:50px; } ... <h1>了不起的盖茨比</h1> 字母与字母之间的距离
h1{ word-spacing:50px; } ... <h1>welcome to imooc!</h1> 单词与单词之前的距离
h1{ text-align:center/left/right; } <h1>了不起的盖茨比</h1> 居中/左/右对齐
长度值
1、em
就是本元素给定字体的 font-size 值,如果元素的 font-size 为 14px ,那么 1em = 14px;如果 font-size 为 18px,那么 1em = 18px。如下代码:
p{font-size:12px;text-indent:2em;}
上面代码就是可以实现段落首行缩进 24px(也就是两个字体大小的距离)。
html:
<p>以这个<span>例子</span>为例。</p>
css:
p{font-size:14px} span{font-size:0.8em;}
结果 span 中的字体“例子”字体大小就为 11.2px(14 * 0.8 = 11.2px)。
2、百分比
p{font-size:12px;line-height:130%}
设置行高(行间距)为字体的130%(12 * 1.3 = 15.6px)。