Issue #1072💬 AnsweredOpened April 25, 2018by andsnake0 reactions

Cannot add a new css rule if an element that is using it is not present in the html

快速解答by artf

Yes, it's a normal behavior, the editor optimizes the exported code, but in the next release you'll find a new keepUnusedStyles option, which allows you to skip this optimization

Read full answer below ↓

Question

HI, i'm using the latest build and i have the issue as described in the title.

I am editing html and css separately. I have noticed that when editing the css, if i try to add a new class, not used by any of the elements in the canvas yet, after saving, that css class is removed,

if instead i go and create a dummy div, assign i.e class ="test", and then go and add the .test{color="red"} rule to the css, the css change is retained correctly.

here is a JS Fiddle you can play with to see the behaviour. https://jsfiddle.net/d64sc5g4/

is this normal behaviour or a bug?

Answers (2)

artfApril 29, 2018

Yes, it's a normal behavior, the editor optimizes the exported code, but in the next release you'll find a new keepUnusedStyles option, which allows you to skip this optimization

lock[bot]September 17, 2019

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

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.