2017-04-12 253 views
0

我有一個2頁相鄰的HTML頁面。每次我在一列中的文字少時,其高度就會變小。使HTML列保持相同大小

無論列中有什麼內容,我都希望列的高度保持不變。請注意我將有超過2列。當我添加更多的列時,列將在下面顯示。

這是我到目前爲止有:

HTML

  <div class="col-sm-6"> 
       <div class="services-post services-single-post"> 
        <div class="single-post-title"> 
         <h2> Music Production </h2> 
        </div> 

        <div class="single-post-image"> 
         <img src="img/music.jpg" alt="Post Title"> 
        </div> 

        <div class="single-post-info"> 
        </div> 

        <div class="single-post-content"> 
         <p>We also offer music production. We have been making music for over 10 years using industry standard software and equipment. If you are looking for the best you've come to the right place. </p> 
        <a href="services-post.html" class="btn">Read more</a> 
        </div> 
       </div> 
      </div> 

      <div class="col-sm-6"> 
       <div class="services-post services-single-post"> 
        <div class="single-post-title"> 
         <h2>Graphic design</h2> 
        </div> 

        <div class="single-post-image"> 
         <img src="img/s4.jpg" alt="Post Title"> 
        </div> 

        <div class="single-post-info"> 
        </div> 

        <div class="single-post-content"> 
         <p> 
          Graphic design solutions</p> 
        <a href="services-post.html" class="btn">Read more</a> 
        </div> 
       </div> 
      </div> 

CSS

.services-post { 
    background: #FFF; 
    position: relative; 
    margin: 20px 0; 
    border: 1px solid #EEE; 

} 
.services-post img { 
    max-width: 100%; 
} 
.services-post .post-info { 
    background: #000; 
    background: rgba(0, 0, 0, 0.6); 
    color: #FFF; 
    line-height: 1.2; 
    position: absolute; 
    padding: 5px; 
    left: 10px; 
    top: 10px; 
    -webkit-border-radius: 5px; 
    -webkit-background-clip: padding-box; 
    -moz-border-radius: 5px; 
    -moz-background-clip: padding; 
    border-radius: 5px; 
    background-clip: padding-box; 
} 
.services-post .post-comments-count { 
    text-align: center; 
} 

.post-info .post-comments-count i { 
    margin-right: 5px; 
} 
.post-info .post-comments-count a { 
    color: #FFF; 
} 
.post-info .post-date .date { 
    font-size: 0.7em; 
    font-weight: 600; 
} 
.post-title h3 { 
    font-size: 1.2em; 
    border-bottom: 1px dotted #828282; 
    margin: 0 20px; 
    padding-top: 10px; 
} 
.post-title h3 a { 
    color: #535b60; 
} 
.post-summary { 
    margin: 10px 20px; 
} 
.post-summary p { 
    color: #828282; 
    font-size: 0.9em; 
    text-align: justify; 
} 
.post-more { 
    text-align: right; 
    padding: 0 20px 20px 0; 
} 
/* Single Post */ 
.services-single-post { 
    padding: 10px 30px; 
} 
.single-post-title h2 { 
    font-size: 36px; 
    margin: 0 0 10px 0; 
    border-bottom: 1px dotted #828282; 
} 
.single-post-info { 
    margin: 20px 0; 
    padding-bottom: 10px; 
    border-bottom: 1px dotted #828282; 
} 
.single-post-info i { 
    color: #333; 
    margin-right: 5px; 
} 
.single-post-image { 
    text-align: center; 
} 
.single-post-image img { 
border:none; 
} 
.single-post-content { 
    margin: 30px 0 20px 0; 
    padding-bottom: 20px; 
    border-bottom: 2px dotted #CCC; 
} 
.single-post-content p { 
    color: #828282; 
    font-size: 0.9em; 
    text-align: justify; 
} 
+0

的可能的複製[在自舉高度相等的列3](http://stackoverflow.com/questions/28484089/equal-height-columns-in-bootstrap-3) – APAD1

回答

1

您可以使用bootstrap 4開箱即用,因爲它集成了flexbox,但您也可以使用它自舉3。

我添加了一個名爲.equal-height到將有你想等寬列的行類,並添加.equal-height { display: flex; }然後加入height: 100%.services-post讓邊框將延伸到塔的底部。

.services-post { 
 
    background: #FFF; 
 
    position: relative; 
 
    margin: 20px 0; 
 
    border: 1px solid #EEE; 
 
    height: 100%; 
 
} 
 
.services-post img { 
 
    max-width: 100%; 
 
} 
 
.services-post .post-info { 
 
    background: #000; 
 
    background: rgba(0, 0, 0, 0.6); 
 
    color: #FFF; 
 
    line-height: 1.2; 
 
    position: absolute; 
 
    padding: 5px; 
 
    left: 10px; 
 
    top: 10px; 
 
    -webkit-border-radius: 5px; 
 
    -webkit-background-clip: padding-box; 
 
    -moz-border-radius: 5px; 
 
    -moz-background-clip: padding; 
 
    border-radius: 5px; 
 
    background-clip: padding-box; 
 
} 
 
.services-post .post-comments-count { 
 
    text-align: center; 
 
} 
 

 
.post-info .post-comments-count i { 
 
    margin-right: 5px; 
 
} 
 
.post-info .post-comments-count a { 
 
    color: #FFF; 
 
} 
 
.post-info .post-date .date { 
 
    font-size: 0.7em; 
 
    font-weight: 600; 
 
} 
 
.post-title h3 { 
 
    font-size: 1.2em; 
 
    border-bottom: 1px dotted #828282; 
 
    margin: 0 20px; 
 
    padding-top: 10px; 
 
} 
 
.post-title h3 a { 
 
    color: #535b60; 
 
} 
 
.post-summary { 
 
    margin: 10px 20px; 
 
} 
 
.post-summary p { 
 
    color: #828282; 
 
    font-size: 0.9em; 
 
    text-align: justify; 
 
} 
 
.post-more { 
 
    text-align: right; 
 
    padding: 0 20px 20px 0; 
 
} 
 
/* Single Post */ 
 
.services-single-post { 
 
    padding: 10px 30px; 
 
} 
 
.single-post-title h2 { 
 
    font-size: 36px; 
 
    margin: 0 0 10px 0; 
 
    border-bottom: 1px dotted #828282; 
 
} 
 
.single-post-info { 
 
    margin: 20px 0; 
 
    padding-bottom: 10px; 
 
    border-bottom: 1px dotted #828282; 
 
} 
 
.single-post-info i { 
 
    color: #333; 
 
    margin-right: 5px; 
 
} 
 
.single-post-image { 
 
    text-align: center; 
 
} 
 
.single-post-image img { 
 
border:none; 
 
} 
 
.single-post-content { 
 
    margin: 30px 0 20px 0; 
 
    padding-bottom: 20px; 
 
    border-bottom: 2px dotted #CCC; 
 
} 
 
.single-post-content p { 
 
    color: #828282; 
 
    font-size: 0.9em; 
 
    text-align: justify; 
 
} 
 
.equal-height { 
 
    display: flex; 
 
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/> 
 
<div class="container-fluid"> 
 
    <div class="row equal-height"> 
 
    <div class="col-sm-6"> 
 
     <div class="services-post services-single-post"> 
 
     <div class="single-post-title"> 
 
      <h2> Music Production </h2> 
 
     </div> 
 

 
     <div class="single-post-image"> 
 
      <img src="img/music.jpg" alt="Post Title"> 
 
     </div> 
 

 
     <div class="single-post-info"> 
 
     </div> 
 

 
     <div class="single-post-content"> 
 
      <p>We also offer music production. We have been making music for over 10 years using industry standard software and equipment. If you are looking for the best you've come to the right place. </p> 
 
      <a href="services-post.html" class="btn">Read more</a> 
 
     </div> 
 
     </div> 
 
    </div> 
 

 
    <div class="col-sm-6"> 
 
     <div class="services-post services-single-post"> 
 
     <div class="single-post-title"> 
 
      <h2>Graphic design</h2> 
 
     </div> 
 

 
     <div class="single-post-image"> 
 
      <img src="img/s4.jpg" alt="Post Title"> 
 
     </div> 
 

 
     <div class="single-post-info"> 
 
     </div> 
 

 
     <div class="single-post-content"> 
 
      <p> 
 
      Graphic design solutions</p> 
 
      <a href="services-post.html" class="btn">Read more</a> 
 
     </div> 
 
     </div> 
 
    </div> 
 
    </div> 
 
</div>

+0

您好,你的答案完美的工作,但它不會很好地在IE中定位列。請你幫助我 –

0

無法看到您額外的標記,但是這看起來像是引導。網格系統列需要嵌套在其類中標有「行」的元素內:

<div class="row"> 
    <div class="col-sm-6"> content</div> 
    <div class="col-sm-6"> more content</div> 
</div> 

您的HTML是否有這個?

+0

是我有 –

0

可以使錶行的最小高度輸入你需要的是確切的像素數量靜態的。嘗試將以下內容添加到css並在您的html中實施相關類。

.tableHeight{ 
    min-height: 20px; 
} 
相關問題