一、字体属性
1.font-family:字体族
常用的属性值有:Arial,Courer,宋体
<style type="text/css">
p.song{
font-family:宋体;
}
</style>
2.font-size:字体大小
常用单位为pt(point,磅),px(pixel,像素),有时也可用xx-small,x-small,medium,large,x-large,xx-
large
如:
<style type="text/css">
p.large{
font-size:20pt;
}
</style>
3.font-style:字体样式
属性值有:normal, italic, oblique,其中italic和oblique为斜体,但有些浏览器不支持oblique,建议
用斜体时使用italic
4.font-weight:字体粗细
属性值有:normal(默认值),bold,bolder,lighter
5.color:字体颜色
二、文本属性
1.text-indent:文本缩进
该属性可以指定段落首行的缩进
2.text-align:文本对齐
属性值有:left(默认值),right
3.text-decoration:文本修饰
用于指定文本和横线的关系,属性值有:none(默认值),overline(上划线),line-through(当中划
线),underline(下划线)
4.letter-spacing:字符间距
属性值可设定特定长度,默认值为normal
用于指定文本的颜色
示例:
text.html:
<html>
<head>
<title>文本属性演示</title>
<link href="text_show.css" rel="stylesheet" style="text/css">
</head>
<body>
<p class="indent">这是文本缩进,0.5in ,首行缩进</p>
<p>这是默认对齐方式</p>
<p class="alignr">这是右对齐方式</p>
<p>这是普通文本,无文本修饰</p>
<p class="overline">文本有上划线</p>
<p class="through">文本中间划线</p>
<p class="underline">文本有下划线</p>
<p class="spacing" >字符间距为:0.8in</p>
</body>
</html>
text_show.css:
p.indent{
text-indent:0.5in;
}
p.alignl{
text-align:left;
}
p.alignr{
text-align:right;
}
p.overline{
text-decoration:overline;
}
p.through{
text-decoration:line-through;
}
p.underline{
text-decoration:underline;
}
p.spacing{
letter-spacing:0.8in;
}
三、列表属性
列表样式类型属性为:list-style-type
1.无序列表
属性list-style-type 的常用属性值有:disc(实心圆点),circle(空心圆点),square(实心方块),none
2.有序列表
属性list-style-type的常用属性值有:decimal(阿拉伯数字),upper-alpha(小写字母),lower-alpha(大写
字母),upper-roman(大写罗马数字),lower-roman(小写罗马数字)
四、背景属性
1.background-color:背景颜色属性
该属性用于指定html背景颜色
2.background-image:背景图片属性:
该属性用于指定html背景图片
如:
<html>
<head>
<title>背景颜色和背景图片</title>
</head>
<body style="background-color:#990012;background-image:url(Images/bg.jpg)">
<p><font color=#0000ff>现在我们在演示背景颜色和背景图片</font></p>
</body>
</html>
五、边框属性
1.border-style:边框样式
每个html元素都有一个border-style属性,该属性用于指定元素的内容是否有一个边框,并指定边框的样式.
属性值有:none(默认值),dotted(点线式),dashed(破折线),solid(直线),double(双线),groove (槽线),
ridge(脊线),inset (内嵌),outset (突起)
2.border-width:边框宽度
该属性用来指定上下左右边框的宽度,常用属性值有medium,thin,thick,也可用带长度单位的数字指定.
另外,也可分别指定元素四个边框的宽度,可通过属性border-top-width,border-bottom-width,border-
left-width,border-right-width来设置.
3.border-color:边框颜色
该属性用于指定边框的颜色.元素的四个边框的颜色也可以不相同,可通过属性border-top-color,border-
bottom-color,border-left-color,border-right-color来设置.
六、间隙属性
间隙(padding)用于指定元素内容与其边框之间的距离。
1.padding-left:左间隙属性
用来设置元素内容到左边框的宽度
2.padding-right:右间隙属性
用来设置元素内容到右边框的宽度
3.padding-top:上间隙属性
用来设置元素内容到上边框的宽度
4.padding-bottom:下间隙属性
用来设置元素内容到下边框的宽度
特殊写法:
(1)上下左右间隙相同
.mypadding1{padding:0.1in}
(2)分别设置上下左右间隙(顺序是上,右,下,左)
.mypadding2{padding:0.1in 0.2in 0.3in 0.4in }
七、margin
边距(margin)用于指定元素边框与相邻元素边框之间的距离。
1.margin-left:左边距属性
该属性用于指定左边距的宽度
2.margin-right:右边距属性
该属性用于指定右边距的宽度
3.margin-top:上边距属性
该属性用于指定上边距的宽度
4.margin-bottom:下边距属性
该属性用于指定下边距的宽度
特殊写法:
(1)上下左右边距相同
.mymargin1{margin:0.1in}
(2)分别设置上下左右边距(顺序是上,右,下,左)
.mymargin2{margin:0.1in 0.2in 0.3in 0.4in}