【问题标题】:Why does my right hand flex column suddenly drop below a left column?为什么我的右手 flex 列突然下降到左列下方?
【发布时间】:2019-08-13 06:04:58
【问题描述】:

添加(流动)内容后,为什么我的右手 flex 列突然下降到左列下方?

我想要一个固定宽度的左列和一个包含图像滑块的右列 (Owl Carousel)。

列布局在空时可以正常工作,但是一旦我添加图像滑块,列就会跳到 100% 宽度并下降到固定列之下。这很奇怪,因为滑块是响应式的,并且不应扩展超出其容器 - 它不是固定宽度。

请看这个codepen:https://codepen.io/nick-gilbert/pen/wORaOP

我的基本列布局很简单:

<div class="row">

   <div class="col search-sidebar">
      left
   </div>

   <div class="col">
      right
  </div>

</div>

CSS:

.search-sidebar: {
  flex: 0 0 260px;
}

这是显示问题的图像(但最好查看 codepen):

【问题讨论】:

    标签: css html flexbox bootstrap-4


    【解决方案1】:

    在行元素上添加flex-nowrap 类。

    默认情况下,行是 flex-wrap:wrap,所以当内容大于宽度时,div 会堆叠起来。为避免它们堆积,请使用flex-nowrap 引导类。

    查看更新后的codepen

    <div class="container">
    
      <div class="row" style="margin-bottom:40px;">
        <div class="col search-sidebar" style="background-color:aquamarine">left</div>
    
        <div class="col" style="margin-bottom:20px;background-color:pink">right<br /> (works when empty)
        </div>
      </div>
    
      <div class="row flex-nowrap">
    
        <div class="col search-sidebar" style="background-color:aquamarine">
          left<br><br>
        </div>
    
        <div class="col" style="margin-bottom:20px;background-color:pink">
          right<br />Broken when an Image slider loads. This should stay to the right of the green column.
          <br />
    
          <!--  Demos -->
          <div id="imageCarousel">
            <div id="imageThumbnails" class="owl-carousel owl-theme">
    
              <div class="sliderThumb rounded">
                <a class="galleryLink" rel="Group" href='#'>
                                <img src='http://placehold.it/160x160' width="175" height="175" />
                            </a>
              </div>
    
              <div class="sliderThumb rounded">
                <a class="galleryLink" rel="Group" href='#'>
                                <img src='http://placehold.it/160x160' width="175" height="175"  />
                            </a>
              </div>
              <div class="sliderThumb rounded">
                <a class="galleryLink" rel="Group" href='#'>
                                <img src='http://placehold.it/160x160' width="175" height="175" />
                            </a>
              </div>
    
              <div class="sliderThumb rounded">
                <a class="galleryLink" rel="Group" href='#'>
                                <img src='http://placehold.it/160x160' width="175" height="175"  />
                            </a>
              </div>
              <div class="sliderThumb rounded">
                <a class="galleryLink" rel="Group" href='#'>
                                <img src='http://placehold.it/160x160' width="175" height="175" />
                            </a>
              </div>
    
              <div class="sliderThumb rounded">
                <a class="galleryLink" rel="Group" href='#'>
                                <img src='http://placehold.it/160x160' width="175" height="175"  />
                            </a>
              </div>
              <div class="sliderThumb rounded">
                <a class="galleryLink" rel="Group" href='#'>
                                <img src='http://placehold.it/160x160' width="175" height="175" />
                            </a>
              </div>
    
              <div class="sliderThumb rounded">
                <a class="galleryLink" rel="Group" href='#'>
                                <img src='http://placehold.it/160x160' width="175" height="175"  />
                            </a>
              </div>
              <div class="sliderThumb rounded">
                <a class="galleryLink" rel="Group" href='#'>
                                <img src='http://placehold.it/160x160' width="175" height="175" />
                            </a>
              </div>
    
              <div class="sliderThumb rounded">
                <a class="galleryLink" rel="Group" href='#'>
                                <img src='http://placehold.it/160x160' width="175" height="175"  />
                            </a>
              </div>
    
            </div>
          </div>
        </div>
    
      </div>
      <!-- end row -->
    
    </div>
    

    【讨论】:

    • 谢谢!演示现在运行良好,但不幸的是我的实际问题有一个新问题,即 flex 列仍然太宽:venuefinder.staging.x-rm.com(粉色列不应该那么宽)
    • 让我检查一下并回复你
    • min-width:0 添加到包含猫头鹰轮播的col,了解为什么请参阅thisthis
    • 我猜@kukkuz 说的很有道理。你可以随它去。我试过了,它对我有用
    • 对不起 - 我这边的“用户错误”。它现在正在工作!非常感谢你们!
    猜你喜欢
    • 1970-01-01
    • 2018-06-15
    • 2023-03-20
    • 1970-01-01
    • 2019-12-06
    • 2021-02-28
    • 1970-01-01
    • 1970-01-01
    • 2017-02-12
    相关资源
    最近更新 更多