2017-08-29 62 views
0

我有兩個並排的div,但似乎無法確定如何使它們響應。兩個Side-by-Side Divs - 增加響應度

尋找正確的方框落在左邊框下600px或更低,保持所有其他居中,我在divs內完成。

每個並排div分別具有class .div-seller-resources-left和.div-seller-resources-right。

我爲每個文本框的高度已經使用600px的媒體屏幕,因此我將使用600作爲此斷點。

附加了它在普通尺寸瀏覽器中所做的照片,以及它在小屏幕上的樣子。正如您所看到的,較小的屏幕恰好可以將所有內容放在一個頁面上。

enter image description here

enter image description here

/* formats the seller-resources page */ 
 
.div-header-seller-resources{ 
 
    font-size:30px; 
 
    line-height:32px; 
 
    margin-bottom:10px; 
 
} 
 
.div-detail-seller-resources{ 
 
    font-size:20px; 
 
    line-height:22px; 
 
    margin-bottom:45px; 
 
} 
 
/*sets the height of the div so each text box is the same size no matter how much text*/ 
 
.seller-resources-height{ 
 
    height: 125px; 
 
} 
 
/*main container of two side by side boxes*/ 
 
.div-main-container-seller-resources{ 
 
    width:100%; 
 
    margin-top:30px; 
 
    text-align: center; 
 
    display: flex; 
 
    justify-content: center; 
 
} 
 
/*div under main container, containing both right and left seller resourcs */ 
 
.seller-resources-inner{ 
 
    display: flex; 
 
    flex-direction:row; 
 
} 
 
/*margin here centeres all the content within the div*/ 
 
.div-seller-resources-left{ 
 
    width: 300px; 
 
    display: flex; 
 
    text-align:center; 
 
    margin:0px auto; 
 
} 
 
/*margin here centeres all the content within the div*/ 
 
.div-seller-resources-right{ 
 
    width: 350px; 
 
    display: flex; 
 
    text-align:center; 
 
    margin:0px auto; 
 
} 
 
/* sets the text box screens taller at smaller screens so they don't overlap */ 
 
@media screen and (max-width: 600px) { 
 
    .seller-resources-height{ 
 
    height:200px; 
 
    } 
 
} 
 
@media screen and (max-width: 600px) { 
 
    div-seller-resources-left .div-seller-resources-left{ 
 
    width:100%; 
 
    } 
 
}
<div class="div-main-container-seller-resources"> 
 
    <div class="seller-resources-inner"> 
 
    <div class="div-seller-resources-left" style="display: inline-block;"> 
 
     <div class="seller-resources-height"> 
 
      <div class="div-header-seller-resources"><a href="https://yodega.com/how-yodega-works/">How Yodega Works</a></div> 
 
      <div class="div-detail-seller-resources">Learn about how Yodega works for sellers</div> 
 
      </div> 
 
      <div class="clear"></div> 
 
     <div class="seller-resources-height"> 
 
      <div class="div-header-seller-resources"><a href="https://yodega.com/referrals/">Referrals</a></div> 
 
      <div class="div-detail-seller-resources">Refer another business to reduce your fees</div> 
 
     </div> 
 
     <div class="clear"></div> 
 
     <div class="seller-resources-height"> 
 
       <div class="div-header-seller-resources"><a href="https://yodega.com/how-to-sell-with-yodega/">How to Sell with Yodega</a></div> 
 
      <div class="div-detail-seller-resources">Learn the best ways to promote your Yodega store</div> 
 
     </div> 
 
     <div class="clear"></div> 
 
    </div> 
 
    <div class="div-seller-resources-right" style="display: inline-block;"> 
 
     <div class="seller-resources-height"> 
 
      <div class="div-header-seller-resources"><a href="https://yodega.com/setting-up-your-store/">Setting Up Your Store</a></div> 
 
      <div class="div-detail-seller-resources">Detailed instructions on how to build your store</div> 
 
     </div> 
 
     <div class="clear"></div> 
 
     <div class="seller-resources-height"> 
 
      <div class="div-header-seller-resources"><a href="https://yodega.com/advanced-product-shipping/">Advanced Shipping &amp; Product Options</a></div> 
 
      <div class="div-detail-seller-resources">Variable Shipping Costs, Add Product Details and More</div> 
 
     </div> 
 
     <div class="clear"></div> 
 
     <div class="seller-resources-height"> 
 
      <div class="div-header-seller-resources"><a href="https://yodega.com/order-management-seller-dashboard/">Order Management, Seller Dashboard &amp; Payment</a></div> 
 
      <div class="div-detail-seller-resources">Detailed information on how to manage and fill orders and payments</div> 
 
     </div> 
 
     <div class="clear"></div> 
 
       </div> 
 
    </div> 
 
</div>

+0

您可以添加柔性包裝:包裝;進入媒體查詢之外的.seller-resources-inner {},它應該可以工作,但是如果您想要更具體的話,請在媒體查詢中嘗試使用 –

+0

您可以改進問題以描述您想要實現的內容。據我可以看到2個div是並排的。是不是希望2個並排div的標題佔據相同數量的垂直空間? –

+0

嗨馬丁喬伊納,他們看起來如何我喜歡全屏幕,但在較小的屏幕上,我想並排divs堆棧。 –

回答

1

我會建議使用flex-wrap屬性。在這種情況下,您可以將元素強制爲單個列。 (請參閱MDN Docs

只需將flex-wrap: wrap;應用於.seller-resources-inner類(請參閱下面的代碼段)。

/* formats the seller-resources page */ 
 

 
.div-header-seller-resources { 
 
    font-size: 30px; 
 
    line-height: 32px; 
 
    margin-bottom: 10px; 
 
} 
 

 
.div-detail-seller-resources { 
 
    font-size: 20px; 
 
    line-height: 22px; 
 
    margin-bottom: 45px; 
 
} 
 

 

 
/*sets the height of the div so each text box is the same size no matter how much text*/ 
 

 
.seller-resources-height { 
 
    height: 125px; 
 
} 
 

 

 
/*main container of two side by side boxes*/ 
 

 
.div-main-container-seller-resources { 
 
    width: 100%; 
 
    margin-top: 30px; 
 
    text-align: center; 
 
    display: flex; 
 
    justify-content: center; 
 
} 
 

 

 
/*div under main container, containing both right and left seller resourcs */ 
 

 
.seller-resources-inner { 
 
    display: flex; 
 
    flex-direction: row; 
 
} 
 

 

 
/*margin here centeres all the content within the div*/ 
 

 
.div-seller-resources-left { 
 
    width: 300px; 
 
    display: flex; 
 
    text-align: center; 
 
    margin: 0px auto; 
 
} 
 

 

 
/*margin here centeres all the content within the div*/ 
 

 
.div-seller-resources-right { 
 
    width: 350px; 
 
    display: flex; 
 
    text-align: center; 
 
    margin: 0px auto; 
 
} 
 

 

 
/* sets the text box screens taller at smaller screens so they don't overlap */ 
 

 
@media screen and (max-width: 600px) { 
 
    .seller-resources-height { 
 
    height: 200px; 
 
    } 
 
    .seller-resources-inner { 
 
    flex-wrap: wrap; 
 
    } 
 
} 
 

 
@media screen and (max-width: 600px) { 
 
    div-seller-resources-left .div-seller-resources-left { 
 
    width: 100%; 
 
    } 
 
}
<div class="div-main-container-seller-resources"> 
 
    <div class="seller-resources-inner"> 
 
    <div class="div-seller-resources-left" style="display: inline-block;"> 
 
     <div class="seller-resources-height"> 
 
      <div class="div-header-seller-resources"><a href="https://yodega.com/how-yodega-works/">How Yodega Works</a></div> 
 
      <div class="div-detail-seller-resources">Learn about how Yodega works for sellers</div> 
 
      </div> 
 
      <div class="clear"></div> 
 
     <div class="seller-resources-height"> 
 
      <div class="div-header-seller-resources"><a href="https://yodega.com/referrals/">Referrals</a></div> 
 
      <div class="div-detail-seller-resources">Refer another business to reduce your fees</div> 
 
     </div> 
 
     <div class="clear"></div> 
 
     <div class="seller-resources-height"> 
 
       <div class="div-header-seller-resources"><a href="https://yodega.com/how-to-sell-with-yodega/">How to Sell with Yodega</a></div> 
 
      <div class="div-detail-seller-resources">Learn the best ways to promote your Yodega store</div> 
 
     </div> 
 
     <div class="clear"></div> 
 
    </div> 
 
    <div class="div-seller-resources-right" style="display: inline-block;"> 
 
     <div class="seller-resources-height"> 
 
      <div class="div-header-seller-resources"><a href="https://yodega.com/setting-up-your-store/">Setting Up Your Store</a></div> 
 
      <div class="div-detail-seller-resources">Detailed instructions on how to build your store</div> 
 
     </div> 
 
     <div class="clear"></div> 
 
     <div class="seller-resources-height"> 
 
      <div class="div-header-seller-resources"><a href="https://yodega.com/advanced-product-shipping/">Advanced Shipping &amp; Product Options</a></div> 
 
      <div class="div-detail-seller-resources">Variable Shipping Costs, Add Product Details and More</div> 
 
     </div> 
 
     <div class="clear"></div> 
 
     <div class="seller-resources-height"> 
 
      <div class="div-header-seller-resources"><a href="https://yodega.com/order-management-seller-dashboard/">Order Management, Seller Dashboard &amp; Payment</a></div> 
 
      <div class="div-detail-seller-resources">Detailed information on how to manage and fill orders and payments</div> 
 
     </div> 
 
     <div class="clear"></div> 
 
       </div> 
 
    </div> 
 
</div>

+0

感謝您的信息,Ramiz!這似乎是正確的道路。但是,他們仍然並排放置(不堆疊)在一個較小的屏幕上。也許是因爲divs能夠縮小到足以觸發堆棧?要看現場去http://yodega.com/seller-resources –

+0

@JacobJordan嗯,我認爲這個問題是錯誤的選擇。嘗試將'flex-wrap:wrap'應用於'600px'媒體查詢(我在現場查看)中的'.div-main-container-seller-resources'。 –

+1

謝謝,這樣做!幾個小小的高度調整,現在看起來不錯。非常感謝!! –