I have an image centered inside a container, but when I increase the width/height of an image, it won't fully showing inside the container.
But when an image is not centered(top left), the image fully showing. Why is that happening?
const scaleUp = () => {
const img = document.getElementById("tree")
img.style.height = "100%"
}
const scaleDown = () => {
const img = document.getElementById("tree")
img.style.height = "50%"
}
.container {
width: 500px;
height: 500px;
background: #f2d0d0;
overflow: auto;
margin-bottom: 20px;
display: flex;
justify-content: center;
align-items: center;
}
#tree {
height: 100%;
border: 1px solid cyan;
}
span {
width: 200px;
height: 40px;
border: 1px solid #333;
padding: 10px;
cursor: pointer
}
<div class="container">
<img id="tree" src="https://momentum.photos/img/843956cc-70c7-4578-97d5-e95102c0a7e2.jpg" />
</div>
<span onClick="scaleUp()" id="scale_up">scale up</span>
<span onClick="scaleDown()" id="scale_up">scale down</span>