I’m using a Bootstrap grid to have 3 columns on large screens, two on smaller screens.
Inside the grid I’m displaying products. These products have two images that need to be overlaid. To accomplish this I’m using the standard pattern of a container with position: relative, and images inside it with position: absolute. The first (red) image is 500x666, while the second (blue) image is 640x320; I can’t change the sizes of these images. The second image needs to be transformed: rotate
d, scale
d and moved (translate
d) to a different position. The images in this example and the actual transformation applied are of course just examples to highlight the problem.
The code I have is as follows:
With 0.25x or full screen on the Code Pen site you can see how it should look; 0.5x and 1.x will show two problems:
- On smaller screens the blue rectangle moves – it’s no longer in the same position relative to the red image. I tried changing the order of the transforms but it didn’t help.
- The
height: 666px
is hardcoded in the CSS, but because the images are scaled down on smaller screens that’s not correct. I’m not sure if this is what’s causing the first problem, and that if I could get the height to adjust automatically then the blue rectangle would stay in the same relative place.
Has anyone encountered anything like this before and, hopefully, know how to fix the problem?