html - 如何通过css选择所有输入元素?
问题描述
下面的 css 代码是重复的,是否有任何 css 快捷方式,所以我们可以在单行代码中选择所有输入字段。
.form-group input[type='text'],
.form-group input[type='email'],
.form-group input[type='password'],
.form-group input[type='tel']
{
margin:10px;
}
解决方案
假设您的 HTML 结构如下所示:
<div class="form-group"> // or any other kind of wrapper element with a class of "form-group"
<input type="text">
<input type="email">
<input type="pasword">
<input type="tel">
</div>
您可以将当前的 css 替换为以下内容:
.form-group input { margin:10px; }
无论输入类型如何,边距都将应用于<input>
嵌套在元素内的所有元素。.form-group
检查并运行以下代码片段以获取上述代码的实际示例:
.form-group input { margin:10px; }
<div class="form-group">
<input type="text">
<input type="email">
<input type="pasword">
<input type="tel">
</div>
推荐阅读
- python - TextRazor 自定义词典 - AttributeError
- mysql - 从一个巨大的表中检索所有行
- android - 安卓| Java 通知未出现在 API 25 及更低版本中
- python - 如何使用 Tweepy 从用户的时间线实时获取推文
- xml - 如何在 YANG 中建模没有公共子元素的列表?
- git - .gitignore 文件不忽略 VS 文件
- python - 为python中数据框列表中的单个数据框赋值
- android - 如何在打开活动之前获取 api 结果(等待屏幕)
- pytorch - 无法使用两个 csv 输入文件为循环 gans 创建 Dataloader
- laravel - 如何与许多用户一起托管 Angular 前端和 Laravel 后端信使机器人