2017-09-01 40 views
1

我試圖使用Bootstrap和Flexbox創建一個庫,其中有一個大圖像,旁邊是兩個較小的堆疊圖像,並且兩者都是相同的高度。Boostrap和Flexbox的等高柱高

容器列似乎正在做他們的工作,並保持相同的高度,但我需要列中的img填充容器的高度。

它適用於Firefox,如果我在img上使用height: 100%,但在Chrome和Safari中均可使用。

img { 
 
    max-width: 100%; 
 
    width: auto\9; 
 
    height: auto; 
 
    vertical-align: middle; 
 
    border: 0; 
 
    -ms-interpolation-mode: bicubic; 
 
} 
 
figure { 
 
    margin-bottom: 0; 
 
} 
 
.rts-col { 
 
    margin-bottom: 30px; 
 
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta/css/bootstrap.min.css" rel="stylesheet"/> 
 
<div class="container"> 
 
    <div class="row"> 
 
    <div class="rts-col col-8"> 
 
     <figure> 
 
     <img src="http://via.placeholder.com/1400x933"> 
 
     </figure> 
 
    </div> 
 
    <div class="rts-col col-4"> 
 
     <figure style="margin-bottom: 30px;"> 
 
     <img src="http://via.placeholder.com/1400x933"> 
 
     </figure> 
 
     <figure> 
 
     <img src="http://via.placeholder.com/1400x933"> 
 
     </figure> 
 
    </div> 
 
    </div> 
 
</div>

這裏的標記和樣式表:https://jsfiddle.net/tylorreimer/q8qe5p80/2/

+2

@Paulie_D我沒有意識到我可以將代碼插入到我的問題上左右。我剛剛更新了我的問題,以包含最小代碼標記。 – tylorreimer

回答

1

看起來對我來說,就好像你需要一個有一側的多個圖像嵌套flexboxes。

img { 
 
    max-width: 100%; 
 
    width: auto\9; 
 
    height: auto; 
 
    vertical-align: middle; 
 
    border: 0; 
 
    -ms-interpolation-mode: bicubic; 
 
} 
 

 
figure { 
 
    margin: 0; 
 
} 
 

 
.rts-col.split { 
 
    display: flex; 
 
    flex-direction: column; 
 
    justify-content: space-between; 
 
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta/css/bootstrap.min.css" rel="stylesheet" /> 
 
<div class="container"> 
 
    <div class="row"> 
 
    <div class="rts-col col-8"> 
 
     <figure> 
 
     <img src="http://via.placeholder.com/1400x933"> 
 
     </figure> 
 
    </div> 
 
    <div class="rts-col col-4 split"> 
 
     <figure> 
 
     <img src="http://via.placeholder.com/1400x933"> 
 
     </figure> 
 
     <figure> 
 
     <img src="http://via.placeholder.com/1400x933"> 
 
     </figure> 
 
    </div> 
 

 
    </div> 
 
</div>

+0

你和@LGSon基本上有相同的解決方案,但爲了減少我的HTML標記中的類,我使用瞭解決方案。乾杯! – tylorreimer

1

如果使col-4柔性容器column方向,然後你可以使用justify-content及其space-between對準那些2圖像頂部/底部

添加d-flex flex-column justify-content-between<div class="rts-col col-4">所以它變成了<div class="rts-col col-4 d-flex flex-column justify-content-between">

N OTE,我也去掉了一些你的利潤率,使他們更好地對準

img { 
 
    display: block; 
 
    max-width: 100%; 
 
} 
 
figure { 
 
    margin: 0; 
 
} 
 
.rts-col { 
 
    margin-bottom: 30px; 
 
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta/css/bootstrap.min.css" rel="stylesheet"/> 
 
<div class="container"> 
 
    <div class="row"> 
 
    <div class="rts-col col-8"> 
 
     <figure> 
 
     <img src="http://via.placeholder.com/1400x933"> 
 
     </figure> 
 
    </div> 
 
    <div class="rts-col col-4 d-flex flex-column justify-content-between"> 
 
     <figure> 
 
     <img src="http://via.placeholder.com/1400x933"> 
 
     </figure> 
 
     <figure> 
 
     <img src="http://via.placeholder.com/1400x933"> 
 
     </figure> 
 
    </div> 
 
    <div class="rts-col col-6"> 
 
     <figure> 
 
     <img src="http://via.placeholder.com/1400x933"> 
 
     </figure> 
 
    </div> 
 
    <div class="rts-col col-6"> 
 
     <figure> 
 
     <img src="http://via.placeholder.com/1400x933"> 
 
     </figure> 
 
    </div> 
 
    </div> 
 
</div>

+0

非常感謝!我最終用@Paulie_D解決方案來保持我的HTML更清潔。 – tylorreimer

+0

@tylorreimer完美無瑕,不過,html中的3個類比創建額外的CSS規則更小,這是使用框架的全部重點......並使其更容易在標記中看到發生了什麼。 – LGSon

+0

我實際上只使用基本網格的Bootstrap版本。我不得不以任何方式添加這些額外的類,因此它更加簡單地將樣式添加到一個類中。 – tylorreimer