2016-09-28 98 views
2

我試圖讓一個100%列出現在引導網格的coloumn內部的一個元素下面。因爲它更容易用圖片來了解,這裏就是我想實現:引導響應網格佈局(3列)與每個網格元素下方的摺疊/隱藏col-12

grid of images, col-sm-4

當選擇一個圖像(1至x),一個隱藏的DIV(每個不同的內容)應該會出現下面的圖像中的全部12列大小:

selected image 1 selected image 2

我成功地做到這一點,但是,使用較小的分辨率時,這個隱藏的div顯示第三元素之下,而不是下面元素1.本是怎麼回事ULD是:

small resolution, selected image 1

會高興一些幫助!

這裏的實際版本的代碼片段:

// hide all 
 
\t $('.descriptions .panel').hide(); 
 

 
\t // handle img click 
 
\t $('#grid img').click(function() { 
 

 
\t // get index of the img that was clicked 
 
\t var idx = $(this).parent().parent().parent().index(); 
 

 
\t var row = $(this).parent().parent().parent().parent().next('.row'); 
 

 
\t // remove special style from all others 
 
\t $('#grid img').removeClass('highlight'); 
 

 
\t // add a special style to the clicked image 
 
\t $(this).addClass('highlight'); 
 

 
\t // hide all others 
 
\t $('.descriptions .panel').hide(); 
 

 
\t // show desc for clicked img 
 
\t row.find('.descriptions .panel').eq(idx).show(); 
 

 
\t });
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> 
 
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/> 
 
<style> 
 
.img-responsive{ 
 
\t margin: 0 auto; 
 
} 
 
</style> 
 
<!-- row 1 --> 
 
<div class="row" id="grid"> 
 
\t <div class="col-sm-4 portfolio-item"> 
 
\t \t <figure class="gallery-item"> 
 
\t \t \t <div class="img-title-text"> 
 
\t \t \t \t <img class="img-responsive" src="http://placehold.it/250x250" style="opacity:0.1;" alt=""> 
 
\t \t \t \t <span style="position: absolute; top: 25%; text-align: center;width: 95%; font-size: 20px;">text</span> 
 
\t \t \t </div> 
 
\t \t </figure> 
 
\t </div> 
 
\t <div class="col-sm-4 portfolio-item"> 
 
\t \t <figure class="gallery-item"> 
 
\t \t \t <div class="img-title-text"> 
 
\t \t \t \t <img class="img-responsive" src="http://placehold.it/250x250" style="opacity:0.1;" alt=""> 
 
\t \t \t \t <span style="position: absolute; top: 25%; text-align: center;width: 95%; font-size: 20px;">text</span> 
 
\t \t \t </div> 
 
\t \t </figure> 
 
\t </div> 
 
\t <div class="col-sm-4 portfolio-item"> 
 
\t \t <figure class="gallery-item"> 
 
\t \t \t <div class="img-title-text"> 
 
\t \t \t \t <img class="img-responsive" src="http://placehold.it/250x250" style="opacity:0.1;" alt=""> 
 
\t \t \t \t <span style="position: absolute; top: 25%; text-align: center;width: 95%; font-size: 20px;">text</span> 
 
\t \t \t </div> 
 
\t \t </figure> 
 
\t </div> 
 
</div> 
 

 
<!-- hidden row for images --> 
 
<div class="row"> 
 
    <div class="col-md-12 descriptions"> 
 
\t <div class="panel panel-default"> 
 
\t <div class="panel-body flex-grow">Content here for image 1.. Blah blah blah, blah blah. That is very interesting stuff. Aenean sit amet felis 
 
\t dolor, in sagittis nisi. Sed ac orci quis tortor imperdiet venenatis. </div> 
 
\t </div> 
 
\t <div class="panel panel-default"> 
 
\t <div class="panel-body flex-grow">Content here for image 2.. Blah blah blah, blah blah. That is very interesting stuff. Aenean sit amet felis 
 
\t dolor, in sagittis nisi. Sed ac orci quis tortor imperdiet venenatis. </div> 
 
\t </div> 
 
\t <div class="panel panel-default"> 
 
\t <div class="panel-body flex-grow">Content here for image 3.. Blah blah blah, blah blah. That is very interesting stuff. Aenean sit amet felis 
 
\t dolor, in sagittis nisi. Sed ac orci quis tortor imperdiet venenatis. </div> 
 
\t </div> 
 
    
 
    </div> 
 
</div> 
 

 
<!-- row 2 --> 
 
<div class="row" id="grid"> 
 
\t <div class="col-sm-4 portfolio-item"> 
 
\t \t <figure class="gallery-item"> 
 
\t \t \t <div class="img-title-text"> 
 
\t \t \t \t <img class="img-responsive" src="http://placehold.it/250x250" style="opacity:0.1;" alt=""> 
 
\t \t \t \t <span style="position: absolute; top: 25%; text-align: center;width: 95%; font-size: 20px;">text</span> 
 
\t \t \t </div> 
 
\t \t </figure> 
 
\t </div> 
 
\t <div class="col-sm-4 portfolio-item"> 
 
\t \t <figure class="gallery-item"> 
 
\t \t \t <div class="img-title-text"> 
 
\t \t \t \t <img class="img-responsive" src="http://placehold.it/250x250" style="opacity:0.1;" alt=""> 
 
\t \t \t \t <span style="position: absolute; top: 25%; text-align: center;width: 95%; font-size: 20px;">text</span> 
 
\t \t \t </div> 
 
\t \t </figure> 
 
\t </div> 
 
\t <div class="col-sm-4 portfolio-item"> 
 
\t \t <figure class="gallery-item"> 
 
\t \t \t <div class="img-title-text"> 
 
\t \t \t \t <img class="img-responsive" src="http://placehold.it/250x250" style="opacity:0.1;" alt=""> 
 
\t \t \t \t <span style="position: absolute; top: 25%; text-align: center;width: 95%; font-size: 20px;">text</span> 
 
\t \t \t </div> 
 
\t \t </figure> 
 
\t </div> 
 
</div> 
 

 
<!-- hidden row for images of row 2 --> 
 
<div class="row"> 
 
    <div class="col-md-12 descriptions"> 
 
\t <div class="panel panel-default"> 
 
\t <div class="panel-body flex-grow">Content here for image 1.. Blah blah blah, blah blah. That is very interesting stuff. Aenean sit amet felis 
 
\t dolor, in sagittis nisi. Sed ac orci quis tortor imperdiet venenatis. </div> 
 
\t </div> 
 
\t <div class="panel panel-default"> 
 
\t <div class="panel-body flex-grow">Content here for image 2.. Blah blah blah, blah blah. That is very interesting stuff. Aenean sit amet felis 
 
\t dolor, in sagittis nisi. Sed ac orci quis tortor imperdiet venenatis. </div> 
 
\t </div> 
 
\t <div class="panel panel-default"> 
 
\t <div class="panel-body flex-grow">Content here for image 3.. Blah blah blah, blah blah. That is very interesting stuff. Aenean sit amet felis 
 
\t dolor, in sagittis nisi. Sed ac orci quis tortor imperdiet venenatis. </div> 
 
\t </div> 
 
    
 
    </div> 
 
</div> 
 
[...]

回答

1

首先,我會將全寬列放在標記的相應圖像列下方,以便在較小的屏幕上獲得所需的佈局。

然後,您可以使用@media查詢在較大的屏幕上相應地調整隱藏行,使其成爲全寬並覆蓋父行。例如,給隱藏行overlay類。

@media (min-width:992px) { 
    .row { 
     position:relative; 
     padding: 30px; 
    } 
    .overlay { 
     position: absolute; 
     z-index:1; 
     width: 100%; 
     bottom: 0; 
    } 
} 

您可以使用Bootstrap的崩潰組件來顯示/隱藏隱藏的內容。

演示http://www.codeply.com/go/qhVNyUFOvj

+0

這正是我需要的!感謝您提供乾淨簡單的解決方案 – jmd

+0

任何想法如何讓隱藏的行更大(比如400px)並將元素4-6的行按此大小向下移動?這裏是您的代碼的一個分支:http://www.codeply.com/go/e1XIJn564r – jmd

+0

我通過向@media查詢添加一個圖像底部的邊距來管理它:'a [data-toggle = collapse]:不是(.collapsed)> img { \t \t \t margin-bottom:280px; \t \t}' – jmd

1

你有沒有試圖把隱藏的div爲每個圖像直接在圖像下面?如果您在每張圖片後面使用可摺疊的Bootstrap,並將其隱藏起來,然後應用所需的功能,則應該獲得所需的功能。是否有理由不能/不想爲每個描述使用單獨的<div>?

+0

如果我直接把一個div圖像下面,這個div具有相同的寬度圖像(所以只有1在桌面上時,列),僅在移動這種做法是可行的。如果你有一個解決桌面版本的想法,我會很樂意按照你的方式去做 – jmd

+0

可摺疊的div不必在觸發div之後。您可以將它放在所有三列之後,放在它自己的單獨行上。 –