Issue with getting Images to Resize in my Blazor Application with Azure Web App

Andrew Sabin 80 Reputation points
2026-08-16T04:49:56.1833333+00:00

Hello Again Microsoft Azure Support,

Thank you again for your help with my URL question I had earlier.

Recently I have been having issues with getting images to resize after they reach the @media(max-width 768px) part of my CSS file.

Specifically, whenever I want the program to read in a MarkupString for an HTML string created by a WYSIWYG/Rich Text Editor, it refuses to change the width and height of an image being read in once the screen width reaches 768px. In the case of both razor pages that this applies to, the display is set to display: grid;

The MarkUpString is used as such:

<div class="content-description-container">
				@((MarkupString)contentRevision.Value.Description)
</div>

In the case of one of my pages, I have it change from a specific grid pattern to having all the items listed top to bottom, where my CSS file has the following for the column that contains my MarkupString value for in the case of @media(max-width 768px) :

.content-review-column {
    order: 4;
    width: 100%;
    padding: 0.5rem;
    box-sizing: border-box;
    justify-content: center;
}
.content-review-column ::deep img {
    display: block;
    max-width: 100% !important;
    width: auto;
    height: auto !important;
    object-fit: contain;
    margin: 0.5rem 0;
}
.content-description-container {
    width: 100%;
    padding: 0.5rem;
    box-sizing: border-box;
}
.content-description-container ::deep img {
    display: block;
    max-width: 100% !important;
    width: auto;
    height: auto !important;
    object-fit: contain;
    margin: 0.5rem 0;
}

And for the other page that uses MarkupString, I keep everything I have just (for @media(max-width 768px) ):

.article-body-col ::deep img {
    display: block;
    max-width: 100% !important;
    width: auto;
    height: auto !important;
    object-fit: contain;
}

I'm trying to give as much details as I can, but to summarize, images do not shrink when the width reaches 768px or below when deployed on Azure Web App but do so in development.

If you need any further information, please let me know, I would be happy to provide it.

Thank you very much for your help and time,
Andrew Sabin

Azure Static Web Apps
Azure Static Web Apps

An Azure service that provides streamlined full-stack web app development.


Answer accepted by question author
Golla Venkata Pavani 7,440 Reputation points Microsoft External Staff Moderator
2026-08-16T11:33:27.51+00:00

Hi @Andrew Sabin

Thank you for reaching us regarding the issue.

Looking at the tag you provided

<img src="..." class="e-rte-image" ... width="517" height="292"

 style="min-width: 0px; max-width: 900px; min-height: 0px; width: 517px; height: 292px;">  

The combination of the width/height attributes and the inline style is what is preventing the media-query rules from taking effect in production. Inline styles have higher specificity than stylesheet rules, so they win even when you use ::deep and !important. Because the content arrives as a MarkupString, Blazor does not automatically attach the isolation scope attribute to the injected elements. That is why the ::deep rules are required, but they still cannot override an inline style attribute unless the conflicting declarations are removed or the CSS is made strong enough.

Recommended next steps:
1. Strengthen the CSS to target the editor classes

@media (max-width: 768px) {
    .content-description-container ::deep img.e-rte-image,
    .content-description-container ::deep img.e-img-inline,
    .content-review-column ::deep img.e-rte-image,
    .article-body-col ::deep img.e-rte-image {
        display: block !important;
        max-width: 100% !important;
        width: auto !important;
        height: auto !important;
        min-width: 0 !important;
        max-width: 100% !important;   /* overrides the editor’s 900px */
        object-fit: contain !important;
    }
}

2. Sanitize the markup before rendering (most reliable)

Remove the width/height attributes and the width/height-related declarations from the style attribute. This lets the CSS control sizing cleanly, which is the approach recommended when working with untrusted or third-party HTML content.

private string SanitizeImageMarkup(string html)
{
    if (string.IsNullOrWhiteSpace(html)) return html;
    // Remove width and height attributes
    html = System.Text.RegularExpressions.Regex.Replace(
        html,
        @"\s*(width|height)\s*=\s*[""'][^""']*[""']",
        "",
        System.Text.RegularExpressions.RegexOptions.IgnoreCase);
    // Strip width/height (and min/max variants) from the style attribute
    html = System.Text.RegularExpressions.Regex.Replace(
        html,
        @"(style\s*=\s*[""'])([^""']*)([""'])",
        m => {
            var cleaned = System.Text.RegularExpressions.Regex.Replace(
                m.Groups[2].Value,
                @"(^|;)\s*(width|height|min-width|max-width|min-height|max-height)\s*:[^;]*",
                "",
                System.Text.RegularExpressions.RegexOptions.IgnoreCase);
            return m.Groups[1].Value + cleaned.Trim(';', ' ') + m.Groups[3].Value;
        },
        System.Text.RegularExpressions.RegexOptions.IgnoreCase);
    return html;
}

Then render with:

SQL

@((MarkupString)SanitizeImageMarkup(contentRevision.Value.Description))

After deploying either change, do a hard refresh on the Azure site and inspect an image in DevTools (Computed tab). You should see max-width: 100% and width: auto coming from your media query.

Reference: https://learn.microsoft.com/en-us/aspnet/core/blazor/components/css-isolation?view=aspnetcore-10.0 https://learn.microsoft.com/en-us/aspnet/core/blazor/components/?view=aspnetcore-10.0#raw-html

If the answer is helpful,  Please do click "accept” and Yes, this can be beneficial to other community members.

If you have any other questions, let me know in the "comments" and I would be happy to help you

Was this answer helpful?

1 person found this answer helpful.

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.