CSS与HTML结合方式:
(1)在每个HTML标签中都有个style
(2)在头文件中写一个style标签
<style type="text/css">
(选择器名称)div{
background-color:blue;
color:red;
}
</style>
(3)在style标签中,使用:@import url(css路径)(缺点:在某些浏览器中不起作用)
<style type="text/css">
@import url(css路径)
</style>
(4)使用头标签link,引入外部css文件
<link rel="stylesheek" type="text/css" href="css文件路径"/>
(5)三种基本选择器
标签选择器:
div{
background-color:red;
}
class选择器:
div.classname{
background-color:blue;
}
id选择器:
div#idname{
background-color:orange;
}
(6)选择器的优先级:
style>id>class>标签
(7)扩展选择器
关联选择器:
div p{
background-color:green;
}
组合选择器:
div,p{
background-color:#156544;
}
伪元素选择器:
*css定义好的一些样式,可以直接使用。
css盒子模型
(1)边框
border:统一设置
border:2px solid blue
分别设置:
上 border-top
下 border-bottom
左 border-left
右 border-right
(2)内边距
padding:统一设置
padding:20px
上 padding-top
下 padding-bottom
左 padding-left
右 padding-right
(3)外边距
margin:统一设置
margin:20px
上 margin-top
下 margin-bottom
左 margin-left
右 margin-right
CSS布局的定位
position:
**属性值:
-absolute:将对象从文档流中拖出,使用left,top,right,bottom等属性进行定位
-relative:对象不可层叠,使用left,top,right,bottom等属性在正常界面进行偏移