利用CSS transform屬性中的 translateY 來改變垂直位移

再利用position:relative 設定 top屬性,配合使物件可以垂直置中

<div class="col-xs-4 recommendPic">
         <img src="/template/hw/pic/obj2243009_1.jpg" >
</div>
<style>
.recommendPic{
    padding: 0px;
    background-color: #ebebeb;
    width: 33.3333%;
    height: 126px;
    text-align: center;
}
.recommendPic>img {
    max-height: 126px;
    max-width: 100%;
    position: relative;
    top: 50%;
    transform: translateY(-50%);

}
</style>

arrow
arrow
    全站熱搜
    創作者介紹
    創作者 swordheart313 的頭像
    swordheart313

    前端筆記

    swordheart313 發表在 痞客邦 留言(0) 人氣()