I would like to put an image to fit some containers based on the height or the width.
The outer container A have the fixed width and height.
I only need to set the img like width:100% if I want it to be based on the width.
Then the image will fit the container. (no need to set the width of the container B)
But why do I have to set the height of the container B and the img if based on the height, otherwise the image will not fit and overflow the container. (can't I be like setting the width? ignore the height of container B)
<div className="containerA">
      <div className="containerB">
      <img src={abc}/>
      </div>
    </div>
CSS based on the width:
.containerA{
    width: 100px;
    height: 140px;
}
img{
   width:100%
}
CSS based on the height:
.containerA{
    width: 100px;
    height: 140px;
}
.containerB{
   height:100%
}
img{
   height:100%
}
 
     
     
    