表单标签
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>表单标签</title>
</head>
<body>
<!--
from(表单标签):用于定义表单的,可以定义一个范围,这个范围代表
* 属性
* action:指定提交数据的URL
* method: 指定提交方式
* 分类: 一共7种 2种比较常用
get:
1. 请求参数会在地址栏中显示。会封装到请求行中(HTTP协议后讲解)。
2. 请求参数大小是有限制的。
3. 不太安全。
post:
1. 请求参数不会再地址栏中显示。会封装在请求体中(HTTP协议后讲解)
2. 请求参数的大小没有限制。
3. 较为安全。
* 表单项中的数据要想被提交:必须指定其name属性
* 表单项标签:
* input:可以通过type属性值,改变元素展示的样式
* type属性:
* text:文本输入框,默认值
* placeholder:指定输入框的提示信息,当输入框的内容发生变化,会自动清空提示信息
* password:密码输入框
* radio:单选框
* 注意:
1. 要想让多个单选框实现单选的效果,则多个单选框的name属性值必须一样。
2. 一般会给每一个单选框提供value属性,指定其被选中后提交的值
3. checked属性,可以指定默认值
* checkbox:复选框
* 注意:
1. 一般会给每一个单选框提供value属性,指定其被选中后提交的值
2. checked属性,可以指定默认值
* file:文件选择框
* hidden:隐藏域,用于提交一些信息。
* 按钮:
* submit:提交按钮。可以提交表单
* button:普通按钮
* image:图片提交按钮
* src属性指定图片的路径
* label:指定输入项的文字描述信息
* 注意:
* label的for属性一般会和 input 的 id属性值 对应。如果对应了,则点击label区域,会让input输入框获取焦点。
* select: 下拉列表
* 子元素:option,指定列表项
* textarea:文本域
* cols:指定列数,每一行有多少个字符
* rows:默认多少行。
-->
<form action="#" method="get">
<label for="username">用户名</label>:<input type="text" name="username" placeholder="请输入密码" id="username"><br>
密码:<input type="password" name="password" placeholder="请输入密码"><br>
性别:<input type="radio" name="gender" value="male"> 男
<input type="radio" name="gender" value="female" checked> 女
<br>
爱好:<input type="checkbox" name="hobby" value="shopping"> 逛街
<input type="checkbox" name="hobby" value="java" checked> java
<input type="checkbox" name="hobby" value="game"> 游戏 <br>
图片:<input type="file" name="file"><br>
隐藏域:<input type="hidden" name="id" value="aaa"><br>
拾色器:<input type="color" name="color"><br>
生日:<input type="data" name="birthday"><br>
生日:<input type="datetime-local" name="birthday"><br>
邮箱:<input type="email" name="email"><br>
年龄:<input type="number" name="age"><br>
省份:<select name="province">
<option value="">--请选择--</option>
<option value="1">北京</option>
<option value="2">上海</option>
<option value="3">陕西</option>
</select><br>
自我描述:
<textarea cols="20" rows="5" name="des"></textarea><br>
<input type="submit" value="登录">
<input type="button" value="一个按钮"><br>
<input type="image" src="icon_3.jpg">
</form>
</body>
</html>
案例
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>登陆界面</title>
</head>
<body>
<table border="1" width="500" align="center">
<form action="#" method="post">
<tbody align="center">
<tr>
<td>
<label for="username"> 用户名</label>:
</td>
<td>
<input type="text" name="username" placeholder="请输入账号" id="username">
</td>
</tr>
<tr>
<td>
<label for="password"> 密码 </label>:
</td>
<td>
<input type="password" name="password" placeholder="请输入密码" id="password">
</td>
</tr>
<tr>
<td>
<label for="email"> Email </label>:
</td>
<td>
<input type="email" name="email" placeholder="请输入Email" id="email">
</td>
</tr>
<tr>
<td>
<label for="name"> 姓名 </label>:
</td>
<td>
<input type="text" name="name" placeholder="请输入真实姓名" id="name">
</td>
</tr>
<tr>
<td>
<label for="tel"> 手机号 </label>:
</td>
<td>
<input type="text" name="tel" placeholder="请输入您的手机号" id="tel">
</td>
</tr>
<tr>
<td>
<label> 性别 </label>:
</td>
<td>
<input type="radio" name="gender" value="male" > 男
<input type="radio" name="gender" value="female" > 女
</td>
</tr>
<tr>
<td>
<label for="birthday"> 出生日期 </label>:
</td>
<td>
<input type="date" name="birthday" id="birthday">
</td>
</tr>
<tr>
<td>
<label for="checkCode"> 验证码 </label>:
</td>
<td>
<input type="text" name="checkCode" id="checkCode" >
<img src="svm_picture.png">
</td>
</tr>
<tr>
<td colspan="2">
<input type="submit" value="注册">
</td>
</tr>
</tbody>
</form>
</table>
</body>
</html>
运行结果:
css与html相结合
配置css文件
div{
color: red;
}
方式1:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>css+html</title>
<link rel="stylesheet" href="css/a.css">
</head>
<body>
<!--
外部样式:
1.定义css资源文件
2.在head标签内,定义link标签,引入外部的资源文件
-->
<div>hello css</div>
<div>hello css</div>
</body>
</html>
方式2:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<style>
div{
color: black;
}
</style>
</head>
<body>
<!--
内部样式
在head标签内,定义style标签,style标签的标签体内容就是css代码
-->
<div>hello css</div>
</body>
</html>
css语法格式
css语法:
- 格式:
选择器 {
属性名1:属性值1;
属性名2:属性值2;
...
}
- 选择器:筛选具有相似特征的元素
- 注意:
- 每一对属性需要使用;隔开,最后一对属性可以不加;
CSS选择器
- 基础选择器
- id选择器(优先级最高):选择具体的id属性值的元素.建议在一个html页面中id值唯一
- 语法:#id属性值{}
- 元素选择器:选择具有相同标签名称的元素
- 语法: 标签名称{}
- 注意:id选择器优先级高于元素选择器
- 类选择器:选择具有相同的class属性值的元素。
- 语法:.class属性值{}
- 注意:类选择器优先级高于元素选择器
- id选择器(优先级最高):选择具体的id属性值的元素.建议在一个html页面中id值唯一
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>基础选择器</title>
<style>
/* id选择器 */
#div1{
color:red;
}
/* 元素选择器 */
div{
color: blue;
}
/*类选择器*/
.cls1{
color: darkmagenta;
}
</style>
</head>
<body>
<div id="div1">我是你爸爸</div>
<div>你说啥?</div>
<p class="cls1">哦</p>
</body>
</html>
- 扩展选择器:
-
选择所有元素:
- 语法: *{}
-
并集选择器:
- 选择器1,选择器2{}
-
子选择器:筛选选择器1元素下的选择器2元素
- 语法: 选择器1 选择器2{}
-
父选择器:筛选选择器2的父元素选择器1
- 语法: 选择器1 > 选择器2{}
-
属性选择器:选择元素名称,属性名=属性值的元素
- 语法: 元素名称[属性名=“属性值”]{}
-
伪类选择器:选择一些元素具有的状态
- 语法: 元素:状态{}
- 如: < a >
- 状态:
- link:初始化的状态
- visited:被访问过的状态
- active:正在访问状态
- hover:鼠标悬浮状态
- 状态:
-
并集选择器:
h1,p{
background-color:yellow;
}
子选择器:
div p{
background-color:yellow;
}
父选择器:
div>p{
background-color:yellow;
}
属性选择器:
a[target=_blank]{
background-color:yellow;
}
伪类选择器:
a:link{
background-color:yellow;
}
案例
需求样式:
html css代码实现:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>注册页面</title>
<style>
*{
margin: 0px;
padding: 0px;
box-sizing: border-box;
}
body{
background: url("img/register_bg.png") no-repeat center;
background-size: cover;
}
.rg_layout{
width: 900px;
height: 500px;
border: 8px solid #EEEEEE;
background-color: white;
/*让div水平居中*/
margin: auto;
margin-top: 15px;
}
.rg_left{
/*border: 1px solid red;*/
float: left;
margin: 15px;
}
.rg_left > p:first-child{
color: #FFD026;
font-size: 20px;
}
.rg_left > p:last-child{
color: #A6A6A6;
font-size: 20px;
}
.rg_center{
/*border: 1px solid red;*/
float: left;
width: 450px;
}
.rg_right{
/*border: 1px solid red;*/
float: right;
margin: 15px;
}
.rg_right > p:first-child{
font-size: 15px;
}
.rg_right p a{
color: pink;
}
.td_left{
width: 100px;
text-align: right;
height: 45px;
}
.td_right{
padding-left: 50px;
}
#username, #password, #email, #name, #tel, #birthday, #checkCode {
width: 251px;
height: 32px;
border: 1px solid #A6A6A6;
/*设置边框圆角*/
border-radius: 5px;
padding-left: 10px;
}
#checkCode{
width: 110px;
}
#img_check{
height: 32px;
/*垂直居中*/
vertical-align: middle;
}
#btn_sub{
width: 150px;
height: 40px;
background-color: #FFD026;
border: 1px solid #FFD026;
}
</style>
</head>
<body>
<div class="rg_layout">
<div class="rg_left">
<p>新用户注册</p>
<p>USER REGISTER</p>
</div>
<div class="rg_center">
<div class="rg_form">
<form action="#" method="post">
<table>
<tr>
<td class="td_left"><label for="username">用户名</label></td>
<td class="td_right"><input type="text" name="username" placeholder="请输入用户名" id="username"></td>
</tr>
<tr>
<td class="td_left"><label for="password">密码</label></td>
<td class="td_right"><input type="password" name="password" placeholder="请输入密码" id="password"></td>
</tr>
<tr>
<td class="td_left"><label for="email">email</label></td>
<td class="td_right"><input type="email" name="email" placeholder="请输入Email" id="email"></td>
</tr>
<tr>
<td class="td_left"><label for="name">姓名</label></td>
<td class="td_right"><input type="text" name="name" placeholder="请输入真实姓名" id="name"></td>
</tr>
<tr>
<td class="td_left"><label for="tel">手机号</label></td>
<td class="td_right"><input type="text" name="tel" placeholder="请输入您的手机号" id="tel"></td>
</tr>
<tr>
<td class="td_left"><label >性别</label></td>
<td class="td_right"><input type="radio" name="gender" value="male"> 男
<input type="radio" name="gender" value="female"> 女 </td>
</tr>
<tr>
<td class="td_left"><label for="birthday">出生日期</label></td>
<td class="td_right"><input type="date" name="birthday" id="birthday"></td>
</tr>
<tr>
<td class="td_left"><label for="checkCode">验证码</label></td>
<td class="td_right"><input type="text" name="checkCode" id="checkCode">
<img id="img_check" src="verify_code.jpg">
</td>
</tr>
<tr>
<td colspan="2" align="center"><input type="submit" id="btn_sub" value="注册"></td>
</tr>
</table>
</form>
</div>
</div>
<div class="rg_right">
<p>已有账号?<a href="#">立即登录</a></p>
</div>
</div>
</body>
</html>
显示结果: