【问题标题】:Two Side-by-Side Divs - Adding Responsiveness两个并排的 div - 增加响应性
【发布时间】:2018-02-07 04:28:11
【问题描述】:

我有两个并排的 div,但似乎不知道如何使它们响应。

在 600 像素或更低的地方寻找右框在左框下方,保持我在 div 内完成的所有其他居中。

每个并排的 div 分别具有 .div-seller-resources-left 和 .div-seller-resources-right 类。

我已经为每个文本框的高度使用了 600 像素的媒体屏幕,所以我也将使用 600 作为断点。

附上它在正常尺寸浏览器中的作用的照片,以及它在较小屏幕上的样子。如您所知,较小的屏幕会尽可能地压缩以将所有内容都放在一个页面上。

/* 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>

【问题讨论】:

  • 可以添加 flex-wrap: wrap;进入媒体查询之外的 .seller-resources-inner{} 并且它应该可以工作,但是如果您想要更具体,请在媒体查询中尝试它
  • 您能否改进问题以描述您想要实现的目标。据我所见,这 2 个 div 是并排的。是不是想让 2 个并排 div 的标题占据相同的垂直空间?
  • 嗨,Martin Joiner,它们在全屏时看起来是我喜欢的样子,但在较小的屏幕上,我希望将并排的 div 堆叠起来。

标签: html css responsive


【解决方案1】:

我建议使用flex-wrap 属性。在这种情况下,您可以强制将元素放入单个列中。 (见MDN Docs)

只需将flex-wrap: wrap; 应用于.seller-resources-inner 类(参见下面的sn-p)。

/* 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>

【讨论】:

  • 感谢您的信息,拉米兹!这似乎是正确的道路。但是,它们仍然并排放置(不要堆叠)在较小的屏幕上。也许是因为 div 能够缩小到足够小而不会触发堆栈?看直播去yodega.com/seller-resources
  • @JacobJordan 嗯,我认为问题出在错误的选择器上。尝试将flex-wrap: wrap 应用于.div-main-container-seller-resources 内的600px 媒体查询(我检查了现场)。
  • 谢谢,成功了!一些小的高度调整,现在看起来很棒。非常感谢!!
猜你喜欢
  • 2020-09-23
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-10-06
  • 2017-02-06
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多