如果您正在使用Flexbox布局来排列一些行中的项目,则Flexbox容器将占用其所在容器的全部宽度。如何将Flexbox容器设置为仅占用其子元素的宽度?
请看以下示例:
有可能实现吗?
请看以下示例:
https://jsfiddle.net/5fr2ay9q/
在这个示例中,flexbox容器的大小超出了子元素的宽度。通常解决这种问题的方法是使用display:inline
,但显然这样做不起作用,因为那样就不再是flexbox容器了。有可能实现吗?
.container {
display: flex;
flex-direction: row;
outline: 1px solid red;
}
p {
outline: 1px solid blue;
}
Can you make the flex container not 100% width but rather the width of the content itself?
<div class='container'>
<img src='https://placehold.it/300x300'/>
<p>
This is some content hello world testing 123.
</p>
</div>