一、CSS在网页中的应用方式:
1、 行业样式:(把css样式写入html中----不推荐使用)
例如:<p style=”font-size:12px;” >网页</p>
2、 内嵌样式:(在<head></head>之间)
<style type=”text/css”>
Html标记 / 类名称(class=”类名称”){
Color : red;
属性 :属性值;
}
</style>
如:如果一个整站有很多页面,此方法很麻烦,适用于一个页面
3、 链接样式:(在<head></head>之间)
<link href=”style.css”rel=”tyllesheet” type=”text/css”>
注:css代码和html完全分离,推荐使用
4、 导入样式:例子:
<style>
<!—
@import url(“main.css”);
-->
</style>
以上优先级:由高到低
1行内样式----à内嵌样式、链接样式--à4导入样式
内嵌样式和链接样式,这两个优先级不一定,主要看谁的位置在前就读谁
二、CSS选择器
1、标记选择器(自动应用):
<style>
H1,p,span{-------------选择器
color:red;
属性:值;
}
</style>
2、类别选择器(手动应用)
<style>
.text{-------------类别选择器(定义的class=”text”)
color:red;
属性:值;
}
</style>
3、id选择器
<style>
#idone {-------------id选择器(定义id=”idone”)
Font-weight:bold;-----加粗
属性:值;
}
</style>
Id选择器和类别选择器的区别:
(1) id选择器是:#号
类别选择器是:.(点)
(2)id选择器用于整个布局,一个页面只用一次
类别选择器用于样式,用于多个页面
三、选择器的声明
1、集体声明:用逗号,如:
H1,h2,p,span{
Text-decoration:underline;
}
2、全局声明:*号
*{------对于这个页面
Bgcolor:red;
}
四、文字CSS效果
<span></span>-------行内元素,单独对某一个进行设置
Font:
font-style:istalic;------文本倾斜(<i></i>)
font-style:normal;-----文本不倾斜
font-weight:bold / normal;-----文本加粗、不加粗
font-family:”黑体”;-------字体(<b></b>)
font-size:20px;----------文本大小
color:red;--------------文本颜色;
线:
text-decoration:overline;------------上划线
text-decoration:underline;------------下划线(<u></u>)
text-decoration:line-through;------------删除线(<s></s>)
字母:
Text-tansform:capitalize;---------单词首字母大写
Text-tansform:uppercase;---------单词首全部大写
Text-tansform:lowercase;---------单词首全部小写
Letter-spacing:2px;---------字母间距