表单:负责采集用户输入的信息,由相当多的表单元素组成。
- 基本语法:
- method:get和post,默认为get。用这种方式提交数据用于设置表单数据的提交方式,保密性差且有数据量限制。post不但保密性好,还可以提交大量的数据。
<form action="url地址" method="提交方式" name="表单名称">
各种表单控件
</form>
- 表单标签:包含处理表单数据所用的CGI程序好的URL以及提交服务器的方法。
- 表单域:文本框、密码框、隐藏域、多行文本框、复选框、下拉菜单
- 表单按钮:提交按钮、复位按钮
HTML5新增的表单属性
(1)autocomplete属性:用于指定表单是够有自动完成功能
- on:表单有自动完成功能
- off:表单无自动完成功能
(2)novalidate属性:用于在提交表单取消对表单进行有效的检查。
HTML5标签
- type:text、password、radio、CheckBox、button、submit、reset、image、hidden、file、URL、number、range、date、search、color、tel
- name:控件名称
- value:input控件的默认文本
- size:正整数:显示宽度
- readonly:设置只读
- disabled:第一次加载是禁用该控件
- checked:默认选中
- maxlength;输入最多字符数
- autocomplete:自动完成表单内容
- autofocus:自动获取焦点
- form:设定字段隶属于哪一个或多个表单
- list:datalist的id元素:字段候选数据列表
- multiple:是否选择多个值
- min\max\step:最大值、最小值、间隔
- pattern:验证内容是否无正则表达式匹配
- placeholder:为input类型的输入提示一种提示
- required:规定填入的内容不能为空
下面是一个登录界面:
<!DOCTYPE<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<style>
body{
background: url('./image/背景图片1.jpg') center center fixed;
background-size: cover;
padding: 20px;
}
form{
width: 343px;
height: 500px;
margin: 0 auto;
padding: 30px;
border:1px solid rgba(0, 0, 0, 0.2);
border-radius: 5px;
background-color: rgba(0,0,0,0.5);
box-shadow: 0 0 13px 3px rgba(0,0,0,0.5);
overflow: hidden;
}
.border-radius{
width: 200px;
height: 200px;
border-radius: 200px;
background: url('./image/1 (1).jpg') no-repeat center center;
margin: 40px auto;
border:5px solid rgba(255,255,255,0.4)
}
input{
width:276px ;
height: 48px;
border:1px solid rgba(68, 67, 67, 0.4);
border-radius:4px;
display: block;
font-size: 18px;
color:rgb(59, 59, 59);
padding-left: 45px;
padding-right: 20px;
margin-bottom: 20px;
margin-left: 20px;
background: rgba(255,255,255,0.4) no-repeat 16px 16px;
}
input[type=submit]{
cursor: pointer;
}
::-webkit-input-placeholder{
color: white;
}
.btn{
width: 138px;
height: 44px;
border-radius: 4px;
padding:15px 20px;
border-radius: 6px;
color:whitesmoke;
margin-left: 60px;
}
.btn:hover{
border:1px solid black;
box-shadow: 0px 1px 0 black;
}
input:focus{
background-color: rgba(0, 0, 0, 0.2);
box-shadow: 0 0 5px 1px rgba(255,255,255,.0.5);
overflow: hidden;
}
.btn:active{
margin-top: 1px;
text-shadow: 0 -1px #333333;
background: #00B0DC;
color:#fff
}
</style>
</head>
<body>
<form action="">
<div class="border-radius"></div>
<input type="text" name="name" placeholder="用户名">
<input type="password" name="password" placeholder="登录密码">
<input type="submit" name="submit" value="登录" class="btn">
</form>
</body>
</html>