定位
position属性可以控制Web浏览器如何以 及在何处显示特定的元素。
可以使用position属性把一个元素放置到网 页中的任何位置。可选值:
static
relative
absolute
fixed
相对定位
- 每个元素在页面的文档流中都有一个自然位置。相 对于这个位置对元素进行移动就称为相对定位。周 围的 元素完全不受此影响。
- 当将position属性设置为relative时,则开启了元素 的相对定位。
- 当开启了相对定位以后,可以使用top、right、 bottom、left四个属性对元素进行定位
特点
- 如果不设置元素的偏移量,元素位置不会发生改变。
- 相对定位不会使元素脱离文本流。元素在文本流中 的位置不会改变。
- 相对定位不会改变元素原来的特性。
- 相对定位会使元素的层级提升,使元素可以覆盖文 本流中的元素。
绝对定位
- 绝对定位指使元素相对于html元素或离他最近 的祖先定位元素进行定位。
- 当将position属性设置为absolute时,则开启 了元素的绝对定位。
- 当开启了绝对定位以后,可以使用top、right、 bottom、left四个属性对元素进行定位。
特点
- 绝对定位会使元素完全脱离文本流。
- 绝对定位的块元素的宽度会被其内容撑开。
- 绝对定位会使行内元素变成块元素。
- 一般使用绝对定位时会同时为其父元素指定一 个相对定位,以确保元素可以相对于父元素进 行定位。
固定定位
- 固定定位的元素会被锁定在屏幕的某个位置上,当 访问者滚动网页时,固定元素会在屏幕上保持不动。
- 当将position属性设置为fixed时,则开启了元素的 固定定位。
- 当开启了固定定位以后,可以使用top、right、bottom、left四个属性对元素进行定位。
- 固定定位的其他特性和绝对定位类似。
z-index层级设置
- 当元素开启定位以后就可以设置z-index这 个属性。
- 这个属性可以提升定位元素所在的层级。
- z-index可以指定一个整数作为参数,值越 大元素显示的优先级越高,也就是z-index 值较大的元素会显示在网页的最上层。
- 无论z-index值多都不能够将自己的子元素覆盖
表格table
- tr表示一行
- th表示表头
- td表示一个单元格
- 对于表格可以设置thead tbody tfoot并且无论位置如何表格顺序均不变
- colspan横向合并colspan=“2”横向合并2行在td里写<td colspan=“2”></td>
- rowspan横向合并rowspan=“2”纵向合并2列在td里写<td rowspan=“2”></td>
其他样式
- text-align:设置文本的水平对齐。
- vertical-align:设置文本的垂直对齐。
可选值:top、baseline、middle、bottom - border-spacing:边框间距
- border-collapse:合并边框
collapse:合并边框
separate:不合并边框
子类与父类分开解决高度塌陷的又一个方法display table
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<style type="text/css">
.box1{
width: 200px;
height: 200px;
background-color: #d86aff;
}
.box2{
width: 100px;
height: 100px;
background-color: yellow;
margin-top: 100px;
}
.box1:before{
content: "";
display: table;
}
.box3{
border: 1px solid red;
}
.box4{
width: 100px;
height: 100px;
background-color: cornflowerblue;
}
.clearfix:before,.clearfix:after{
content: "";
display: table;
clear: both;
}
.clearfix{
zoom: 1;
}
</style>
</head>
<body>
<div class="box3 clearfix">
<div class="box4"></div>
</div>
<div class="box1 clearfix">
<!--<table></table>-->
<div class="box2"></div>
</div>
</body>
</html>
表单
基本用法如下:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<style type="text/css">
/*.form{*/
/*background-color: #bbffaa;*/
/*text-align: center;*/
/*}*/
</style>
</head>
<body>
<form method="get" action="1.html" class="form">
<table align="center" border="0">
<tr>
<td>
用户名:
</td>
<td><input type="text" name="username" id="username" placeholder="请输入用户名" size="30"></td>
</tr>
<tr>
<td>
密 码:
</td>
<td><input type="password" name="password" id="password" placeholder="请输入密码" size="30"></td>
</tr>
<tr>
<td>
性别:
</td>
<td><input type="radio" name="radio">男
<input type="radio" name="radio">女
</td>
<tr>
<tr>
<td>
爱好:
</td>
<td><input type="checkbox" name="checkbox">游泳
<input type="checkbox" name="checkbox">下棋
<input type="checkbox" name="checkbox">网球
<input type="checkbox" name="checkbox">篮球
</td>
</tr>
<tr>
<td colspan="2">
来自:
<select>
<option>请选择</option>
<optgroup label="中国">
<option>广州</option>
<option>上海</option>
<option>北京</option>
</optgroup>
<optgroup label="美国">
<option>华盛顿</option>
<option>纽约</option>
<option>休斯敦</option>
</optgroup>
</select></td>
</tr>
<tr>
<td>
<input type="submit" name="submit" id="submit"></td>
<td><input type="reset" name="reset" id="reset"></td>
</tr>
</table>
</form>
</body>
</html>
结果如下:

表单.png
表单其他属性
textarea
- textarea用来创建一个文本域,实际效果和 文本框类似,只是可以输入多行数据。
可用属性:
cols:文本域的列数
rows:文本域的行数
fieldset
- fieldset用来为表单项进行分组。
label
- label标签用来为表单项定义描述文字
附录
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<style type="text/css">
*{
margin: 0;
padding: 0;
}
.one{
width: 960px;
height: 42px;
margin: 50px auto;
list-style-type: none;
border: 1px solid gainsboro;
}
.one li{
float: left;
margin: 8px 5px;
position: relative;
left: 239px;
}
.one a:not(.span){
display: block;
text-decoration: none;
padding: 5px 10px;
background-color: gold;
color: black;
text-align: center;
font: 12px 微软雅黑;
}
.span{
text-decoration: none;
}
.one a:hover{
background-color: #d86aff;
}
.two{
width: 960px;
height: 42px;
margin: 50px auto;
list-style-type: none;
border: 1px solid black;
text-align: center;
}
.two a{
text-decoration: none;
font: 14px 微软雅黑;
color: #333;
font-weight: bold;
}
.two li{
display: block;
float: left;
margin: 9px 0px;
position: relative;
left: 170px;
}
.two span{
margin: 0px 20px;
}
.two a:hover{
background-color: #bbffaa;
}
</style>
</head>
<body>
<div class="box1">
<ul class="one">
<li><a href="#">上一页</a></li>
<li><a href="#">1</a></li>
<li><a href="#">2</a></li>
<li><a href="#">3</a></li>
<li><a href="#">4</a></li>
<li><a href="#" class="span"><span >...</span></a></li>
<li><a href="#">17</a></li>
<li><a href="#">18</a></li>
<li><a href="#">19</a></li>
<li><a href="#">20</a></li>
<li><a href="#">下一页</a></li>
</ul>
</div>
<div class="box2">
<ul class="two">
<li><a href="#">首页</a></li>
<li><span>|</span></li>
<li><a href="#">网站建设</a></li>
<li><span>|</span></li>
<li><a href="#">程序开发</a></li>
<li><span>|</span></li>
<li><a href="#">网络营销</a></li>
<li><span>|</span></li>
<li><a href="#">企业VI</a></li>
<li><span>|</span></li>
<li><a href="#">案例展示</a></li>
<li><span>|</span></li>
<li><a href="#">联系我们</a></li>
</ul>
</div>
</body>
</html>
结果如下:

标题栏.png