例えば商品一覧など横並びに4つ並べて表示させたい場合
しかし用意された画像が全部バラバラで統一してくれない
そんな場合の処理になります。
imgタグのクラスに「img-fit」を追加して対応しております。
object-fit: contain; と要素の幅と高さを指定しております




<div class="fixed-flex_in"> <div class="list-fixed-box"><img src="/wp-content/uploads/2024/12/line.png" alt="LINEアイコン" width="512" height="512" class="aligncenter size-full wp-image-148 img-fit" /></div> <div class="list-fixed-box"><img src="/wp-content/uploads/2024/12/top.png" alt="雲の画像" width="1920" height="1003" class="aligncenter size-full wp-image-203 img-fit" /></div> <div class="list-fixed-box"><img src="/wp-content/uploads/2024/12/01.png" alt="振り向きねこちゃん" width="370" height="320" class="aligncenter size-full wp-image-142 img-fit" /></div> <div class="list-fixed-box"><img src="/wp-content/uploads/2024/12/syokuji_computer.png" alt="ラーメンを食べてる画像" width="800" height="756" class="aligncenter size-full wp-image-233 img-fit" /></div> </div>
.fixed-flex_in { display: flex; flex-wrap: wrap; justify-content: center; } .list-fixed-box { position: relative; width: calc(100% / 4 - 2%); margin: 0.45%; padding: 10px 0px; box-shadow: 0px 1px 5px 0px rgb(0 0 0 / 10%); } .img-fit { width: 200px; height: 200px !important; object-fit: contain; }