dillonzq / LoveIt

❤️A clean, elegant but advanced blog theme for Hugo 一个简洁、优雅且高效的 Hugo 主题
https://hugoloveit.com
MIT License
3.35k stars 1.07k forks source link

[BUG] Using ![]() image Markdown results in incorrect image dimensions #777

Open DanielBaulig opened 1 year ago

DanielBaulig commented 1 year ago

Describe the bug 描述你遇到的错误

When using the ![Alt text](image_url.png) Markdown in content in front matter leads to an incorrectly sized image for very large images. The generated CSS results in a scaled down image to be displayed, but the height of the image element itself remains the original height of the image. This appears to be because the layouts/partials/plugin/img.html plugin explicitly renders width and height attributes on the img element. If those are removed, the image scales correctly not blocking out unused whitespace along it's vertical axis.

Screen Shot 2022-12-18 at 5 38 58 PM

Expected behavior 期待的行为

Instead, no explicit width and height should be set on the img element, such that the CSS applied resizing (object-fit: contain and max-width:100%) can free up the vertical space.

Screen Shot 2022-12-18 at 5 39 40 PM

Environment 构建环境

DanielBaulig commented 1 year ago

It appears setting height: auto in the .single .content img selector will also resolve the issue.

jamesdeluk commented 1 year ago

It appears setting height: auto in the .single .content img selector will also resolve the issue.

I'd been resizing all my images manually - only today I noticed that height was always 2x what it should be. Then I found this post. Works perfectly, thanks!

gongyho commented 10 months ago

assets/css/_custom.scss

.single .content img{
  height: auto
}

Works perfectly, thanks!