Issue #2378💬 AnsweredOpened November 5, 2019by varadero0 reactions

Modifying global CSS in style manager

快速解答by artf

we want to remove almost everything from the Style Manager You can change what to show in the Style Manager: https://grapesjs.com/docs/getting-started.html#style-manager and it works based on what is selected in the canvasLet's say we will have "Primary color" and "Secondary color" in these settings - all the HTML ele...

Read full answer below ↓

Question

We want to achieve the following:

  • Mark our block HTML elements with some classes like:
<div class="my-container">
  <h3 class="my-title">Some title</h3>
  <h2>Subheader</h2>
</div>
  • Add some styles that define CSS classes like:
<style>
  .my-container {
    background-color: red;
  }
  .my-title {
    color: green;
  }
  h2 {
    font-size: large;
  }
</style>
  • Using GrapesJS style manager we want to change the above CSS classes so we can have a "Container background color" setting which can change the "background-color" of the ".my-container" rule

Why we want this ? We want to use some kind of "theming" for the page which can be changed by the user - we don't want the user to click on the elements to change their style. And more - we want to remove almost everything from the Style Manager - it is way too complex for the users to change such technical settings - it is not realistic to expect the users to spend time changing shadows, border radius etc. We want to greatly simplify styling for the users. Let's say we will have "Primary color" and "Secondary color" in these settings - all the HTML elements which must have the "primary" color will be marked with ... class="primary-color ... and others will be marked as ... class="secondary-color" ..., the user will go to the "theme" settings and will see "Primary color" and "Secondary color" settings.

Answers (3)

artfNovember 7, 2019

we want to remove almost everything from the Style Manager

You can change what to show in the Style Manager: https://grapesjs.com/docs/getting-started.html#style-manager

and it works based on what is selected in the canvas

Let's say we will have "Primary color" and "Secondary color" in these settings - all the HTML elements which must have the "primary" color will be marked with ... class="primary-color ... and others will be marked as ... class="secondary-color" ..., the user will go to the "theme" settings and will see "Primary color" and "Secondary color" settings.

Ok, if you want to achieve it without selecting components it means it has nothing to do with StyleManager/TraitManager, you have to create your UI (eg. primary and secondary colors could be <input type="color"/> defined by you), init listeners on change and update CSS rules via setRule

amenkApril 18, 2021

This is very interesting! @varadero Did you succeed with this and maybe have some code to share?

varaderoApril 21, 2021

This is very interesting! @varadero Did you succeed with this and maybe have some code to share?

We ended up providing CSS when we initialize grapesjs. The CSS is created elsewhere, not inside grapesjs builder.

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 →

Browse Plugin Categories

Jump directly to plugin category pages on the marketplace.