Issue #404✓ SolvedOpened October 11, 2017by thecodefish9 reactions

Changing CSS properties on a component with an existing class modifies that class instead of adding a new one

Quick answerby thecodefish5

I was thinking that the behaviour could be something like this: Default (current setup):If element has no classes, create unique class based on cid and apply stylesIf element has classes, apply styles to the union of those classes (or whatever classes are selected in the UI) Toggled behaviourTest if element has an exi...

Read full answer below ↓

Question

You can see this in action on the demo (http://grapesjs.com/demo.html). Select one of the nav items ('Web' for example) - note that it has an existing class of menu-item. If you now change some of the properties, such as text alignment, it applies those changes to the menu-item class, which affects the other instances ('Template', 'Builder'). Is it possible to force GrapesJS to apply a new 'unique' class and apply the changes there - similar to how it works if you make changes to a component with no existing classes (c1234 for example)? Ultimately I want any Style changes to only apply to the...

Answers (3)

👍 Most helpfulthecodefishOctober 11, 2017

I was thinking that the behaviour could be something like this: Default (current setup):If element has no classes, create unique class based on cid and apply stylesIf element has classes, apply styles to the union of those classes (or whatever classes are selected in the UI) Toggled behaviourTest i...

artfNovember 17, 2017

Hi @thecodefish what do you think about this approach? https://codepen.io/artf/pen/jaaKvq You will see there how to make selectors private (not stylable by the user) and the usage of the new avoidInlineStyle option which allows you to style components (not class selectors) without losing the respon...

artfOctober 11, 2017

I'd say you have 2 options:

  1. Just deselect the class, in this case, the style manager scope will change to the component and not the rule
  2. Add a new class to the component, instead of .menu-item rule you will get .menu-item.your-new-class

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.