[BUG]: Exported CSS cannot override body's background-color
Question
When a body background style is defined in the style option of the init function it's not possible to override.
Given the style:
body {
background-color: #000000;
}
After changing the background-color in Grapes, the CSS output is:
body {
background-color:#f80000; /* Colour selected in Grapes */
}
body {
background-color:rgb(0, 0, 0); /* Original colour that should be overwritten */
}
Due to the ordering, the original colour will take precedence when used.
While not necessarily an issue, the repetition of body isn't needed and would probably solve this issue if the body css definition was merged. I believe this happens with other CSS selectors too.
Steps to reproduce
- https://jsfiddle.net/jk3g2eu2/
- Click the wrapper in the canvas
- Change background color.
- Click the code icon to see generated CSS.
Answers (2)
Thanks James, we already aware of it #552 but unfortunately not yet provided any fix :/
The main problem is that GrapesJS doesn't handle well body/wrapper styling and so, as a result, we have the body coming from 3 different spots:
- from protectedCss option
- from the wrapper's component style (which usually is the body and so I handle it separately)
- and like in your case, also from another CSSRule (created by
style: 'body{background-color:#000000;}') We need to find a correct way to handle all these cases but I didn't yet find time to look at it, so I'd appreciate any advice/help. I close this and suggest you subscribe to #552 if you want any further updates.
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.
Issue #914
[BUG]: Grapes cannot be reinitiated with new HTML
Calling init() on Grapes after changing HTML fails. This kinda situation happens on one page apps. I think a destory() function to graceful...
Issue #1033
[BUG]: When IDs are used, it's not possible to update or remove a style
Steps to reproducehttps://jsfiddle.net/1cjjr02p/Click the text in editor, change background colour.Export CSS. You'll see both new and orig...
Issue #1425
Properties Validate of elements
@Arif How can we validate the properties for the grapejs element like background color We have given an option for manual background entry...
Issue #1877
[FEATURE REQUEST] Custom styles that add/remove custom classes?
Currently, all the style manager values that you change for an element simply update a <style> tag inline in the HTML. Is it possible to ch...
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.