一.字体属性
css字体属性定义字体,颜色,大小,加粗,文字样式
1.color
规定文本的颜色
div{ color:red;}
div{ color:#ff0000;}
div{ color:rgb(255,0,0);}
div{ color:rgba(255,0,0,.5);}
2.font-size
设置文本的大小
能否管理文字的大小,在网页设计中非常重要的,但是,你不能通过调整字体大小段落看上去像标题,或者使标题看上去像段落。
h1{font-size:40px;}
h2{font-size:30px;}
p{font-size:14px;}
chrome浏览器接受最小字体是12px
3.font-weight
设置文本的粗细
值 | 描述 |
bold | 定义粗体字符 |
bolder | 定义更粗的字符 |
lighter | 定义更细的字符 |
100-900 | 400默认,700bold |
h1{font-size:normal;}
div{font-size:bold;}
p{font-size:900;}
4.font-family
设置一个元素的字体
Ps:每个值要用逗号隔开,如果字体名称包含空格,必须加上引号
font-size:"microsoft YaHei","Simsun","SimHei";
二.背景属性
css背景属性主要有以下几个
属性 | 描述 |
background-color | 设置背景颜色 |
background-image | 设置背景图片 |
background-position | 设置背景图片显示位置 |
background-repeat | 设置背景图片如何填充 |
background-size | 设置背景图片大小属性 |
1.background-color
设置背景的颜色,div设置区块,style设置大小(不设置长宽默认为0,无法看见)
<head>
<style>
div{
width:300px;
height:500px;
background-color: red;
}
</style>
</head>
<body>
<div></div>
</body>
2.background-image
设置背景图片
在style中添加设置属性background-image,并用url来标注路径,用(“”)包含
并且可以设置平铺方式,通过repeat
3.background-repeat
该属性设置如何平铺背景图像
值 | 说明 |
repeat | 默认值 |
repeat-x | 只向水平方向平铺 |
repeat-y | 只向垂直方向平铺 |
no-repeat | 不平铺 |
4.background-size属性
值 | 说明 |
length | 设置宽高,第一个宽第二个高,如果只设置一个,第二个值auto |
percentage | 计算相对位置区域百分比,第一个宽度第二个高,如果只设置一个第二个auto |
cover | 保持纵横比缩放完全覆盖背景区域大小 |
contain | 保持纵横比并将图像缩放成适合背景定位(自适应) |
5.background-position
值 | 说明 |
left top | 左上角 |
left center | 左中 |
left center | 左下 |
right top | 右上角 |
right bottom | 右中 |
right bottom | 右下 |
center center | 中中 |
center center | 中中 |
center bottom | 中下 |
三.文本属性
1.text-align
指定元素文本的水平对齐方式
值 | 描述 |
left | 文本居左排列,默认值 |
right | 右边 |
center | 中间 |
h1 {text-align:center}
h2 {text-align:left}
h3 {text-align:right}
2.text-decoration
文本的修饰,下划线上划线删除线等
值 | 描述 |
underline | 定义下划线 |
overline | 定义上划线 |
line-through | 定义删除线 |
h1 {text-decoration:overline}
h2 {text-decoration:line-througe}
h3 {text-decoration:underline}
3.text-transform
属性控制文本的大小写
值 | 描述 |
captialize | 定义每个单词开头大写 |
uppercase | 定义全部大写 |
lowercase | 定义全部小写字母 |
h1 {text-transform:uppercase}
h2 {text-transform:capitialize}
p {text-transform:lowercase}
4.text-indent
规定首行文本的缩进
p{text-indent:50px;}
提示:负值是允许的,将第一行向左缩进,30px为俩个字的大小
四.表格属性
1.表格边框
指定css表格边框,使用border属性
table, td {
border: 1px solid black;
}
如果要内部也有,那就加个td
2.折叠边框
border-collapse属性设置表格的边框是否被折叠成单一个边框或隔开
把外围的边框合成一个
table { border-collapse:collapse; }
table, td { border: 1px solid black}
solid实线
3.表格的宽度和高度
weight和height定义表格的宽度和高度
4.表格填充
表的内容中控制空格之间的边框,使用td和th填充属性(在文本的周围加入一些空白)
td { padding:15px;}
5.表格颜色
指定边框颜色和th元素的文本和背景颜色
table, td, th {border:1px solid green; }
td { background-color:green; color:white;}