2016-05-12 16 views
-2

我正在爲我的網站構建一個「團隊」部分,其中與成員img和成員頭部相同的列包含的member_body div滑落,如果我想定義他們的寬度。在這種情況下可能會出現什麼問題?我希望他們垂直對齊,並有相同的寬度。同一列中的div不會垂直對齊

.member { 
 
    padding: 30px; 
 
    text-align: center; 
 
    position: relative; 
 
} 
 
.member img { 
 
    max-width: 250px; 
 
    margin: 20px auto 0px auto; 
 
} 
 
.member h3 { 
 
    margin: 30px 0px; 
 
} 
 
.member_body { 
 
    border: 1px solid red; 
 
    max-width: 250px; 
 
    overflow: hidden; 
 
    height: 200px; 
 
} 
 
.member_body span { 
 
    margin-top: 20px; 
 
    font-size: 30px; 
 
}
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" integrity="sha384-1q8mTJOASx8j1Au+a5WDVnPi2lkFfwwEAa8hDDdjZlpLegxhjVME1fgjWPGmkzs7" crossorigin="anonymous"> 
 
<div id="team"> 
 
    <h1>Our Team</h1> 
 
    <div class="separator2"></div> 
 
    <div class="container-fluid"> 
 
    <div class="row"> 
 
     <div class=" col-md-6"> 
 
     <div class="member"> 
 
      <h3>Member One</h3> 
 
      <img src="photos/team-member-1.jpg" alt="Team Member 1"> 
 
      <div class="member_body"> 
 
      <h5>Position</h5> 
 
      <div class="separator"></div> 
 
      <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit.</br>Voluptates praesentium nulla cupiditate!</p> 
 
      <span class="glyphicon glyphicon-envelope" aria-hidden="true"></span> 
 
      </div> 
 
     </div> 
 
     </div> 
 
     <div class=" col-md-5"> 
 
     <div class="member"> 
 
      <h3>Member 2</h3> 
 
      <img src="photos/team-member-2.jpg" alt="Team Member 2"> 
 
      <div class="member_body"> 
 
      <h5>Position</h5> 
 
      <div class="separator"></div> 
 
      <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit.</br>Voluptates praesentium nulla cupiditate!</p> 
 
      <span class="glyphicon glyphicon-envelope" aria-hidden="true"></span> 
 
      </div> 
 
     </div> 
 
     </div> 
 
     <div class="col-md-1"></div> 
 
    </div> 
 
    </div> 
 
</div>

`

+2

保證金:20px的汽車?在member_body類? – Pushpendra

回答

2

您使用3列(col-md-6 + col-md-5 + col-md-1),只需使用2(col-md-6 + col-md-6

UPDATE

  • add margin:auto to member_body如果您希望它與圖像具有相同的width並保持圖像居中。

  • 刪除max-width:250pximg在CSS並添加class="img-responsive"標記img

注意

  • 添加col-xs-*用於演示
  • </br>無效,應該是<br><br />

.member { 
 
    padding: 30px; 
 
    text-align: center; 
 
    position: relative; 
 
} 
 
.member img { 
 
    margin: 20px auto 0; 
 
} 
 
.member h3 { 
 
    margin: 30px 0px; 
 
} 
 
.member_body { 
 
    border: 1px solid red; 
 
    max-width: 250px; 
 
    overflow: hidden; 
 
    height: 200px; 
 
    margin:auto 
 
} 
 
.member_body span { 
 
    margin-top: 20px; 
 
    font-size: 30px; 
 
}
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css"> 
 
<div id="team"> 
 
    <h1>Our Team</h1> 
 
    <div class="separator2"></div> 
 
    <div class="container-fluid"> 
 
    <div class="row"> 
 
     <div class="col-xs-6 col-md-6"> 
 
     <div class="member"> 
 
      <h3>Member One</h3> 
 
      <img class="img-responsive" src="//lorempixel.com/250/200" alt="Team Member 1"> 
 
      <div class="member_body"> 
 
      <h5>Position</h5> 
 
      <div class="separator"></div> 
 
      <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. 
 
       <br />Voluptates praesentium nulla cupiditate!</p> 
 
      <span class="glyphicon glyphicon-envelope" aria-hidden="true"></span> 
 
      </div> 
 
     </div> 
 
     </div> 
 
     <div class="col-xs-6 col-md-6"> 
 
     <div class="member"> 
 
      <h3>Member 2</h3> 
 
      <img class="img-responsive" src="//lorempixel.com/250/200" alt="Team Member 2"> 
 
      <div class="member_body"> 
 
      <h5>Position</h5> 
 
      <div class="separator"></div> 
 
      <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Voluptates 
 
       <br />praesentium nulla cupiditate!</p> 
 
      <span class="glyphicon glyphicon-envelope" aria-hidden="true"></span> 
 
      </div> 
 
     </div> 
 
     </div> 
 
    </div> 
 
    </div> 
 
</div>

+0

儘管如此,最後一列僅僅是爲了美學,它應該是完全獨立的,它與上述col-md-5是同一列。我已經在我的代碼中試過了,但它仍然分開: -/ – sklrboy

+0

小心爲您的網站提供鏈接?我現在不在電腦上,但我會盡快看看。我不明白現在的問題是什麼。 – dippas

+0

當然,超級! http://laszlovaszi.com/yoursite/ – sklrboy

1

如果你想將它們對齊垂直使用多個<div class="row">

因此,1隊每<div class="row">

+0

不是我想要對齊的團隊成員,而是2個成員身體的成員照片:)您的意思是這樣嗎? – sklrboy

+0

這不是OP正在尋找的東西 – dippas