sass:第一个孩子不工作
我已经很长时间没有使用 SASS 了,想知道 :first-child
或 :last-child
等伪元素是否存在一些问题?
I have not been using SASS for a very long time and wanted to know if there are some issues with pseudo-elements such as :first-child
or :last-child
?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
虽然 @Andre 是正确的,伪元素及其支持存在问题,特别是在较旧的 (IE) 浏览器中,但这种支持一直在改进。
至于你的问题,是否有任何问题,我想说我还没有真正看到任何问题,尽管伪元素的语法可能有点棘手,特别是在第一次解决它时。所以:
它按照人们的预期进行编译:
除了“sass 可以做 css 可以做的一切”这一声明之外,我还没有看到任何关于这方面的文档。一如既往,对于 Haml 和 SASS,缩进就是一切。
While @Andre is correct that there are issues with pseudo elements and their support, especially in older (IE) browsers, that support is improving all the time.
As for your question of, are there any issues, I'd say I've not really seen any, although the syntax for the pseudo-element can be a bit tricky, especially when first sussing it out. So:
which compiles as one would expect:
I haven't seen any documentation on any of this, save for the statement that "sass can do everything that css can do." As always, with Haml and SASS the indentation is everything.
我认为(根据我的经验)最好使用:
:first-of-type
,:nth-of-type()
,:last-类型
。只需稍微改变一下规则就可以完成,但我能做的不仅仅是*-of-type
和*-child
选择器。I think that it is better (for my expirience) to use:
:first-of-type
,:nth-of-type()
,:last-of-type
. It can be done whit a little changing of rules, but I was able to do much more than whit*-of-type
, than*-child
selectors.这就是我通常在 中编写伪元素
:first-child
、:last-child
和:nth-child(n)
的方式>萨斯This is how I usually write pseudo-elements
:first-child
,:last-child
and:nth-child(n)
in sass首先,仍然有浏览器不支持这些伪元素(即:first-child,:last-child),因此您必须“处理”这个问题。
有一个很好的例子,如何在不使用伪元素的情况下实现这一点:
我希望这是有用的。
First of all, there are still browsers out there that don't support those pseudo-elements (ie. :first-child, :last-child), so you have to 'deal' with this issue.
There is a good example how to make that work without using pseudo-elements:
I hope that was useful.