字体属性
CSS字体属性定义字体,颜色、大小,加粗,文字样式
color
规定文本的颜色
div{ color:red;}
div{ color:#ff0000;}
div{ color:rgb(255,0,0);}
div{ color:rgba(255,0,0,.5);}
font-size
设置文本的大小
能否管理文字的大小,在网页设计中是非常重要的。但是,你不能通过调整字体大小使段落看上去像标题,或者使标题看上去像段落。
h1 {font-size:40px;}
h2 {font-size:30px;}
p {font-size:14px;}
chrome浏览器接受最小字体是12px
font-weight
设置文本的粗细
值 | 描述 |
---|---|
bold | 定义粗体字符 |
bolder | 定义更粗的字符 |
lighter | 定义更细的字符 |
100~900 | 定义由细到粗 400等同默认,而700等同于bold |
H1 {font-weight:normal;}
div{font-weight:bold;}
p{font-weight:900;}
font-style
指定文本的字体样式
值 | 描述 |
---|---|
normal | 默认值 |
italic | 定义斜体字 |
font-family
font-family属性指定一个元素的字体
温馨提示
每个值用逗号分开
如果字体名称包含空格,它必须加上引号
font-family:"Microsoft YaHei","Simsun","SimHei";
文本属性
text-align
指定元素文本的水平对齐方式
值 | 描述 |
---|---|
left | 文本居左排列,默认值 |
right | 把文本排列到右边 |
center | 把文本排列到中间 |
h1 {text-align:center}
h2 {text-align:left}
h3 {text-align:right}
text-decoration
text-decoration 属性规定添加到文本的修饰,下划线、上划线、删除线等
值 | 描述 |
---|---|
underline | 定义下划线 |
overline | 定义上划线 |
line-through | 定义删除线 |
h1 {text-decoration:overline}
h2 {text-decoration:line-through}
h3 {text-decoration:underline}
text-indent
text-indent 属性规定文本块中首行文本的缩进
p{
text-indent:50px;
}
温馨提示
负值是允许的。如果值是负数,将第一行左缩进
链式伪类选择器
###a:link
a:link用于未访问的链接
###a:visited
a:vivisted用于已访问的链接
###a:hover
a:hover用于鼠标移动到目标元素
###a:active
a:active用于选定的链接
文本字符间的间距
###litter-spacing
litter-spacing用于控制汉字的字符间距
###word-spacing
word-spacing用于控制英语单词