How do I make side-by-side images equal height (CSS/HTML)? -
Two images, one 300x400 pixels (height x width), the other is 500x600. How can I reveal those two sides to scale, so that they are the same height on the screen (or the container / div) without changing the aspect ratio of the image either?
I have an HTML / CSS method to do this - something that probably works possibly for more than 2 images, currently I manually calculate the width of each image (math below) I am
Edit:
An example of what I'm trying to do:
The formula used below (or trial and error) to come up with the 79/20 split. Note that 79 + 20 & lt; 100- If I set it to 80/20, then wrap the images due to the limit. How can I do this without any calculations? The browser should be able to do this for me.
ah1 = 300 // The actual height of the image is 1 aw1 = 400 // The actual width of the image is 1 aH 2 = 500 / actual height of the image 2 aw2 = 600 // Actual width 2 image / / These are needed to calculate: dw1 // the width of the image's display 1, expressed as the percentage dw2, the width of 2 image 2, percent dw1 + dw2 == 100% expressed as s1 = dw1 / aw1 // Image size 1 (how much it has shrunk) s2 = dw2 / aw2 dh1 = ah1 * s1 // height of image 1 = its actual height * its scale factor dh2 = ah2 * s2 // similar To obtain Manta heights, this equality needs to be resolved: dh1 == dh2 s1 * ah1 == s2 * ah2 dw1 / aw1 * ah1 = dw2 / aw2 * ah2 dw1 / aw1 * ah1 == (1 - dw1 ) / Aw2 * Ah2 dw1 * aw2 * ah1 == (1 - dw1) * aw1 * ah2 dw1 * aw2 * ah1 == aw1 * ah2 - aw1 * ah2 * dw1 dw1 * aw2 * ah1 + aw1 * ah 2 * dw1 = = Aw1 * ah 2 dw1 * (aw2 * ah1 + aw1 * ah2) == aw1 * ah 2 dw1 == aw1 * ah2 / (aw2 * ah1 + aw1 * ah2) == 400 * 500 / (600 × 300 + 400 * 500) == 20 / (18 + 20) == 20/38 == 52.63% // that ends in style = "width: 53%" which is not quite right ...
why value of image height value without properties of width To Irdharit?
Like this: & lt; Img height = "300" src = "path / to / image.png" />
You can get it through CSS, the same principle: You set the height, And not the breadth. Rescaling will be proportional ...
Comments
Post a Comment