Image size in Editor in % not in px size

1 Answer 113 Views
Editor
Egbert
Top achievements
Rank 1
Iron
Egbert asked on 23 Feb 2022, 06:39 AM

Hi,

When adding a large image (>1000px width) in the Editor, it looks fine on a laptop/tablet.

But when showing it on a mobile, it doesn't.

Is it possible to enter the image size in % so it auto rescales depending on the screen size?
Or is there another way to solve this problem?

Thanks...

1 Answer, 1 is accepted

Sort by
0
Stoyan
Telerik team
answered on 25 Feb 2022, 04:27 PM

Hello Egbert,

When you add an image to the Editor it's wrapped in an img Html element. You can use the available Stylesheets configuration to set up different sizes of the img element for different screen sizes.

.StyleSheets(css => css
                    .Add(Url.Content("~/shared/web/editor/editorStyles.css"))
                  )
I hope this information helps in the scenario at hand.

Regards,
Stoyan
Progress Telerik

Love the Telerik and Kendo UI products and believe more people should try them? Invite a fellow developer to become a Progress customer and each of you can get a $50 Amazon gift voucher.

Egbert
Top achievements
Rank 1
Iron
commented on 03 Mar 2022, 04:10 PM

Hi,

I've never used this before, so hopefully you can help me a little bit further than this.

I would like to add the following style for an image to the editor:

img {
  max-width: 80%;
  height: auto;
}

How should the complete editorStyles.css file look like and do I only need to use the .StyleSheets(.....) line in my current html file to implement this style?

Thanks and best regards,
Egbert

Alexander
Telerik team
commented on 08 Mar 2022, 01:04 PM

Hi Egbert,

In general, the Editor component renders its content inside an iframe by design. Having this in mind, the content inside the iframe is isolated from the main page, thus any styling that you apply to the main page will not intervene with what is in the iframe content.

In this regard, there are no restrictions as to what rules need to be applied or not, when it comes to configuring the stylesheet file for the iframe content.

Finally, for your convenience, I am also attaching a runnable sample for you to review that illustrates how the stylesheets configuration option can be utilized within the content area of the Editor with the previously provided style rules. Notice that the custom stylesheet is allocated within the ~/wwwroot/css folder

Additionally, you can review the following resources that you might find useful as well:

Tags
Editor
Asked by
Egbert
Top achievements
Rank 1
Iron
Answers by
Stoyan
Telerik team
Share this question
or