I am attempting to transfer the width and height measurements of the initial image to all subsequent images on the page.
Currently, I have successfully applied the dimensions of the first image to the second one, but I am facing difficulties with the third, fourth, and so on...
As a newcomer to JavaScript, I acknowledge that there may be a simple mistake in my approach.
You can view the current status here: https://codepen.io/GBol/pen/GRXWvJY
<div class="boxA">
<img class="landscape"src="http://placekitten.com/800/400">
</div>
<div class="boxB">
<img class="portrait"src="http://placekitten.com/400/800">
</div>
<div class="boxC">
<img class="portrait"src="http://placekitten.com/400/800">
</div>
.boxA {
width: 20%;
border: solid blue;
display: block;
float: left;
}
.boxB {
border: solid blue;
display: block;
float: left;
}
.landscape {
width: 100%;
display: block;
}
.portrait {
height: 100%;
/** to center horizontally **/
margin: auto;
display: block;
}
var boxA = document.querySelector(".boxA"),
boxB = document.querySelector(".boxB")
function copyHeight(from,to){
to.style.height = from.getBoundingClientRect().height + "px"
}
copyHeight(boxA,boxB)
function copyWidth(from,to){
to.style.width = from.getBoundingClientRect().width + "px"
}
copyWidth(boxA,boxB)