html表格创建及样式设定
table标签 声明表格
tr标签 定义表格中的一行
td和th标签 定义一行中的一个单元格 td表示普通单元格 th表示表头单元格
表格中有数据的权重大于没有数据的权重 显示比其他没有数据的格子大些
样式:border-collapse:collapse 边线合并
样式:text-align:center 文字水平居中
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
<style>
.table01{
width: 500px;
height: 200px;
border: 1px solid black;
border-collapse: collapse;
margin: 0px auto;
}
.table01 th{
border: 1px solid black;
background: lightblue;
}
.table01 td{
border: 1px solid black;
text-align: center;
}
</style>
</head>
<body>
<table class="table01">
<tr>
<th>序号</th>
<th>姓名</th>
<th>性别</th>
<th>年龄</th>
<th>班级</th>
</tr>
<tr>
<td>1</td>
<td>二狗子</td>
<td>男</td>
<td>18</td>
<td>幼儿园</td>
</tr>
<tr>
<td>1</td>
<td>二狗子</td>
<td>男</td>
<td>18</td>
<td>幼儿园</td>
</tr>
<tr>
<td>1</td>
<td>二狗子</td>
<td>男</td>
<td>18</td>
<td>幼儿园</td>
</tr>
<tr>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
</tr>
</table>
</body>
</html>
定位
文档流:
指盒子按照html标签编写的顺序依次从上到下 从左到右排序
块元素占一行 行内元素在一行之内从左到右排序
定位:css的position属性不受文档流影响
relative相对定位
相对自身位置做偏移
absolute绝对定位
相对于父级位置定位
fixed固定定位
相对于浏览器四个角 进行定位
常用绝对定位 相对定位
定位元素的层级
设置z-index 优先度 越大 优先越高
相对位置
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
<style>
.con{
width: 300px;
height: 300px;
border: 1px solid black;
margin: 0px auto;
}
.con div{
width: 200px;
height: 70px;
margin: 10px;
}
.box01{
background: lightblue;
position: relative;
left: 32px;
top: 50px;
}
.box02{
background: lightpink;
}
.box03{
background: lightgray;
}
</style>
</head>
<body>
<div class="con">
<div class="box01">1</div>
<div class="box02">2</div>
<div class="box03">3</div>
</div>
</body>
</html><!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
<style>
.con{
width: 300px;
height: 300px;
border: 1px solid black;
margin: 0px auto;
}
.con div{
width: 200px;
height: 70px;
margin: 10px;
}
.box01{
background: lightblue;
position: relative;
left: 32px;
top: 50px;
}
.box02{
background: lightpink;
}
.box03{
background: lightgray;
}
</style>
</head>
<body>
<div class="con">
<div class="box01">1</div>
<div class="box02">2</div>
<div class="box03">3</div>
</div>
</body>
</html>
绝对定位
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
<style>
.con{
width: 300px;
height: 300px;
border: 1px solid black;
margin: 0px auto;
position: relative;
overflow: hidden;
}
.con div{
width: 200px;
height: 70px;
margin: 10px;
}
.box01{
background: lightblue;
position: absolute;
left: 32px;
top: 50px;
}
.box02{
background: lightpink;
}
.box03{
background: lightgray;
}
</style>
</head>
<body>
<div class="con">
<div class="box01">1</div>
<div class="box02">2</div>
<div class="box03">3</div>
</div>
</body>
</html>
固定定位
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
<style>
.con{
width: 300px;
height: 300px;
border: 1px solid black;
margin: 0px auto;
}
.con div{
width: 200px;
height: 70px;
margin: 10px;
}
.box01{
background: lightblue;
position: fixed;
left: 32px;
top: 50px;
}
.box02{
background: lightpink;
}
.box03{
background: lightgray;
}
</style>
</head>
<body>
<div class="con">
<div class="box01">1</div>
<div class="box02">2</div>
<div class="box03">3</div>
</div>
</body>
</html>
定位元素的层级
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
<style>
.con{
width: 300px;
height: 300px;
border: 1px solid black;
margin: 0px auto;
}
.con div{
width: 200px;
height: 70px;
margin: 10px;
}
.box01{
background: lightblue;
position: absolute;
left: 0px;
top: 0px;
z-index: 6;
}
.box02{
background: lightpink;
position: absolute;
left: 30px;
top: 30px;
z-index: 7;
}
.box03{
background: lightgray;
position: absolute;
left: 60px;
top: 60px;
z-index: 8;
}
</style>
</head>
<body>
<div class="con">
<div class="box01">1</div>
<div class="box02">2</div>
<div class="box03">3</div>
</div>
</body>
使用定位创建垂直水平居中弹框
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
<style>
.pop{
width:500px;
height: 300px;
border: 1px solid black;
background: white;
position:fixed;
left: 50%;
top: 50%;
margin-left: -251px;
margin-top: -151px;
z-index: 9999;
}
.pop h3{
margin: 5px;
background: lightblue;
line-height: 40px;
}
.mask{
position: fixed;
left: 0px;
top: 0px;
width: 100%;
height: 100%;
background: black;
z-index: 9998;
opacity: 0.3;
filter: alpha(opacity=30);
}
.pop_con{
display: none;
}
</style>
</head>
<body>
<h1 class="pop_con" style="display: block;">网页内容</h1>
<div class="pop">
<h3>弹框标题</h3>
<p>弹框的文字内容</p>
</div>
<div class="mask"></div>
</body>
</html>
css权重值
多条样式作用于一个元素 使用权重大的样式
权重的等级
内联样式 style="" 权重值为1000
ID选择器 #content 权重值为100
类 伪类 .div{} 权重值为10
标签选择器 div p 权重值为1
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
<style>
div{
color: red;
}
body .con .box h3{
color:blue
}
.con .box h3{
color:red
}
</style>
</head>
<body>
<div style="color: blue">
this is a div
</div>
<div class="con">
<div class="box">
<h3 style="color: pink;">this is h3</h3>
</div>
</div>
</body>
</html>