表单状态伪类
/* 1. 匹配获取到焦点的元素*/
fieldset :focus {
background-color: lightgreen;
transition: 0.5s;
}
/* 2. 匹配被选中的复选框元素*/
input[type='checkbox']:checked + label {
color: red;
}
/* 3. 当鼠标悬停到某个元素上的效果*/
button {
/* 去掉默认的边框与轮廓线 */
border:none;
outline:none;
/*重置默认字体与背景色*/
background-color: seagreen;
color: white;
padding: 5px 10px;
/* 文字少,可适当拉开字间距 */
letter-spacing: 1em;
}
/* 鼠标悬停按钮上的效果 */
button:hover {
cursor: pointer;
opacity: 0.8;
transition: 0.4s;
}
/* 4. checkbox实现下拉菜单的效果*/
*原理*
1.将复选框的状态与下拉菜单列表进行绑定
2.根据复选框的状态决定下拉菜单是否显示
*/
/* 初始状态:必须将复选框进行隐藏 */
/* 隐藏复选框 */
#menu {
display: none;
}
/* 隐藏下拉菜单 */
#menu + ul {
display: none;
}
/* 状态伪类:显示下拉菜单 */
#menu:checked + ul {
display: block;
}
示例HTML代码
<form action="">
<fieldset>
<legend>用户注册</legend>
<input type="text" id="username" name="username" placeholder="请输入用户名" autofocus required />
<input type="password" id="password" name="password" placeholder="请输入密码" required />
<input type="email" id="email" name="email" placeholder="请输入邮箱" required />
<div><input type="checkbox" id="rem" name="remember" checked><label for="rem">记住我</label></div>
<button>提交</button>
</fieldset>
</form>
<div class="box">
<!--label.for与input.id绑定-->
<label for="menu">视频教程</label>
<input type="checkbox" name="" id="menu">
<ul>
<li><a href="">前端开发</a></li>
<li><a href="">后端开发</a></li>
<li><a href="">全栈开发</a></li>
</ul>
</div>
Statement of this Website
The copyright of this blog article belongs to the blogger. Please specify the address when reprinting! If there is any infringement or violation of the law, please contact admin@php.cn Report processing!