css - LESS选择器: how to apply styling only for one of the elements from inside mixin?

标签 css less mixins

我有一个无法更改的代码:

item.left,
item.centre,
item.right{
.MIXIN();
}

.MIXIN(){
width: 100px;
}

我只需将宽度应用于 .right 元素。我只能更改 MIXIN() 的内容。我正在考虑使用 & 但它会导致 .right item.rightitem.right .right 这不是我想要的。有没有办法使用 MIXIN() 的内容仅对 .right 元素应用样式?

最佳答案

您可以使用否定CSS伪类:not() .

item.left,
item.centre,
item.right{
  width: 20px; 

  &:not(.left):not(.centre) {
    width: 100px;
  }
}

fiddle :https://jsfiddle.net/e0nd7pk4

关于css - LESS选择器: how to apply styling only for one of the elements from inside mixin?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43002919/

相关文章:

javascript - 可在彩色背景上放置

javascript - 更改 Bootstrap 的默认模态类

html - 使用外部文件 W3.css 中的类创建 LESS mixin

html - 如何创建水平元素列表?

javascript - 带渲染器的 Angular 2+ CSS 自定义属性(变量)

html - 使立方体尺寸变小

html - 如何在保持响应能力的同时避免 float 图像旁边段落的文本中断?

html - CSS 网格的复杂混合

Javascript 混入

css - 如何让 flex div 只占用需要的空间?