如何在SASS中使用通配符星号CSS选择器? [英] How do I use a wildcard asterisk CSS selector in SASS?

查看:915
本文介绍了如何在SASS中使用通配符星号CSS选择器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在使用SASS时如何使用"*" CSS通配符选择器?例如,如何将以下CSS代码设为SASSy?

How do I use a "*" CSS wildcard selector when using SASS? For instance, how would I make the following CSS code SASSy?

* {
  -webkit-box-sizing: border-box;
     -moz-box-sizing: border-box;
          box-sizing: border-box;
  line-height: 1;
}
*:before,
*:after {
  -webkit-box-sizing: border-box;
     -moz-box-sizing: border-box;
          box-sizing: border-box;
}

到目前为止,谢谢您的回答,但让我澄清一下.我意识到在代码示例中有很多不同的观点.代码示例不是问题.问题仍然存在,如何使用*选择器? SASS解析器在遇到*并说它遇到*时抛出语法错误,但期望使用选择器.我在Mac OSX 10.9.5上使用的是Sass 3.4.19(选择性Steve).

Thank you for the answers so far, but let me clarify. I realize that there are many different perspectives on the code sample. The code sample is not the question. The question remains, how do I use the * selector? The SASS parser throws a syntax error when it encounters the * and says that it encountered *, but expected a selector. I'm using Sass 3.4.19 (Selective Steve) on Mac OSX 10.9.5.

我找到了解决方案.该错误是由*代码块之前的行中包含的文件中缺少;引起的.这就是与他人代码打交道的生活.我将授予@torazaburo答案,因为他是唯一实际解决此问题并让我重新考虑其他可能性的人.

I have found the solution. The error was being cause by a missing ; in a file that was included on the line immediately preceding the * code block. Such is the life of dealing with other people's code. I'm going to award the answer to @torazaburo since he was the only one who actually addressed the question and made me rethink other possibilities.

推荐答案

在这里,SASS可以为您提供帮助.您不需要供应商前缀.只需写

There's little here that SASS can help you with. You do not need vendor prefixes. Just write

*, ::before, ::after {
  box-sizing: border-box;
}

* {
  line-height: 1;
}

*::before还是::before是个人喜好的问题.

Whether to write *::before or ::before is a matter of personal preference.

我必须使用SASS 的心态是说我必须

*::before 

规则为

* { 
  &::before

因为我必须使用嵌套,无论如何,只是因为我可以.其实并不是.您的CSS通常更干净,嵌套更少(或为零). (通常更清晰,根本没有SASS,但这是另一天的话题.)

because I must use nesting, no matter what, just because I can. Actually, not. Your CSS is often much cleaner with less (or zero) nesting. (Often it's clearer with no SASS at all, but that's a topic for another day.)

在使用SASS时如何使用* CSS通配符选择器?

How do I use a * CSS wildcard selector when using SASS?

SASS的*没有什么特别的.这只是另一个选择器.您可以像使用其他选择器一样使用它.

There is nothing special about the * to SASS. It's just another selector. You use it like you use any other selector.

这篇关于如何在SASS中使用通配符星号CSS选择器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆