水平滚动flex子级

编程入门 行业动态 更新时间:2024-10-10 01:18:42
本文介绍了水平滚动flex子级的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我一直在打乱网络,但似乎无法找到可行的解决方案.

I have been scowering the web, but can not seem to get a solution to work.

这是一个示例代码笔:

codepen.io/anon/pen/Wxjjqp

.container { display: flex; } .horizontally-scrolled-items { display: flex; background: lightblue; overflow-x: scroll; } .item { width: 1000px; border: 1px solid blue; }

html:

<div class="container"> <div class="horizontally-scrolled-items"> <div class="item">item1</div> <div class="item">item2</div> <div class="item">item3</div> </div> <div class="aside"> <button>keep me on screen</button> </div> </div>

这个想法是将水平滚动的项目设置为flex:1.如果这些项目大于容器的宽度,则可以滚动它们,将其放在视图中.

The idea is for horizntally-scrolled-items to be flex:1. If the items are greater than the width of the container, for them to scroll, leaving aside in the view.

推荐答案

您可以使用min-width来实现.给您的.item类一个min-width和一个flex-grow: 1;.然后将.horizontally-scrolled-items div设置为width: 100%;.

You can achieve this with min-width. Give your .item class a min-width with a flex-grow: 1;. Then set your .horizontally-scrolled-items div to width: 100%;.

CSS

.horizontally-scrolled-items { width: 100%; } .item { min-width: 400px; flex-grow: 1; }

CodePen

更多推荐

水平滚动flex子级

本文发布于:2023-11-23 04:20:02,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1620062.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:水平   flex

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!