一、表单
简介
HTML表单(form)是HTML文档中的一个区域,包含了一系列的可交互元素。表单主要用于收集用户输入的信息。
常用表单元素
(1)文本输入元素
定义用于文本输入的单行输入字段。
格式:<input type="text"/>
(2)单选框元素
单选按钮允许用户在有限数量的选项中选择其中之一。
格式:<input type="radio"/>
(3)复选框元素
复选按钮允许用户在有限的选项中选择多个选项。
格式:<input type="checkbox" name=" "/>
注意: 同一组复选框,其name必须相同。
(4)文本区元素
用于输入多行文本内容。
格式:<textarea name="" rows="" cols=""></textarea>
(5)下拉选择元素
下拉列表按钮允许用户通过下拉列表框的方式选择相应选项。
格式:
<select>
<option></option>
<option></option>
<option></option>
</select>
注意: 有多少个选项就有多少个option。
(6)按钮元素
格式1:<input type="button"/>
格式2:<button type=""></button>
按钮的type类型有:button(普通按钮)、menu(菜单按钮)、reset(重置按钮)和submit(提交按钮)。
实例
运用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>个人简历</title>
<style type="text/css">
body {
justify-content: center;
display: flex;
}
table {
border: 1px solid black;
}
td {
border: 1px solid black;
width: 100px;
height: 40px;
}
#text{
text-align: center;
}
input{
height:40px;
}
</style>
</head>
<body>
<table cellspancing="0">
<tbody>
<caption>
<h2>个人简历</h2>
</caption>
<tr>
<td id="text">姓名</td>
<td>
<form>
<input type="text" name=""/>
</form>
</td>
<td id="text">性别</td>
<td>
<form>
<input type="radio" name="sex" value="男" />男
<input type="radio" name="sex" value="女" />女
</form>
</td>
<td id="text">出生年月</td>
<td>
<form>
<input type="date" name=""/>
</form>
</td>
<td rowspan="4">
<form>
<input type="file" name="photo" />
</form>
</td>
</tr>
<tr>
<td id="text">民族</td>
<td>
<form>
<input type="text" name=""/>
</form>
</td>
<td id="text">政治面貌</td>
<td>
<form>
<input type="text" name=""/>
</form>
</td>
<td id="text">身高</td>
<td>
<form>
<input type="number" name=""/>
</form>
</td>
</tr>
<tr>
<td id="text">学制</td>
<td>
<form>
<input type="number" name=""/>
</form>
</td>
<td id="text">学历</td>
<td>
<form>
<input type="text" name=""/>
</form>
</td>
<td id="text">户籍</td>
<td>
<form>
<input type="text" name=""/>
</form>
</td>
</tr>
<tr>
<td id="text">专业</td>
<td>
<form>
<input type="text" name=""/>
</form>
</td>
<td id="text" colspan="2">毕业学校</td>
<td colspan="2">
<form>
<input type="text" name="" style="width:258px;"/>
</form>
</td>
</tr>
<tr>
<td id="text" colspan="7"><b>技能、特长或爱好</b></td>
</tr>
<tr>
<td id="text">外语等级</td>
<td>
<form>
<input type="text" name=""/>
</form>
</td>
<td id="text">计算机</td>
<td colspan="4">
<form>
<input style="width:680px;" type="text" name=""/>
</form>
</td>
</tr>
<tr>
<td id="text" colspan="7">个人履历</td>
</tr>
<tr>
<td id="text">时间</td>
<td id="text" colspan="2"> 单位</td>
<td id="text" colspan="4">经历</td>
</tr>
<tr>
<td>
<form>
<input type="date" name=""/>
</form>
</td>
<td colspan="2">
<form>
<input type="text" name="" style="width:258px;"/>
</form>
</td>
<td colspan="4">
<form>
<input type="text" name="" style="width:680px;"/>
</form>
</td>
</tr>
<tr>
<td>
<form>
<input type="date" name=""/>
</form>
</td>
<td colspan="2">
<form>
<input type="text" name="" style="width:258px;"/>
</form>
</td>
<td colspan="4">
<form>
<input type="text" name="" style="width:680px;"/>
</form>
</td>
</tr>
<tr>
<td>
<form>
<input type="date" name=""/>
</form>
</td>
<td colspan="2" >
<form>
<input style="width:258px;" type="text" name=""/>
</form>
</td>
<td colspan="4">
<form>
<input style="width:680px;" type="text" name=""/>
</form>
</td>
</tr>
<tr>
<td id="text">联系方式</td>
</tr>
<tr>
<td id="text">通讯地址</td>
<td colspan="2">
<form>
<input style="width:258px;" type="text" name="address"/>
</form>
</td>
<td id="text">联系电话</td>
<td colspan="3">
<form>
<input style="width:515px;" type="tel" name="tel"/>
</form>
</td>
</tr>
<tr>
<td id="text">E-mail</td>
<td colspan="2">
<form>
<input style="width:258px;" type="email" name="email"/>
</form>
</td>
<td id="text">邮编</td>
<td colspan="3">
<form>
<input style="width:515px;" type="number" name="邮编"/>
</form>
</td>
</tr>
<tr>
<td id="text" colspan="7">自我评价</td>
</tr>
<tr>
<td colspan="7">
<form>
<select>
<option></option>
<option></option>
<option></option>
</select>
<textarea style="width:1100px;"name="othertall" cols="60" rows="10"></textarea>
</form>
</td>
</tr>
</tbody>
</table>
</body>
</html>
运行结果如下:
二、CSS样式
简介
CSS是Cascading Style Sheets的缩写,即层叠样式表单。CSS是HTML语言的一种扩展,其主要作用为:
1、定义web页面布局及页面中元素的显示方式;
2、利用CSS样式实现HTML内容的(结构)与表现(格式)的分离。
简而言之,CSS相当于HTML的“装饰器”。
语法结构
选择器{声明;声明;… }
注释
格式:/*注释内容*/
引入方式
(1)内嵌式
又称为行内式,在HTML标签内编写样式,如:<div style="width:500px;height:500px;"
(2)内部式
一般放置在HTML的head区域,只对当前页面有效,格式:<style type="text/css"></style>
(3)外部式
通过链接引入外部样式表文件,格式:<<link href="style.css">
选择器
选择器用于定位(选择)需要添加样式的网页元素,可分为以下几类:
- 标签选择器
顾名思义将HTML标签名作为选择器的名称,来进行样式设置。 - 类选择器
- ID选择器
用于为标有特定ID的HTML标签设置样式。 - 通配选择器
利用*为指定范围内的所有标签设置样式。 - 包含选择器
为父标签下的子标签设置样式。 - 选择器分组
为一组元素设置相同的样式,利用逗号分隔多个选择器。
标签 | 含义 |
---|---|
<style> | 定义样式定义 |
<link> | 定义资源引用 |
<div> | 定义文档中的节或区域(块级) |
<span> | 定义文档中的行内的小块或区域。 |
<font> | 规定文本的字体、字体尺寸、字体颜色等 |
实例
完成家用电器的统计,要求如下:
1、大标题背景:#0f7cbf ;字体大小:18px; 加粗,文本缩进1个文字的高 度,行高35px。
2、大家电等小标题:背景:#e4f1fa; 字体大小:14px; 加粗,文本缩进 2 个文字的高度,行高30px,颜色:#0f7cbf,当鼠标放上去时内容增加下划线。
3、平板电视等内容:字体颜色:#666,行高20px,文本缩进1个文字的高度,当鼠标放上去时颜色显示为#F60,并且增加下划线。
代码:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>家用电器商品分类列表</title>
<style type="text/css">
body{
width:300px;
}
#p1{
background-color:#0f7cbf;
font-size: 18px;
font-weight: bold;
text-indent: 12px;
line-height: 35px;
}
#p2{
background-color: #e4f1fa;
font-size: 14px;
font-weight: bold;
text-indent: 12px;
color: #0f7cbf;
line-height: 30px;
}
#p2:hover{
text-decoration: underline;
}
a{
text-indent: 12px;
color: #666;
line-height: 20px;
text-decoration: none;
}
a:hover{
color:#f60;
text-decoration: underline;
}
</style>
</head>
<body>
<p id="p1">家用电器</p>
<div>
<p id="p2">大家电</p>
<a href="">平板电视</a>
<a href="">洗衣机</a>
<a href="">冰箱</a>
<br>
<a href="">空调</a>
<a href="">烟机/灶具</a>
<a href="">热水器</a>
<br>
<a href="">冷柜/酒柜</a>
<a href="">消毒柜</a>
<a href="">家庭影院</a>
</div>
<div>
<p id="p2">生活电器</p>
<a href="">电风扇</a>
<a href="">吸尘器</a>
<a href="">净化器</a>
<br>
<a href="">净水设备</a>
<a href="">挂烫机</a>
<a href="">电话机</a>
</div>
<div>
<p id="p2">厨房电器</p>
<a href="">榨汁机</a>
<a href="">电压力机</a>
<a href="">电饭煲</a>
<br>
<a href="">豆浆机</a>
<a href="">微波炉</a>
<a href="">电磁炉</a>
</div>
<div>
<p id="p2">五金家装</p>
<a href="">淋浴/水槽</a>
<a href="">电动工具</a>
<a href="">手动工具</a>
<br>
<a href="">仪器仪表</a>
<a href="">浴霸/排气 </a>
<a href="">灯具</a>
</div>
</body>
</html>
运行结果如下: