diff --git a/src/app/app.scss b/src/app/app.scss index ebe16db2b..739bb6134 100644 --- a/src/app/app.scss +++ b/src/app/app.scss @@ -299,7 +299,6 @@ core-format-text[ng-reflect-single-line="true"] { } img.core-media-adapt-width { - width: 100%; height: auto; } diff --git a/src/directives/format-text.ts b/src/directives/format-text.ts index 466654f91..5d5bf1f36 100644 --- a/src/directives/format-text.ts +++ b/src/directives/format-text.ts @@ -117,11 +117,16 @@ export class CoreFormatTextDirective implements OnChanges { protected adaptImage(elWidth: number, img: HTMLElement): void { const imgWidth = this.getElementWidth(img), // Element to wrap the image. - container = document.createElement('span'); + container = document.createElement('span'), + originalWidth = img.attributes.getNamedItem('width'); - const forcedWidth = parseInt(img.attributes.getNamedItem('width').value); - if (!isNaN(forcedWidth) && img.attributes.getNamedItem('width').value.indexOf('%') < 0) { - img.style.width = forcedWidth + 'px'; + const forcedWidth = parseInt(originalWidth && originalWidth.value); + if (!isNaN(forcedWidth)) { + if (originalWidth.value.indexOf('%') < 0) { + img.style.width = forcedWidth + 'px'; + } else { + img.style.width = forcedWidth + '%'; + } } container.classList.add('core-adapted-img-container');