2017-07-11 5 views
3

Flexboxレイアウトを使用して行内のいくつかのアイテムをレイアウトする場合、Flexboxコンテナはそのコンテナの全幅を占有します。Flexboxコンテナは、それの子要素の幅ですか?フレックスボックスコンテナのサイズは、子要素の幅を超えて拡張するこの例ではフレックスボックスコンテナをコンテンツサイズに縮小

https://jsfiddle.net/5fr2ay9q/

は、次の例を見てみましょう。このようなものを修正する典型的な方法はdisplay: inlineですが、これはフレックスボックスコンテナではないため、動作しないことは明らかです。

これは可能ですか?

.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>

+0

私は、ディスプレイ間の[差分の重複として質問をマーキングに反対:inline- flexとdisplay:flex](https://stackoverflow.com/questions/2741810) 4/display-display-flex-displayflexの違い)。それはまったく異なる質問です。質問者は、インラインフレックスが "どうしたらいいですか?"質問をする前に質問に対する回答を既に知っていない限り、質問はありません。 – Daryn

答えて

2

あなたは(Designating a Flexible Boxを参照)display: inline-flex;を使用することができます。

.container { 
 
    display: inline-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>

+0

うわー「inline-flex」について私はどのように知りませんでしたか?これは標準のフレックスボックス機能ですか?私はそれについて読んだことさえありません。 –

+0

そうです。 **これはあなたがするまで**必要なのですか? –

関連する問題