CSS基础选择器
1,字体
1.1 字体样式
font-family
<style>
h2 {
font-family: '微软雅黑';
}
</style>
1.2 字体大小
font-size
1)谷歌浏览器默认16px;
2)可以在body中指定整个页面的字体大小;
<style>
h2 {
font-size: 20px;
}
</style>
1.3 字体粗细
font-weight
1.4 文本样式
font-style
1.5 font
font 简写属性在一个声明中设置所有字体属性。
- font-style
- font-variantfont-weight
- font-size/line-height
- font-family
- 必须保留font-size和font-family属性,否则font属性不起效。
-
<style> .text { font-style: italic; font-weight: 700; font-size: 20px; font-family: '微软雅黑'; } .text1 { font: italic 700 20px "微软雅黑"; } </style> </head> <body> <p class="text">效果一样</p> <p class="text1">效果一样</p> </body>
2,文本属性
2.1 文本颜色
color
div {
color: red/#ff0000/rgb;
}
2.2 对齐方式
text-align属性设置文本的水平对齐方式;
属性值 | 作用 |
center | 居中 |
right | 右对齐 |
left | 左对齐 |
2.3 装饰文本
text-decoration 给文本修饰,添加如下划线,删除线,上划线等;
属性值 | 作用 |
none | 默认 |
underline | 下划线,链接自带 |
overline | 上划线 |
line-throngh | 删除线 |
2.4 文本缩进
text-indent
首行缩进2em
用法:text-indent: 20px;或者text-indent:2em;
2.5 行间距
line-height 设置行高