Best way to load element's css into the properties panel.
Question
Hi Again everyone,
GrapeJS is too much fun once you get deep into it. I have a simple question:
What's the best way to load the css from a newly created element to the properties panel.
For example I have the following box which has a black background:

The black background comes from the style in the element
...
content: `
<div class="col-8" style="background-color: rgba(0,0,0,0.70); padding:40px;"
...
The editor converts the style tag into a class as shown here:

yet the properties panel does not have a background set:

Now I change the color to dark orange:

it will create a new class for it that will overwrite the previous one:

Thank you in advanced for any thoughts!
Answers (3)
@artf I undertand now

I completely missed the checkbox next to each selector. Setting the forceClass to false solves all my problems! I dont really need that as I'm keeping the source code extremely lean with as little divs as possible. Thank you very much for that!
Dan
I discovered that if the div has no class and just style then a single class is created and the background is applied to the properties panel:


so that would be a partial solution for now but still looking for a better alternative.
Hi @daniel-farina you don't see .c1019's background because your component has two classes so, by default, the Style Manager select the CSS rule where the selector is a combination of all its classes, in your case .col-8.c1019. If you want to see .c1019's styles you can just deselect .col-8

You can also avoid automatic class generation if you want
grapesjs.init({
...
forceClass: false
})
Related Questions and Answers
Continue research with similar issue discussions.
Issue #1787
[Question] Change HTML of Panel buttons from span to button
I have created some Panels and would like to change the element of panel buttons from span to button as its more appropriate and looks bett...
Issue #890
[Question]: I cannot get the simple example working
I am not new to Javascript but when I try the example: I get a blank page. That is with adding the CSS and Javascript library. Any suggesti...
Issue #1608
[Question] Customize CSS class name
GrapesJs editor creates a unique class for element and adds CSS rules to it. For example, Now, is there any way to customize this behaviour...
Issue #1588
[QUESTION]
Hi guys and thank you for your magnificent work and this API! I have a question about the box, which wraps all components after saving. For...
Paid Plugins That Match This Issue
Curated by issue keywords and label relevance to help you ship faster.
Loading paid plugin recommendations...
Browse Plugin Categories
Jump directly to plugin category pages on the marketplace.