学习导航
1、css中的长度与颜色
2、css中的文字属性
3、css中的文本属性
1、文字样式属性
| font-family |
文字字体 |
| font-size |
文字大小 |
| font-color |
文字颜色 |
| font-weight |
文字粗细 |
| font-style |
文字样式 |
font-family 字体属性
作用:元素内文字以什么字体来显示
语法:font-family:[字体1],[字体2],[......];
说明:含空格字体名和中文,用英文引号(")括起;多个字体用英文逗号隔开;引号嵌套,外使用双引号,内使用单引号。
font-size 文字大小
作用:元素内文字大小
语法:font-size:绝对单单位,相相对单位
|
单位 |
说明 |
| in |
英寸 |
| cm |
公分 |
| mm |
公里 |
| ex | 小写字母为单位 |
| pt |
1pt/72英寸 |
| pc |
1pc/12pt |
| px |
像素(推荐使用) |
color 文字颜色
语法:颜色名|十六进制|RGB
font-weight 文字粗细
语法:font-weight:normal 正常 | bold 加粗 | bolder 加粗 | lighter 细体 | 100-900
说明:默认值:normal 400等同于normal,而700等同于bold
font-style 文字样式
作用:为元素内文字设置样式
语法:font-style:normal 正常显示 | italic 文字倾斜 | oblique 文字倾斜(基本不用)
font-variant 字体变形
作用:设置元素中文本为小型大写字母
语法:font-variant:normal 正常显示| small-caps 将英文大小写字母调成为同宽
font 属性简写
语法:font:font-style font-variant font-weight font-size/line-height font-family;
说明:值之间空格隔开,注意书写顺序。
2、CSS文本样式
text-align
作用:设置元素内文本的水平对齐方式
语法:tex-align:left 左对齐 | right 右对齐 | center 居中对齐 | justify 两端对齐
注意:该属性对块级元素设置有效
line-height
作用:设置元素中文本行高
语法:line-height:长度值 | 百分比
说明:一行文字的高度,行高指文本行的基线间的距离
文字基线
注意:基线并不是汉字文字的下沿,看图理解自行理解
行高和行距
行高:基线到基线的距离
行距:底线到顶线的距离
注意:看图自行理解
行框和行内框
注意:看图自行理解
vertical-align
作用:设置元素内容的垂直方式
语法:vertical-align:baseline | sub | super | top | text-top | middle | bottom | text-bottom | 长度 | 百分比
注意:看图自行理解
text-indent 首行缩进
3、文本样式属性
| 字体属性 |
说明 |
| word-spaceing |
设置元素内单词之间的距离 |
| letter-spaceing |
设置元素内字母之间的距离 |
| text-transform |
设置元素内字母的大小写 capitzlize | uppercase | lowercase | none |
| text-decoration |
设置元素内文本的装饰 underline | overline | line-through | blink | none |
text-transform: capitzlize 首字母大写 | uppercase 字母大写 | lowercase 字母小写 | none 正常
text-decoration: underline 下划线 | overline 上划线 | line-through 删除线 | none 正常
综合实操案例
<html><head><title>CSS文本与样式</title><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><style type="text/css">/*为了教学选择内部样式 建议大家使用外部引入方式*/*{padding:0; margin: 0;}hr{ margin: 10px 0;}/*文字字体 文字大小 文字颜色 文字粗细 文字风格*/dl dt{ font-family: '微软雅黑'; font-size:30px; color:red; font-weight: bolder; font-style: italic;}/*text-align*/dl dd.dd_01 .a1{ text-align: left; }dl dd.dd_01 .a2{ text-align: center; }dl dd.dd_01 .a3{ text-align: right }/*text-decoration*/dl dd.dd_02 .a1{ text-decoration: overline; /*上划线*/}dl dd.dd_02 .a2{ text-decoration: line-through; /*穿梭线*/}dl dd.dd_02 .a3{ text-decoration: underline; /*下划线*/}/*text-transform*/dl dd.dd_03 .a1{ text-transform: uppercase; /*小写转大写*/}dl dd.dd_03 .a2{ text-transform: capitalize; /*首字符大写*/}dl dd.dd_03 .a3{ text-transform: lowercase; /*大写转小写*/ }/*letter-spacing word-spacing*/dl dd.dd_04 .a1{ letter-spacing: 6px; /*字母间距*/ }dl dd.dd_04 .a2{ word-spacing: 6px; /*单词间距*/}/*line-height text-indent text-align: justify*/dl dd.dd_05{ width:500px; height: auto; text-indent: 2em;/*首行缩进*/ line-height: 180%;/*行高单位px 或 %*/ text-align: justify; /*文本对接方式*/}</style></head><body><dl><dt>text-align</dt><dd class="dd_01"><ul><li class="a1">左对齐</li><li class="a2">居中对齐</li><li class="a3">右对齐</li></ul></dd><hr/><dt>text-decoration</dt><dd class="dd_02"><ul><li class="a1">上划线</li><li class="a2">删除线</li><li class="a3">下划线</li></ul></dd><hr/><dt>text-transform</dt><dd class="dd_03"><ul><li class="a1">renhaibo</li><li class="a2">renhaibo</li><li class="a3">RENHAIBO</li></ul></dd><hr/><dt>letter-spacing word-spacing</dt><dd class="dd_04"><ul><li class="a1">abcdefg</li><li class="a2">my name is renhaibo</li></ul></dd><hr/><dt>line-height text-indent</dt><dd class="dd_05">每日分享在学习过程中总结的学习经验,学习笔记,笔试题,HTML,CSS,JavaScript,jQuery教程,Vue教程,PHP教程,TinkPHP教程等,望大家能以学习为目的,每天阅读一篇文章,了解身边的技术。陪有梦想的人一起成长!</dd></dl></body></html>
如果您觉得有用,记得在下方点赞、关注、留言,小编会定期奉 上更多的惊喜哦,您的打赏支持才是小编继续努力的动力,么么哒。
每日分享在学习过程中总结的学习经验,学习笔记,笔试题,HTML,CSS,JavaScript,jQuery教程,Vue教程,PHP教程,TinkPHP教程等,望大家能以学习为目的,每天阅读一篇文章,了解身边的技术。陪有梦想的人一起成长!