css - Less 是否具有缩短输入类型选择器的功能?

标签 css less

我写了这个css:

.form-group > input[type="text"],
.form-group > input[type="text"]:hover,
.form-group > input[type="text"]:active,
.form-group > input[type="password"],
.form-group > input[type="password"]:hover,
.form-group > input[type="password"]:active,
.form-group > input[type="email"],
.form-group > input[type="email"]:hover,
.form-group > input[type="email"]:active {
    max-width: 400px;
}

我知道我可以通过写作来缩短它

.form-group > input[type="text"],
.form-group > input[type="password"],
.form-group > input[type="email"] {
    max-width: 400px;
    &:hover,
    &:active {
    }
}

嗯,第二个代码部分是我真正写的,第一个只是为了问题的戏剧性,我猜;)

现在我想知道是否有允许对输入类型选择器进行分组的功能,如下所示:

.form-group > input {
        $:text,password,email
    max-width: 400px;
    &:hover,
    &:active {
    }
}

最佳答案

您可以像常规 CSS 一样使用 less:

.form-group > input {
  &[type="text"], &[type="password"], &[type="email"] {
     &:hover, &:active {
       max-width: 400px;
     }
  }
}

& 符号 (&) 引用 input 元素,您只需为 type 属性添加规则

关于css - Less 是否具有缩短输入类型选择器的功能?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21648113/

相关文章:

html - 可滚动表格,使用 CSS、Joomla 锁定第一列

html - 使用 Z-Index 的 Div 堆叠

css - 背景图片不会出现在我正在处理的 Rails 应用程序中

javascript - 根据href目标设置<p><a>...</a></p>的规则集

css - 如果与 LESS 一起使用,@import 真的那么糟糕吗?

html - 带有 float 图像的段落、列表、 block 引用

css - 使用 LESS CSS 在父元素中选择元素

css - 在 Less 中组合多个 "transform"条目

Flask-Assets 根本不工作... = 精神错乱

html - 安装 React Bootstrap 后如何去除边距