Can't reset CSS code which has parent or child.
Question
Tested on both npm and cdn GJS Version - 0.14.20 (latest) OS - Mac Browser - Chrome
Problem
If CSS class name has a parent or child like #parent .child{ color: red }, user can't reset the style to origin, it still remain inside CodeViewer.
Codepen Demo 1 - Adding CSS from block
Codepen Demo 2 - Adding CSS inside #gjs <div>
In demo1, Let's say user drag "Test Block" into the canvas and remove it. CSS style will still remains inside the CodeViewer. Even user clear the canvas, it will not be removed.
I am not sure this is a bug or not. But in most case, we used to declare CSS selectors including parents not for ruining the other sections' styles.
Answers (3)
To remove the CSS codes that belong to a specific block.
Indeed that block of CSS doesn't belong to any component (I'm talking about how the editor works) so that declaration is always rendered. GrapesJS can associate only class-based selectors, eg.
.class1 {...}
.class1.class2 {...}
.class1.class2, .class3 {...}
not even nested like .class1 .class2, in that case the rule is imported correctly but do not belong to any component
This is because you're just clearing components. You can use the built-in command core:canvas-clear
@artf Thanks for your quick reply.
Sorry for my unclear question.
What I actually want to achieve is
- To remove the CSS codes that belong to a specific block. For example, when I delete a block in the canvas, the CSS codes of that block will also be deleted. I don't want to clear the entire canvas.
Probably, it will fire on destroy.
editor.Commands.add ('tlb-delete', e => {
// remove the CSS from this block
})
In this case, I can remove the CSS code that has no parent by deleting the components but if the CSS codes have a parent or a child, it does not work.
And here is a video I've tested.

According to my components, I added <style> tags inside the block's content, If there is a better option to work with styles, please guide me.
Thanks in advance.
Related Questions and Answers
Continue research with similar issue discussions.
Issue #1505
adding row and sections not working
i am integrating grapejs with angular6. but it is not working means it is not showing on blocks i am using following code
Issue #519
No Blocks by default
Using this code I get an editor but there are no blocks. I also do not get the icons for the screen size but other icons are there. As you...
Issue #615
Apply style to child classes
How we can add style to child classes of editorform? var forminputClass = cssComposer.add([editorform, forminput]); Above code will apply c...
Issue #859
[QUESTIONS] Change canvas style
Hi there, I have some question about canvas style, in this case i have config like this. By default i use css with name builder-desktop.css...
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.