这里写目录标题
二十二、选择器
1、标签选择器
<title>Document</title>
<style>
div{ width: 50% ; height: 100px ; background-color : red; }
h1{color : blue; }
</style>
</head>
<body>
<div>111</div>
<div>222</div>
<h1>111</h1>
<p>111</p>
</body>
</html>
2、类选择器
<title>Document</title>
<style>
.ibm{background-color : red;}
.qianfeng{color:red;}
</style>
</head>
<body>
<div>111</div>
<div class="ibm">222</div>
<div class="ibm qianfeng">333</div>
<div>444</div>
</body>
</html>
3、id选择器
<title>Document</title>
<style>
#box1{background-color : red;}
#box2{background-color : blue;}
#box3{background-color : yellow;}
</style>
</head>
<body>
<div id="box1">111</div>
<div id="box2">222</div>
<div id="box3">333</div>
</body>
</html>
4、通配选择器
外边距:margin:0;
内边距:padding:0;
*{margin:0;padding:0;}
5、群组选择器
<style>
div , p , h1{ background: yellow;}
</style>
6、后代选择器
<title>Document</title>
<style>
div p{ background: yellow;}
</style>
</head>
<body>
<div>
<p>111</p>
</div>
</body>
</html>
7、伪类选择器
link和visited只能用于a,其他的可以用于其余的。
<title>Document</title>
<style>
a:link{color: yellow;}
a:visited{color: red;}
a:hover{color: orange;}
a:action{color: green;}
</style>
</head>
<body>
<a href="http://www.baidu.com">百度</a>
</body>
</html>
8、选择器的权重
!important>内联样式>包含选择器>id选择器>class选择器>类型(元素)选择器
二十三、文本属性
词间距:word-spacing
首行缩进
em单位 :相对单位,1em永远跟字体大小相同 (字缩进字符与字大小不同行与行之间无法对齐,所以需要em单位)
字体:
text-transform: capitalize(首字母大写)
text-transform: lowercase(字母小写)
text-transform: uppercase(字母大写)
text-transform: none(无设置)
二十四、列表属性
二十五、背景属性
背景图片大小
background- size
cover:把背景图像扩展至足够大,以使背景图像完全覆盖背景区域。也许无法显示在背景定位区域中。
contain:把图像图像扩展至最大尺寸,以使其宽度和高度完全适应内容区域。铺不满盒子,留白
视觉差
<title>Document</title>
<style>
#div1{ width:1400px;height: 800px; background-image:url(图片地址1); background-attachment: fixed;}
#div2{ width:1400px; height: 800px; background-image:url(图片地址2); background-attachment: fixed;}
#div3{ width:1408px; height: 800px; background-image:url(图片地址3); background-attachment: fixed;}
</style>
</head>
<body>
<div id="div1">
内容1
</div>
<div id="div2">
内容2
</div>
<div id="div3">
内容3
</div>
</body>
</html>
二十六、背景的复合属性
复合写法:
- 用空格隔开
- 顺序可以换
- 可以只取一个值,放在后面能覆盖前面的值
- background-size只能单独用
注释处与下方代码效果一致
<style>
div{
width : 600px;
height : 600px;
/* background-color: yellow;
background-image:
url(img/1.jPg);background-repeat: no-repeat;
background-position: center;
background-attachment: fixed; */
background : yellow url(img/1.jpg) no-repeat center fixed;}
</style>
二十七、浮动属性
清浮动:
- 固定高度
- clear清浮动
- 当前浮动元素后面补一个盒子,不设宽高,clear:both
- overflow:hidden,让浮动元素计算高度
二十八、盒子模型
注:
1.背景颜色会填充到margin以内的区域。
2.文字会在content区域。
3. padding不能出现负值,margin是可以出现负值。
1、内边距
padding :
只写一个值 :30px
写两个值:30px 40px(上下、左右)
写四个值:30px 40px 50px 60px(上、右、下、左)
单一样式只能写一个值
padding-left
padding-right
padding-top
padding-bottom
2、边框
border-top(方向)
border-width 边框宽度
border-style 边框样式
border- color 边框颜色
solid 实线
double 双线
dashed 虚线
dotted 圆点线
(背景色也能蔓延到边框)
3、外边距
margin :外边距(外填充)
只写一个值 :30px
写两个值:30px 40px(上下、左右)
写四个值:30px 40px 50px 60px(上、右、下、左)
单一样式只能写一个值
margin-left
margin-right
margin-top
margin-bottom