簡體   English   中英

如何在列中將對齊圖像底部對齊和居中

[英]How to bottom align and center an responsive image in a column

我有這個布局(這是一個標題):

<div class="container-fluid">
    <div class="row">
        <div class="col-sm-2" style="background-color: aqua; height: 160px;">
            <img src="logo.png" class="img-responsive logo">
        </div>
        <div class="col-sm-8" style="background-color: blueviolet; height: 160px;"></div>
        <div class="col-sm-2" style="background-color: aqua; height: 160px;"></div>
    </div>
</div>

我想實現的是:

  • 將徽標與底部和中心對齊
  • 讓圖像負責(將寬度設置為列的80%)

我這樣做:

.logo {
  position: absolute;
  width: 80%;
  left: 10%;
  right: 10%;
  bottom: 0;
}

但它不起作用,如您在此處看到的那樣: https : //jsfiddle.net/9kauhbhs/2/

您可以嘗試一下。.https ://jsfiddle.net/9kauhbhs/7/

.container{ 
  position:absolute;
  bottom:0px;
  height:auto;
  width:100%;
  text-align:center;
}
.logo {
  position: relative;
  width: auto;
  height:auto;
  margin:0 auto;
  max-height:100%;
  vertical-align:bottom;
}


<div class="col-sm-2 text-center" style="background-color: aqua; height: 160px;">
    <div class="container">
        <img src="http://www.w3schools.com/html/pic_mountain.jpg" class="logo">
        </div>    
    </div>

left: 50%使用left: 50% ,左邊距為圖像寬度的負一半。

例如

.logo {
    position: absolute;
    width: 80%;
    left: 50%;
    bottom: 0;
    margin-left: calc(-80% / 2); 
}

小提琴

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM