如何将 flex-container 设置为其 flex-item 的宽度? [英] How do I set a flex-container to be the width of its flex-items?

查看:23
本文介绍了如何将 flex-container 设置为其 flex-item 的宽度?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个带有 justify-content: flex-start 的 flex 容器.由于 flex 项目占用的空间小于容器的大小,因此最终会在右侧溢出.

I have a flex container with justify-content: flex-start. There ends up being overflow on the right side due to the flex items taking less space than the size of the container.

除了在 flex-container 上设置显式宽度之外,有没有一种方法可以只使用 width: auto 的等效项来消除溢出?

Aside from setting an explicit width on the flex-container, is there a way of just having the equivalent of width: auto to remove the overflow?

推荐答案

如果你的意思是你想让容器成为项目的宽度,而不是项目扩展到容器宽度...

If you mean you want the container to be the width of the items, rather than the items expanding to the container width...

您可以通过将 display:flex 更改为 display:inline-flex

You may be able to get that by changing display:flex to display:inline-flex

这篇关于如何将 flex-container 设置为其 flex-item 的宽度?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆