I know this is mostly (maybe ?) a html and css issue, but the solution will be full of hugo jargon so I’d better ask here. Although feel free to tell me to get lost if I’m wrong, I won’t be offended I just wish to understand what’s going on, if I do I’ll figure out the solution, or or that there is none.
I have a linear gradient background and use lazy loading, good. Except that the dimensions of the object and its object ratio, before and after the loading, change, and disregard the attributes I gave to the object, which are Img.width and Img.height, Img being of course the biggest (original) image.
This is the code I use:
{{with $img}}width=“{{.Width}}” height=“{{.Height}}” {{end}}loading=“{{with .Attributes.loading}}{{ . }}{{else}}lazy{{end}}” {{with .Attributes.loading}}fetchpriority=high{{end}} alt=“{{ default .Title .Text }}” {{ with .Title }}title=“{{ .|plainify }}”{{end }} sizes=“(max-width: 400px) 100vw, (max-width: 604px) {{if in .Attributes.class “center”}}100vw, 70vw{{else}}50vw, 35vw{{end}}” {{with $img}}style=“max-width:{{.Width}}px;max-height:min({{.Height}}px, 500px); background:linear-gradient(45deg, {{delimit $smallest.Colors “,”}})”{{end}}
Dimensions are all in pixels. Now the weird part:
- css object-ratio: “auto 528/1349” → 0,391401037806
- actual dimensions displayed: 195.688/499.984, giving a ratio of 0,390781563126
- Img.width / Img.height: 549 / 1328 : 0,413403614458
- dimensions if I remove the src and srcset attributes: 141.422 / 361.312: 0,390581717452
this corresponds to no particular image versions, not even the smallest one.
I see that it matches the auto object-ratio css property, supposedly computed with the width and height attributes yet without matching them at all ? This baffles me.
I just want my color background to fill the damn place the image will be half a second after, but instead it occupies a very small surface for no reason. I thought the height and width attributes had the last word ?
The logic should be simple: Take the width and height of the biggest image fitting the 100, 70 50 or 35vw available, and make a colorful box with it until the image is loaded.
Lastly, in case it is the css that interfers, along with the style attribute above I have the following, supposed to say: make it as big as you can but not bigger than its parent or intrinsic size.
figure {
max-width:50%;
a {display:flex; cursor: zoom-in}
img{z-index:1;margin:auto;width:100%;height:100%;}
}
Thanks…