html - CSS Flex,如何显示具有自定义顺序和水平滚动功能的列表

标签 html css flexbox

我尽量不在这上面使用 Javascript。我有一个宽度相同的盒子列表,但第一个 child 的高度不同;

我使用 flex 来连续显示列表,这样我就可以在框之间水平滚动。但在移动分辨率下,我希望 flex 将第一个元素放在顶行,其余元素放在第二行。

如果我将 flex-flow 设置为换行,我可以实现,但随后我松开了滚动。我能找到的最接近的东西是这个,但没有水平滚动。

Jsfiddle Demo approachCSS flex, how to display one item on first line and two on the next line

.section {
  display:flex;
  flex-flow: row nowrap;
  overflow-x: auto;
  overflow-y: hidden;
}

.home_box{
  flex: 0 0 auto;
  width:60%;
  height: 300px;
  background-color: #abc;
  margin: 20px;
}

.home_box:first-child{
  height: 600px;
}
<div class="section menu_section_1">
            <div class="home_box box_2"></div> 
            <div class="home_box box_2"></div>
            <div class="home_box box_2"></div>
            <div class="home_box box_2"></div>
            <div class="home_box box_2"></div>
            <div class="home_box box_2"></div>
</div>

最佳答案

尝试使用以下代码段。您可能需要调整 div 宽度内的第二部分,但您可以检查外部结构并应用媒体查询来实现您想要的。

.section {
  display: flex;
  flex-flow: row wrap;
  overflow-x: auto;
  overflow-y: hidden;
}

.second-section {
  display: flex;
  flex-flow: row nowrap;
  flex-grow:1;
}

.home_box {
  flex: 0 0 auto;
  width: 60%;
  height: 300px;
  background-color: #abc;
  margin: 20px;
}

.first-section {
  height: 600px;
}

@media (min-width: 576px) {
  .section {
    flex-flow: row nowrap;
  }
}
<div class="section menu_section_1">
  <div class="home_box box_2 first-section"></div>
  <div class="second-section">
    <div class="home_box box_2"></div>
    <div class="home_box box_2"></div>
    <div class="home_box box_2"></div>
    <div class="home_box box_2"></div>
    <div class="home_box box_2"></div>
  </div>
</div>

关于html - CSS Flex,如何显示具有自定义顺序和水平滚动功能的列表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51670852/

相关文章:

css - 调整图像大小使其居中

java - 在网络爬虫中解析 HTML

java 。 thymeleaf 。 CRUD 操作后,页面上的所有 .CSS 样式都会消失

html - Flexbox 100% 高度背景问题

html - 在 div 中显示部分背景图像的问题 - 页面的透明效果部分(html、css)

css - Bootstrap 中的图标行

html - Flexbox:水平和垂直居中

html - Bootstrap 中图标后内联显示的文本

html - 悬停时的 CSS 水平缩放图库中的单个图像

php - 如何让 UIKIT nav accordion 始终打开?