Issue #1694💬 AnsweredOpened December 30, 2018by froderf0 reactions

CSS composer not working on two classes

快速解答by artf

This is not how setClassRule is supposed to work. The first argument is only for 1 class name. Currently, there is no specific API method for your case, probably the best one, for now, is editor.CssComposer.getAll().add('.class1 .class2{...}')

Read full answer below ↓

Question

//returnedCssObject is an object that contains css styles
cssComposer.setClassRule("class1 class2", returnedCssObject);

above code is not working but the below is working

//returnedCssObject is an object that contains css styles
cssComposer.setClassRule("class1", returnedCssObject);

All i need is to apply the css rule in two class .class1 .class2{ ... color: red; ... }

Answers (3)

artfJanuary 4, 2019

This is not how setClassRule is supposed to work. The first argument is only for 1 class name. Currently, there is no specific API method for your case, probably the best one, for now, is editor.CssComposer.getAll().add('.class1 .class2{...}')

mailtopaul8January 8, 2019

I need to have a new CSS rule with the combination of both ID & class but currently there is no way to do that (tried using setIdRule by adding .class after ID but didn't worked). Can you add a method like setRule which would simply accepts a whole selector with ID & class combination?

artfJanuary 14, 2019

@mailtopaul8 I'll try to bring it in the next release

Related Questions and Answers

Continue research with similar issue discussions.

Paid Plugins That Match This Issue

Curated by issue keywords and label relevance to help you ship faster.

View all plugins

Loading paid plugin recommendations...

Free option

Check the open-source GrapesJS plugins on GitHub or run a quick search in our free catalog.

Browse free plugins →
Premium option

Premium plugins ship with support, regular updates, and production-ready features — save days of integration work.

Browse premium plugins →

Related tutorials

In-depth guides on the same topic.

All tutorials →

Browse Plugin Categories

Jump directly to plugin category pages on the marketplace.