2016-03-23 12 views
3

私はHTMLとCSSが新しく、現在コーディングしているメニューに問題が発生しました。`justify-content`プロパティがネストされたフレックスボックスで動作しません

ネストフレックスボックスを使用してメニューを作成したいと思います。それは私が欲しいものに近づいていますが、私は理解できない理由で、子どもたちのフレキシボックス内のjustify-contentが適用されていないようです...ここで

は私のコードです:

header { 
 
    display: inline-flex; 
 
    height: 90px; 
 
    align-items: center; 
 
    justify-content: flex-start; 
 
} 
 
.avatar { 
 
    display: inline-flex; 
 
    height: inherit; 
 
    width: 200px; 
 
    background-color: #00D717; 
 
    align-items: center; 
 
    justify-content: space-around; 
 
} 
 
.avatar h1 { 
 
    font-size: 13px; 
 
    text-transform: uppercase; 
 
    color: white; 
 
} 
 
.resteHeader { 
 
    display: inline-flex; 
 
    height: inherit; 
 
    justify-content: flex-start; 
 
    align-items: center; 
 
} 
 
.resteHeader nav { 
 
    display: inline-flex; 
 
    height: inherit; 
 
    justify-content: space-around; 
 
    align-items: center; 
 
} 
 
.resteHeader nav ul { 
 
    display: inline-flex; 
 
    height: inherit; 
 
    justify-content: space-between; 
 
    align-items: center; 
 
}
<header> 
 
    <div class="avatar"> 
 
    <img src="img/avatar.png"> 
 
    <h1>Hoang Nguyen</h1> 
 
    </div> 
 
    <div class="resteHeader"> 
 
    <nav> 
 
     <ul> 
 
     <li> 
 
      <a href="#"> 
 
      <img src="img/silhouette.png" alt=""> 
 
      </a> 
 
     </li> 
 
     <li> 
 
      <a href="#"> 
 
      <img src="img/bulle.png" alt=""> 
 
      </a> 
 
     </li> 
 
     <li> 
 
      <a href="#"> 
 
      <img src="img/cloche.png" alt=""> 
 
      </a> 
 
     </li> 
 
     </ul> 
 
    </nav> 
 
    <img class="logo" src="img/logo.png" alt=""> 
 
    <form> 
 
     Type sor search 
 
     <input type="text"> 
 
     <img src="img/loupe.png" alt=""> 
 
    </form> 
 
    </div> 
 
</header>

ご協力いただきありがとうございます。

+0

?期待される結果は何ですか? – Oriol

+0

'' inline-flex''は、必要なだけ広い幅でコンテナを作ることを意味します。 'inline-flex'コンテナに' justify-content:space-around'を指定するのは意味がありません。(幅広い 'inline-flex'コンテナはそうではありません) – Adam

+0

はインラインでは使用しません-felxはdisplayを使う:flex; – DanyCode

答えて

1

display:inline-flexは、コンテナをインライン要素のように動作させることを意味します。

コンテナはまた、あなたのコード内でjustify-contentプロパティが正常に動作している幅(あなたdisplay:inline-flexコンテナの多くがそうでない)

2

を持っていない限り、それはdisplay:inline-flexコンテナ上justify-content: space-aroundを指定しても意味がありません。

display: inline-flexを使用しているため、フレックスコンテナの内容がコンテンツの幅と同じになります。justify-contentは配信する余分なスペースがありません。

display: flexを使用するか、width: 100%をルールに追加してみてください。

header { 
 
    display: inline-flex; 
 
    height: 90px; 
 
    align-items: center; 
 
    /* justify-content: flex-start; OFF FOR TESTING */ 
 
    justify-content: flex-end;   /* WORKING */ 
 
    width: 100%; 
 
} 
 

 
.avatar { 
 
    display: inline-flex; 
 
    height: inherit; 
 
    width: 200px; 
 
    background-color: #00D717; 
 
    align-items: center; 
 
    /* justify-content: space-around; OFF FOR TESTING */ 
 
    justify-content: flex-start;  /* WORKING */ 
 
} 
 

 
.avatar h1 { 
 
    font-size: 13px; 
 
    text-transform: uppercase; 
 
    color: white; 
 
} 
 

 
.resteHeader { 
 
    display: inline-flex; 
 
    height: inherit; 
 
    align-items: center; 
 
    /* justify-content: flex-start; OFF FOR TESTING */ 
 
    justify-content: space-between; /* WORKING */ 
 
    width: 100%; 
 
} 
 

 
.resteHeader nav { 
 
    display: inline-flex; 
 
    height: inherit; 
 
    align-items: center; 
 
    /* justify-content: space-around; OFF FOR TESTING */ 
 
    justify-content: center;   /* WORKING */ 
 
    width: 100%; 
 
} 
 

 
.resteHeader nav ul { 
 
    display: inline-flex; 
 
    height: inherit; 
 
    align-items: center; 
 
    /* justify-content: space-between; OFF FOR TESTING */ 
 
    width: 100%; 
 
}
<header> 
 
    <div class="avatar"> 
 
     <img src="img/avatar.png"> 
 
     <h1>Hoang Nguyen</h1> 
 
    </div> 
 

 
    <div class="resteHeader"> 
 
     <nav> 
 
      <ul> 
 
       <li> 
 
        <a href="#"><img src="img/silhouette.png" alt=""></a> 
 
       </li> 
 
       <li> 
 
        <a href="#"><img src="img/bulle.png" alt=""></a> 
 
       </li> 
 
       <li> 
 
        <a href="#"><img src="img/cloche.png" alt=""></a> 
 
       </li> 
 
      </ul> 
 
     </nav> 
 

 
     <img class="logo" src="img/logo.png" alt=""> 
 

 
     <form> 
 
      Type sor search 
 
      <input type="text"> 
 
      <img src="img/loupe.png" alt=""> 
 
     </form> 
 
    </div> 
 
</header>

コンテナ
+0

ご協力ありがとうございます! インラインフレックスの代わりにフレックスを使用してコードを修正しました。「width:100%;」を追加しました。ヘッダーに追加します。 –

+0

意図したとおりに作業していますか? –

+0

正確ではありません... resteHeaderフレックスボックスは正しく動作していません。ページ全体に拡張する必要があります。今は、アバターの直後(ちょうどうまくいく)、左の部分に押し込まれています。 (申し訳ありませんが、私の説明がわかりにくい場合は、英語は母国語ではありません)。 –

関連する問題