对 SCSS (Sass) Mixins 进行分组
将一些CSS转换为Sass,例如:
.ptn,
.pvn,
.pan{padding-top:0px !important}
对此
@mixin ptn {padding-top:0px !important}
@mixin pvn {padding-top:0px !important}
@mixin pan {padding-top:0px !important}
但希望我可以做更多类似这样的
@mixin ptn,
@mixin pvn,
@mixin pan {padding-top:0px !important}
事情是可能的吗?
谢谢!
converting some CSS to Sass, for example:
.ptn,
.pvn,
.pan{padding-top:0px !important}
to this
@mixin ptn {padding-top:0px !important}
@mixin pvn {padding-top:0px !important}
@mixin pan {padding-top:0px !important}
but wishing i could do something more like this
@mixin ptn,
@mixin pvn,
@mixin pan {padding-top:0px !important}
is something along these lines possible?
thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
怎么样
?
Sass 注重可重用性,因此请尝试将代码分解为新的代码,以保持代码干混合。
另外你可以写这样的东西:
How about
?
Sass is about Reusability, so try to keep the code DRY by breaking this up into a new mixin.
Additionally you could write something like this:
或者,您可以根据您的目的使用
@extend
功能来变得更简洁。因此,如果您有:
您可以在代码中的任何其他位置执行此操作(它不需要像 mixins 那样出于范围界定目的而执行此操作):
这将输出如下:
这可以是比使用 mixins 更干净的输出,后者会重复代码。这对于较大的代码块特别有用,例如明确的修复。但 mixin 确实有一席之地。
说到各有其位置……
!important
真的有必要吗? ;-)Alternatively you can use the
@extend
feature to be a little cleaner, depending on your purposes.So if you have:
You can do this anywhere else in your code (it doesn't require it to go after for scoping purposes, like mixins do):
This will output as such:
This can be a cleaner output than using mixins, which would duplicate the code. This is particularly useful for larger blocks of code, like clear fixes. But mixins do have their place.
Speaking of things having their place… is that
!important
really necessary? ;-)