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

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

问题描述

我有一个带有 justify-content:flex-start 的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容器上设置显式宽度外,还有没有办法使 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

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

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