Article Image Width: CSS Edit
Posted
#2735
(In Topic #536)
Well there is an easy fix.
Down the bottom of your Global.css add the following:
Code
[itemprop="articleBody"] img {
max-width: 100%
}
Last edit: by Paul Flavel
Posted
Code (CSS)
[itemprop="articleBody"] img:not([width]):not([height]) {
max-width: 100%;
height: auto;
}
max-width: 100%;
height: auto;
}
max-width on images can be pretty hairy, as all the following "overly wide image" situations can occur:
- Image with width set but not height – your code would have worked, height would auto-adjust, best to not apply the rule in this case as a specific size was likely intended
- Image with neither height nor width set – your code would have worked, height would auto-adjust
- Image with height set but not width – the image would have got distorted, best to not apply the rule in this case (hence the nots)
- Image with both width and height set – the image would have got distorted, best to not apply the rule in this case as a specific size was likely intended.
I don't think the "height: auto" is needed but I like to include it for completeness/being-explicit.
If you want to force override of any width/height specified (i.e. a different handling of situation 1/3/4):
Code (CSS)
[itemprop="articleBody"] img {
max-width: 100%;
height: auto;
}
max-width: 100%;
height: auto;
}
Hope that helps. This is something I've only recently got fully on top of myself, hence some changes in the default theme about it across the patch releases.
Last edit: by Chris Graham
Posted
Cheers for the breakdown Chris.
0 guests and 0 members have recently viewed this.