Closed florentb closed 3 years ago
Hey @florentb,
Thank you for your complete explanation.
I agree, the current state of nuxt-image
has blocking behavior in responsive development.
Like your suggestion, in the next changes fixed-width will remove from the wrapper element, and the ratio will be used to preserve image scale.
There are three possible ways to calculate ratio:
ratio
prop provided by userheight / width * 100
nuxt-image
automatically calculates images ratio. All users need to do is sizing their images. Also, the wrapper element in nuxt-images
will have width: 100%
in its class styles. This a fallback size in case users does not size their images.
From what I read in the doc and what I experiment, the
width
andheight
attributes are mandatory. This is a good thing for the CLS reasons explained in the doc but I think they are currently misused. The main reason we have to putwidth
andheight
onimg
elements is to inform the browsers about the aspect ratio.Here is a quote of Addy Osmani on the subject (full article here).
In the current implementation, the
width
is used to define the width of the container which in responsive development is a blocking behavior. I think developers should be responsible for sizing their items whilenuxt-image
should adopt a responsive approach with relative sizings.Eg: https://codepen.io/twicpics/pen/627fd52cd4dc523ff72c2fadef9b78a0?editors=1100
Then let browsers choose the correct image by playing with
srcset
.Eg: https://codepen.io/twicpics/pen/b87821d341540afe22cd079059536f84?editors=1100
Regarding the placeholder behavior, same idea: the
padding-top
trick could be dynamically computed by using CSScalc()
.Eg: https://codepen.io/twicpics/pen/d6317ba5001ecdd3f2920d7dfb2e782a?editors=1100
I didn't dig into the "fit" attribute but it shouldn't be a problem.
Does it make sens?