I had never heard of aspect-ratio in modern CSS when I posted the article, but now I am using A Howarth’s solution (see the first comment replying to the question posted), that of specifying the aspect-ratio in the CSS, instead of specifying the height explicitly. I am hoping that this is the perfect solution, but testing has not yet been completed. Many thanks to A Howarth for this post, which I am hoping is indeed the answer, and an ideal one too, seeing as I really wanted to avoid placing width and height attributes in the (X)HTML because I’m trying hard to keep all presentation information hidden and confined to the CSS.
The plan gives the correct visual results, but I have (i) not checked what happens if the width is constrained to be less than the specified one, and (ii) I have not checked for layout shift. There is a max-width constraint in the CSS, which could cause a reduction in the width, in which case I hope now that the aspect ratio will always remain correct even when the current width is reduced.