2017-04-03 132 views
-1

我試圖在2x2(水平x垂直)網格中製作圖像網格。當屏幕尺寸縮小時,我希望這些圖像以1x4垂直格式顯示,以便它們保留大部分尺寸。我發現了幾個來自不同網站的相關文章,但它們都有內容填滿整個頁面。這不是我想要做的事情。下圖顯示了2x2網格的外觀。在網站的大小版本上,圖像填滿整個屏幕是完全可以的。我會如何去做這件事?2x2圖像響應式圖像網格

我現在已經包含了一些關於如何粗略看看最終產品的截圖,但圖像取代了紅色正方形。
e.g. desktop resolution
e.g. smartphone resolution

.imageLineTop { 
 
\t display: inline-block; 
 
\t width: 100%; 
 
\t height: 725px; 
 
\t top: 60%; 
 
\t left: 50%; 
 
\t transform: translate(50%, 50%); 
 
} 
 

 
.imageLineBottom { 
 
\t display: inline-block; 
 
\t margin-top: 45px; 
 
\t width: 100%; 
 
\t height: 725px; 
 
\t top: 60%; 
 
\t left: 50%; 
 
\t transform: translate(50%, 50%); 
 
} 
 

 
#img0 { 
 
\t height: 700px; 
 
} 
 

 
#img1 { 
 
\t height: 700px; 
 
} 
 

 
#img2 { 
 
\t height: 700px; 
 
} 
 

 
#img3 { 
 
\t height: 700px; 
 
} 
 

 
#fadeBox0 { 
 
\t width: 478px; 
 
\t height: 700px; 
 
\t background-color: black; 
 
\t opacity: 0.5; 
 
\t left: 24%; 
 
\t position: absolute; 
 
\t display: none; 
 
} 
 

 
#fadeBox1 { 
 
\t width: 478px; 
 
\t height: 700px; 
 
\t background-color: black; 
 
\t opacity: 0.5; 
 
\t right: 24%; 
 
\t position: absolute; 
 
\t display: none; 
 
} 
 

 
#fadeBox2 { 
 
\t width: 478px; 
 
\t height: 700px; 
 
\t background-color: black; 
 
\t opacity: 0.5; 
 
\t left: 24%; 
 
\t position: absolute; 
 
\t display: none; 
 
} 
 

 
#fadeBox3 { 
 
\t width: 478px; 
 
\t height: 700px; 
 
\t background-color: black; 
 
\t opacity: 0.5; 
 
\t right: 24%; 
 
\t position: absolute; 
 
\t display: none; 
 
}
\t <!--Top image line--> 
 
\t \t <section class="imageLineTop"> 
 
\t \t \t <img class="discoverImage" id="img0" src="assets/imgs/1.jpg"> 
 
\t \t \t <img class="discoverImage" id="img1" src="assets/imgs/2.jpg"> 
 

 
\t \t \t <section id="fadeBox0"> 
 
\t \t \t \t <h3 class="imageInlineTitle">Purity.</h3> 
 
\t \t \t </section> 
 

 
\t \t \t <section id="fadeBox1"> 
 
\t \t \t \t <h3 class="imageInlineTitle">Style.</h3> 
 
\t \t \t </section> 
 
\t \t </section> 
 

 
\t \t <!--Bottom image line--> 
 
\t \t <section class="imageLineBottom"> 
 
\t \t \t <img class="discoverImage" id="img2" src="assets/imgs/3.jpg"> 
 
\t \t \t <img class="discoverImage" id="img3" src="assets/imgs/4.jpg"> 
 

 
\t \t \t <section id="fadeBox2"> 
 
\t \t \t \t <h3 class="imageInlineTitle">Integrity.</h3> 
 
\t \t \t </section> 
 

 

 
\t \t \t <section id="fadeBox3"> 
 
\t \t \t \t <h3 class="imageInlineTitle">Courage.</h3> 
 
\t \t \t </section> 
 
\t \t </section>

+0

所以只需將父DIV這2個圖像與一些最大寬度和中間父DIV。 –

+0

你可以發佈你的代碼嗎? – Tommy

+0

當然,現在上傳它。 – Josh

回答

0

我也不太確定你的最終目標是什麼在這裏,但你可以讓你的形象走上新線一旦窗口是比實際小大小通過給他們:

.img0, .img1, .img2, .img3 {position: relative} 

記住不要在這種情況下使用百分比寬度。

請看下面的小提琴。希望它有幫助。

https://jsfiddle.net/7rtb084r/

+0

非常感謝!既然提出這個問題,我已經設法做出類似的事情,但我仍然在努力,因爲我也希望「網格」能夠隨時處於中心位置。因此,當它是2×2時,連續兩幅圖像之間的中點在屏幕寬度的50%處,然後在調整到1×4時,圖像的中間位於屏幕寬度的50%處。對不起,如果我沒有說清楚自己,我只是在努力讓自己在這裏做什麼,所以不知道如何把我的話放在紙上。 – Josh

+0

@Josh因此,您需要將每行圖片放入父div,然後添加{margin-left:auto;保證金右:自動;寬度:1010px}到父級。這是假設圖像是500px。看到這個小提琴:https://jsfiddle.net/7rtb084r/4/ – DM98

+1

謝謝,是的,這讓我到我想要的地方。如果我把這兩個小提琴結合起來,它似乎不起作用。他們將正確執行彼此獨立,但是當他們合併時,他們不會。任何提示如何將它們結合起來將不勝感激,所以提前謝謝! – Josh