注册表单选,择器权重的计算过程,上下文选择器
16lz
2021-09-29
制作一个用户注册表单,尽可能将常用控件都用一遍
<!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>
</head>
<body>
<h2>用户注册</h2>
<!--GET: 数据在url中,文明发送,适合少量数据,不超过4k-->
<!--post: 数据在请求体中,不在url中,安全,可发送大量的数据,例如文件上传-->
<form action="check.php" method="POST" style="display: grid; gap: 0.5em">
<fieldset>
<legend>必填项</legend>
<div>
<!--单行文本框-->
<label for="username">账号</label>
<input
type="text"
id="username"
name="username"
placeholder="用户名"
required
autofocus
/>
</div>
<div>
<label for="psw">密码</label>
<input
type="password"
id="psw"
name="psw"
placeholder="密码"
required
autofocus
/>
<!--<button type="button" onclick="document.querySelector('#psw').type='text'" >显示密码 </button> -->
</div>
<div>
<label for="email">邮箱</label>
<input
type="email"
id="email"
name="email"
placeholder="123123@qq.com"
required
autofocus
/>
</div>
<!--checked布尔属性,不需要值,只要存在就是true /真-->
</fieldset>
<!--单选框-->
<div>
<label for="secret">性别:</label>
<!--单选按钮中的name属性,必须全部一样,才能保证返回唯一值-->
<input type="radio" name="gender" id="male" value="male" />
<label for="male">男</label>
<input type="radio" name="gender" id="female" value="female" />
<label for="female">女</label>
<input type="radio" name="gender" id="secret" value="secret" checked />
<label for="secret">保密</label>
<!--checked布尔属性,不需要值,只要存在就是true /真-->
</div>
<!--复选框-->
<div>
<label for="secret">爱号:</label>
<!--单选按钮中的name属性,必须全部一样,才能保证返回唯一值-->
<!--bobby[]表示数组,可以保存一组不同类型的数据,供后端调用-->
<input type="checkbox" name="hobby[]" id="game" value="game" />
<label for="game">游戏</label>
<input type="checkbox" name="hobby[]" id="trvae" value="trvae" />
<label for="trvae">旅游</label>
<input
type="checkbox"
name="hobby[]"
id="shoot"
value="shoot"
checked
/>
<label for="shoot">摄影</label>
<!--checked布尔属性,不需要值,只要存在就是true /真-->
</div>
<div>
<!--下拉列表,将变量名和多个值分开设置,由用户自己选择-->
<!--name,vlaue应该在一个标签内,但是select-->
<select name="" id="">
<option value="1">铜牌会员</option>
<option value="2">银牌会员</option>
<option value="3" selected>金牌会员</option>
<option value="4">永久会员</option>
</select>
</div>
<!--自定义下拉列表-->
<!--datalist+input-->
<div>
<label for="">搜索关键词:</label>
<input type="search" name="search" list="keywords" />
<datalist id="keywords">
<option value="html">html</option>
<option value="css">css</option>
<option value="js">js</option>
<option value="javascript">javascript</option>
</datalist>
</div>
<button>提交</button>
<!--重置不是清空,是恢复到默认值-->
<button type="reset">重置</button>
<!--不想提交,想自定义提交验证的规则,例如异步ajax提交-->
</form>
</body>
</html>
2. 实例演示选择器权重的计算过程;
<!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标签设置样式,适合于当前html文档,内部样式/文档样式-->
<style>
/* 1,浏览器默认样式
h2 {
display: block;
font-size: 1.5em;
margin-block-start: 0.83em;
margin-block-end: 0.83em;
margin-inline-start: 0px;
margin-inline-end: 0px;
font-weight: bold;
}
*/
/* 2,用户自定义样式*/
/*
h1 {
color: brown;
background-color: yellow;
}
*/
</style>
</head>
<body>
hello world
<h1 id="title">hello world</h1>
<!--style属性: 行内样式,仅限于当前元素-->
<h1 style="color: tomato">hello world</h1>
<!--浏览器不检查id的唯一性,唯一性由程序员自己确保-->
<h2 id="title">大家晚上听得很认真</h2>
<style>
/* 选择器: 用于选择页面中一个或多个元素的字符串*/
/*选择器 {
声明1;
声明2;
}*/
/* 选择器 +声明块 +规则 */
/* [id="title"] {
color: brown;
background-color: yellow;
}
*/
#title {
color: #000;
background-color: turquoise;
}
</style>
<p class="demo">今晚我吃的很棒</p>
<h2 class="demo">css其实很有意思</h2>
<style>
[class="demo"] {
color: tomato;
background-color: blanchedalmond;
}
.demo {
color: blue;
background-color: crimson;
}
</style>
<h2 style="color: crimson" id="test" class="aaa">猪老师</h2>
<style>
h2 {
color: blue !important;
/*--!important 用在样式的调试--*/
}
.aaa {
color: crimson;
}
#test {
color: darkgreen;
}
/*--css里面!important大于style大于id大于class大于tag--*/
</style>
<!--三大通用属性;几乎所有的元素都可以使用的属性-->
<!--属性style id class 背下来-->
<h3 id="a" class="b">你好啊</h3>
<style>
/*选择当前的h3有三种选择器:
标签 class id*/
/* 将id,class,tag,想象成一个三位整数,初始为0,0,0 */
/*百位 十位 个数
id class tag
0 0 0 */
/*百位对应;id
十位对应:class
个位对应:tag */
/*id权重大于class大于tag*/
/*1 1 0*/
#a .b {
background-color: indigo;
}
/*1 0 0*/
#a {
background-color: indigo;
}
/*0 1 1*/
h3 .b {
background-color: goldenrod;
}
/*0 1 0*/
.b {
background-color: darkolivegreen;
}
/* 0 0 2*/
body h3 {
color: darkslategrey;
}
/*0 0 1*/
h3 {
color: dodgerblue;
}
/*为什么要学他,因为有许多框架有原始的样式表,这些不能动*/
/*element ui , layui bootstrap ....*/
.col-md-3 {
}
div.clo-md-3 {
/*这样就可以放心的写自己的代码了,不必担心原始的框架源码,为什么?因为权重最大直接覆盖*/
}
上下文选择器
<!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>
</head>
<body>
<ul class="list">
<li>item1</li>
<li class="item">item2</li>
<li>item3</li>
<ul>
<li>item1</li>
<li>item2</li>
<li>item3</li>
</ul>
<li>item4</li>
<li>item5</li>
<li>item6</li>
<li>item7</li>
<li>item8</li>
</ul>
<style>
/*子元素>>>*/
.list > li {
border: 1px solid mediumblue;
}
/*后代 空格*/
.list li {
border: 1px solid mediumblue;
}
/*相邻;+*/
.list .item + * {
background-color: mediumvioletred;
}
/*所有兄弟全选中;~ */
.list .item ~ * {
background-color: mediumvioletred;
}
</style>
</body>
</html>
更多相关文章
- HTML常用标签的用法示例
- 1.模态框 2.flex布局 3.grid属性
- CSS盒模型常用属性,单位,选择器
- 绝对定位、固定定位及flex,grid属性
- 1.box-sizing属性 2.伪类选择器 3.媒体查询
- Flex与grid属性思维导图
- Nofollow属性的介绍和使用
- HTML表单与选择器学习与应用
- CSS 元素样式来源