question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

BUG: When we resize an image with a class 'xyz', all the elements on the page with same class also gets resized because editor adds css to those classes.

See original GitHub issue

GrapesJS version

  • I confirm to use the latest version of GrapesJS

What browser are you using?

Version 104.0.5112.101 (Official Build) (arm64)

Video demo link

https://d.pr/i/27EgH2

Describe the bug

  • When we resize an image with a class ‘xyz’, all the elements on the page with the same class also get resized because the editor adds height width CSS to those classes.
  • But when I remove all the classes from the image, the editor uses the id to set height width CSS.
  • I am loading a bootstrap template in the editor. Recording link: https://d.pr/i/27EgH2

Steps to reproduce:

  • Load bootstrap template for editing.
  • Add multiple divs with shadow class ex.(<div class='shadow'></div>)
  • Place an image in one of the div which has shadow class and then try to resize the image.
  • Notice all the divs moving/resized along with the image.
  • Expected behavior only image should be resized.
  • Using grapesjs-parser-postcss as well and added it in initialization code.
  • Passing the CSS & javascript URLs using canvas option.

init method:

grapesjs.init({
            container: "#gjs",
             .....,
            canvas: {
                scripts: scriptUrls,
                styles: styleUrls,
            },
            parser: {
                parserPostCSS,
            },
        });

Code of Conduct

  • I agree to follow this project’s Code of Conduct

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

3reactions
DevMetwalycommented, Aug 25, 2022

https://grapesjs.com/docs/modules/Components.html#components-css

Component-first styling By default, when you select a component in the canvas and apply styles on it, changes will be applied on its existent classes. This will result on changing of all the components with those applied classes. If you need the style to be applied only on the specific selected component you have to select componentFirst strategy in this way.

grapesjs.init({
 ...
 selectorManager: {
   componentFirst: true,
 },
})
1reaction
FaisalShaikhHAcommented, Aug 25, 2022

Thanks, @DevMetwaly it worked, my bad I missed this.

Read more comments on GitHub >

github_iconTop Results From Across the Web

resize - CSS: Cascading Style Sheets - MDN Web Docs - Mozilla
The resize CSS property sets whether an element is resizable, and if so, in which directions.
Read more >
CSS force image resize and keep aspect ratio - Stack Overflow
I 've tried the max-width/max-height as numbers with width/height as auto, but as setec said above, it will not enlarge the image. I've...
Read more >
How to Resize Images Using CSS for Responsive Web Design
Ensure that your images stay sharp and pixel-perfect on every screen size by resizing them with CSS, or intuitively on Editor X.
Read more >
Resize image proportionally with CSS - GeeksforGeeks
The resize image property is used in responsive web where image is resizing automatically to fit the div container.
Read more >
How to resize an image in HTML? - ImageKit.io
One of the simplest ways to resize an image in the HTML is using the height and width attributes on the img tag....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found