An Azure service that provides streamlined full-stack web app development.
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