Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
377 views
in Technique[技术] by (71.8m points)

javascript - Vanilla Javascript是否可以嵌套CSS选择器?(Is nesting CSS selectors possible with Vanilla Javascript?)

Nesting CSS is a very awesome feature in the CSS-PreProcessors like LESS, SASS, Stylus etc. But SASS has Ruby as dependecy while LESS & Stylus require Node.

(嵌套CSS是CSS预处理器(如LESS,SASS,Stylus等)中一个非常棒的功能。但是SASS具有Ruby作为依赖项,而LESS和Stylus需要Node。)

Due to some restrictions I can neither use Node nor Ruby or any javascript library.

(由于某些限制,我无法使用Node或Ruby或任何javascript库。)

But I require the nesting feature greatly so that I can save my time, but I can't have dependencies.

(但是我非常需要嵌套功能,这样我可以节省时间,但不能有依赖关系。)

I was thinking if Vanilla Javascript can do my work.

(我在想香草Javascript是否可以完成我的工作。)

I assume something like this :

(我假设是这样的:)

Input :

(输入:)

 body {
     h1 {
        color: blue;
        &:hover {
            color: red;
        }
  }

Output :

(输出:)

 body h1 {
    color: blue;
 }
 body h1:hover {
    color: red;
 }

So, is this possible to achieve with Vanilla Javascript ?

(那么,这可以通过Vanilla Javascript实现吗?)

( No problem with ES6 or ES6+ ) If yes please teach me how.

((ES6或ES6 +没问题)如果是,请教我如何操作。)

If no than what can I do ?

(如果没有,我该怎么办?)

  ask by Arcanadian Arc translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...