grapesjs icon indicating copy to clipboard operation
grapesjs copied to clipboard

Media Queries do not apply on a custom block I wrote

Open alikabeer32 opened this issue 7 years ago • 2 comments

I wrote a simple div block like so blockManager.add('simple-div', { label: 'Container', content: '"<!––

––>"', category: 'Basic', attributes: { title: 'Simple Box', class: 'fa fa-square' } });

But it is NOT responsive whatsoever. This is how it is: 1.I set it's width 100% on desktop 2.I switch to tablet and set it's width 50% 3.I switch back to desktop and the width is still 50% There are also no media queries in the CSS (media queries work fine for images)

Am I missing some code that allows it to be responsive?

EDIT

I just realised that that the styling is being done to the element rather than a unique id/class I used the following code to give the element a unique id var comps = editor.DomComponents;

comps.addType('.simple-div', { init: function() { this.set('attributes', { id: randomID() }); }, });

How do I make it so that the styling doesn't go to element but the inline stylesheet

alikabeer32 avatar May 31 '19 16:05 alikabeer32

@alikabeer32 I'm facing the same issue. If you solved this issue. Can you please share the solution here. Thanks

umerrinayat avatar Dec 06 '19 09:12 umerrinayat

@alikabeer32 I'm facing the same issue. If you solved this issue. Can you please share the solution here. Thanks

@umerrinayat I don't remember what I did but try the following:

You need to define the css class and add a unique id to it

    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':'80px 50px',
      height:'auto',
      float: 'left',
    });
    
//adding a unique id

    const privateCls = ['.simple-div'];
    
    editor.on('selector:add', (selector) => {
        if (privateCls.indexOf(selector.getFullName()) >= 0) {
          selector.set({private: 1});
        }
    });

alikabeer32 avatar Dec 06 '19 10:12 alikabeer32