Issue #896✓ SolvedOpened February 23, 2018by maxtacco4 reactions

Media query rules are overridden by class rules in canvas

快速解答by vrudikov2

@artf Created the PR

Read full answer below ↓

Question

Hi @artf , I've noticed an issue while testing one of my templates using different device configurations that supposed to trigger media queries. My template has styles generated as following:

[  
   {  
      "selectors":[  
         {  
            "name":"row",
            "label":"row",
            "type":1,
            "active":true,
            "private":false,
            "protected":false
         }
      ],
      "selectorsAdd":"",
      "style":{  
         "display":"table",
         "padding-top":"10px",
         "padding-right":"10px",
         "padding-bottom":"10px",
         "padding-left":"10px",
         "width":"100%"
      },
      "mediaText":"",
      "state":"",
      "stylable":true,
      "atRuleType":"",
      "singleAtRule":0,
      "important":0
   },
   {  
      "selectors":[  
         {  
            "name":"cell",
            "label":"cell",
            "type":1,
            "active":true,
            "private":false,
            "protected":false
         }
      ],
      "selectorsAdd":"",
      "style":{  
         "width":"100%",
         "display":"block"
      },
      "mediaText":"(max-width: 768px)",
      "state":"",
      "stylable":true,
      "atRuleType":"media",
      "singleAtRule":0,
      "important":0
   },
   {  
      "selectors":[  
         {  
            "name":"cell30",
            "label":"cell30",
            "type":1,
            "active":true,
            "private":false,
            "protected":false
         }
      ],
      "selectorsAdd":"",
      "style":{  
         "width":"100%",
         "display":"block"
      },
      "mediaText":"(max-width: 768px)",
      "state":"",
      "stylable":true,
      "atRuleType":"media",
      "singleAtRule":0,
      "important":0
   },
   {  
      "selectors":[  
         {  
            "name":"cell70",
            "label":"cell70",
            "type":1,
            "active":true,
            "private":false,
            "protected":false
         }
      ],
      "selectorsAdd":"",
      "style":{  
         "width":"100%",
         "display":"block"
      },
      "mediaText":"(max-width: 768px)",
      "state":"",
      "stylable":true,
      "atRuleType":"media",
      "singleAtRule":0,
      "important":0
   },
   {  
      "selectors":[  
         {  
            "name":"cell",
            "label":"cell",
            "type":1,
            "active":true,
            "private":false,
            "protected":false
         }
      ],
      "selectorsAdd":"",
      "style":{  
         "width":"8%",
         "display":"table-cell",
         "height":"75px"
      },
      "mediaText":"",
      "state":"",
      "stylable":true,
      "atRuleType":"",
      "singleAtRule":0,
      "important":0
   }
]

It looks like this JSON is used to generate styles inside canvas as in this screenshot:

screen shot 2018-02-23 at 2 06 57 pm

You can see here that the '.cell' style is added last and it overrides the corresponding media query style from above and as a result it is impossible to test responsive components.

So, It would be really nice if media query styles where included after their corresponding 'normal' styles to guarantee they are taken into consideration when using device configurations.

Also, it looks like the Code viewer generates CSS correctly as in this screenshot below: screen shot 2018-02-23 at 2 07 43 pm

Thank you.

Answers (3)

👍 Most helpfulvrudikovMarch 29, 2018

@artf Created the PR

artfMarch 8, 2018

Thanks for the catch guys and the great video @vrudikov, was really helpful. I'll investigate this

vrudikovMarch 19, 2018

So now we have the following structure:

<div class="gjs-css-rules">
  <style>...</style>
  <style>...</style>
  <style>...</style>
  <style>...</style>
</div>

And you want something like this:

<div class="gjs-css-rules">
  <div id="common-styles"> 
    <style>...</style>
    <style>...</style>
    <style>...</style>
  </div>
  <div id="media-1000-styles"> 
    <style>...</style>
    <style>...</style>
    <style>...</style>
  </div>
  <div id="media-700-styles"> 
    <style>...</style>
    <style>...</style>
    <style>...</style>
  </div>
  <div id="media-400-styles"> 
    <style>...</style>
    <style>...</style>
    <style>...</style>
  </div>
</div>

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.