I have a unique image with dimensions width: 656px
and height: 60px
that serves as the background for my menu. Each menu button has a specific position within the image, for example, the menu button for 'media' is located at (188x, 0y), with a width of 104 and a height of 30:
https://i.stack.imgur.com/Df6uz.png
Each li element has its own distinct id.
If you prefer percentages, the position would be (28.659%x, 0%y) with a width of 15.854% and a height of 50% relative to the entire image.
The actual height of the menu could be 1em or 2em depending on various factors.
My goal in CSS is to:
- Maintain the height of each li element
- Preserve the aspect ratio (e.g., 3.466:1 for 'media')
- Set each
<li>
's width to be 3.466 times its height - Fill it with background from the source image, adjusting the stretching or shrinking of the background accordingly
In pseudo code, this seems straightforward:
li.w = li.h * 3.466;
StretchBlt(src, 188, 0, 104, 30, li, 0, 0, li.w, li.h);
But how can I achieve this using CSS?