文章目录
-
- CSS使用方式
- CSS字体样式属性
- CSS外观属性
一、CSS使用方式
1. 行内样式
<!DOCTYPE html>
<html lang="en">
<head>
<title>This is title</title>
</head>
<body>
<p style="font-size: 16px; color: red;">大家好</p> </body>
</html>
2 .内部样式表
<!DOCTYPE html>
<html lang="en">
<head>
<title>This is title</title>
<style>
p {
font-size: 16px;
color: red;
}
</style>
</head>
<body>
<p>Hello everyone</p> </body>
</html>
3 .外部样式表
链接式
将样式写到单独的文件中,文件的扩展名为 .css 。例如, index.css 文件中有如下样式:
p{
font-size: 16px; color: red;
}
然后通过 <link> 元素将 index.css 文件引入到页面中:
<!DOCTYPE html>
<html lang="en">
<head>
<title>This is title</title>
<link rel="stylesheet" type="text/css" href="./css/index.css"> </head>
<body>
<p>我是优秀的开发工程师</p> </body>
</html>
4.css使用方式总结
(1)定义在外部文件(外链样式):开发中主要是通过这种形式定义样式。
(2)在页面的头部定义(内联样式):通过这种形式定义的样式只在本页面内生效。
(3)定义在特定的元素身上(行内样式):这种形式多用于测试,可维护性较差。
二、CSS字体样式属性
font-size:字号大小
font-family:字体
font-weight:字体粗细
font-style:字体风格
三、CSS外观属性
1. color:文本颜色
属性值:预定义的颜色名 | 十六进制值的颜色值 | RGB颜色值
2 .颜色半透明(css3)
color: rgba(r,g,b,a) a 是alpha , 透明的意思
取值范围 : 0~1之间
color: rgba(0,0,0,0.3)
3 .line-height:行间距
- normal:默认值,行高由浏览器自动处理。
- 数字:行高 = 数字 * 字体大小,例如, line-height: 2;font-size: 16px; ,则行高等于:2 * 16px = 32px
- 长度值:使用长度值设置行高,例如, line-height: 32px 。
- 百分比:基于当前字体大小的百分比。
4. text-align:水平对齐方式
属性值:left | right | center | justify
5. text-indent:首行缩进
6. text-decoration:文本修饰
7. text-transform:大小写转换
8 .letter-spacing:字符间距
9 .word-spacing(单词)
10. 文字阴影
text-shadow:水平位置 垂直位置 模糊距离 阴影颜色;