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.

Question: Responsive images on edit mode

See original GitHub issue

My img elements have styles img.img-responsive { display: block; max-width: 100%; height: auto; } When I’m on edit mode, img elements are changed to div, and they are given background-image property. They are not displayed auto sizing… I hope that div contain origin img which set invisible (no doing none display) at least. Or is there another way? recommend please.

Issue Analytics

  • State:open
  • Created 6 years ago
  • Comments:11 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
darksnake747commented, Jan 13, 2018

First, to start, I want to point out that ContentTools states that the editor does not work well on mobile devices. More importantly, at least from my observations, it doesn’t have native support for responsive displays. Nor does it have native support for Bootstrap, which I am assuming you are using based on that class name. That said, you can achieve this on your own; in fact, it is how I use it. I don’t have mobile support for the edit mode completely perfect, but that is an issue of screen real estate and not something I care to fix.

Because of all that, when the content switches to edit mode and your img tags become divs, the Bootstrap CSS no longer applies - that is really why the responsive images aren’t working. You should be able to add some CSS to the editor pages that appies the Bootstrap CSS from img.img-responsive, which is: { display: block; max-width: 100%; height: auto; } to the divs. Try this:

.ce-element--type-image.img-responsive { display: block; max-width: 100%; height: auto; }

You could be having another problem though. Does the div in edit mode have the img-responsive class on it? If not, the easiest way to handle that will be to add a supported style for it, like this:

ContentTools.StylePalette.add([
    new ContentTools.Style('Responsive', 'img-responsive', ['img']),
]);

Personally, I inject that class on my images when they get inserted. That’s done like this:

dialog.addEventListener('imageuploader.save', function () {
    // ... do stuff here ...
    dialog.save(image.url, [width, height], {
        'class': 'img-responsive',
        //... other image settings ...
    });
});

Moving forward, if these things happen, just keep in mind that by wanting to use the ContentTools editor with Bootstrap and a responsive display, you will have to manually add support for it like this.

I hope this helps you. Let us know if you get the problem resolved.

1reaction
ghostcommented, Jun 6, 2018

No problem 😃 This plugin is still an excellent plugin and I thank you for giving it to us !

That’s why I criticize some part of it, I’m french and we have a proverb that says :

Qui aime bien chatie bien

Which could be translated like that :

Who loves well chatises as well

That’s what I’m doing with your plugin 😃

Read more comments on GitHub >

github_iconTop Results From Across the Web

Responsive images - Learn web development | MDN
Resolution switching: The problem whereby you want to serve smaller image files to narrow-screen devices, as they don't need huge images like ...
Read more >
A Guide to the Responsive Images Syntax in HTML - CSS-Tricks
This guide is about the HTML syntax for responsive images (and a little bit of CSS for good measure). We'll go over srcset...
Read more >
Responsive images: How they work – and how to use them ...
The goal is to have a component, where a developer (or editor!) picks a configuration (preset) from a drop-down, for instance “Art Direction ......
Read more >
How to make Images Responsive with Examples - BrowserStack
Here's how to create responsive background images with CSS: Use the background-size property to encompass the viewport. Give this property a ...
Read more >
glass mapper - How can I make responsive images editable?
There are a couple good ways to do this. Provide a different interface when the page is in edit mode. Image with retina/non-retina...
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