Issue #2060💬 AnsweredOpened June 1, 2019by alikabeer320 reactions

Custom defined css classes do not work if I use editor.setStyle(css_text);

快速解答by artf

Use the setRule API

Read full answer below ↓

Question

I need to set styles using the data I receive from the database asynchronously. But then the css I composed manually gets removed.

const cssComposer = editor.CssComposer;
var sm = editor.SelectorManager;
var sel1 = sm.add('simple-div');
var rule = cssComposer.add([sel1]);
// Update the style
rule.set('style', {
  width: '100%',
  height:'auto',
  padding:'15px',
  float: 'left',
});

the above class .simple-div doesn't exist If I use setStyle()

Answers (1)

artfJune 13, 2019

Use the setRule API

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.