grapesjs icon indicating copy to clipboard operation
grapesjs copied to clipboard

Problem with element positioning in a multi-column layout

Open theSC0RP opened this issue 6 years ago • 5 comments

How to control the position of the elements in the cells in columns? On the left side, I have the map element, and on the right, I have a Text and Image. As seen in the screenshot below, the elements on the right are positioned after the map.

Screenshot (175)

A similar problem is there in this codepen (Grapesjs Custom UI by @artf ) too. Screenshot (177)

theSC0RP avatar Oct 21 '20 07:10 theSC0RP

@theSC0RP This is not really a problem with GrapesJS itself. The cell in GrapesJS has

display:table-cell;

property, so it tries to simulate a table layout, as far as I'm aware. So if you want to change the positioning, then find a way to vertically change position in a table.

One solution might be

vertical-align:middle;

See https://developer.mozilla.org/en-US/docs/Web/CSS/vertical-align

So you would either automatically apply this on your custom component or you could create a custom style property for this setting, so that you could easily change it. There might be other ways to align item in a table layout. Alternatively, you can also create your own custom layout component, which can behave as you would like it.

MartinPutz avatar Oct 21 '20 14:10 MartinPutz

@MartinPutz Thank you for the answer. How would I create and apply a custom style property on the cell? I am using the grapesjs-blocks-basic plugin so the cell has a class name of 'gjs-cell'. I tried to add the suggested property on this class in my styles file but the problem is still there.

theSC0RP avatar Oct 22 '20 05:10 theSC0RP

Hi, @artf. A few observations after experimenting on the demo website and comparing the results with my grapesjs-blocks-basic implementation

  1. The 'display' attribute of the row element in the styles panel on the demo page is set to flex by default. That is not the case when I am using the blocks basic library. I am getting the default 'display' attribute as blank
  2. Similarly the 'display' attribute of the cell element is 'block' but it is blank in my implementation.
  3. The class names of row and cell on the demo page are row and cell respectively but in the grapesjs-blocks-basic the class names are 'gjs-row' and 'gjs-cell' respectively.

Are the above things supposed to be that way?

theSC0RP avatar Oct 22 '20 10:10 theSC0RP

You can add this to pluginOpts inside grapesjs.init:

const editor = grapesjs.init({
  // ...
  pluginsOpts: {
    "gjs-blocks-basic": {
       stylePrefix: '', // no gjs- prefix
       flexGrid: 1 // use flexbox instead of tables
     }
  },
  // ...
});

This will probably also fix your previous alignment issues and is much better for responsive design

Ju99ernaut avatar Oct 23 '20 09:10 Ju99ernaut

@Ju99ernaut Thank you so much. That works like a charm and it has solved both the problems.

theSC0RP avatar Oct 23 '20 10:10 theSC0RP