2017-10-30 4 views
1

アイコン、小さなヘッダー、および説明文を含む小さな「カード」を作ろうとしています。しかし、私のすべてのテキストが右隣の画像に一緒に実行されていますフレックスボックステキストが一緒に実行されています

enter image description here

任意の考え/提案を、なぜこれが起こっているのと?

.tool-grid { 
 
    padding: 0 1rem 1rem 0; 
 
    display: flex; 
 
    justify-content: flex-start; 
 
} 
 

 
.tool-grid a { 
 
    display: flex; 
 
    flex-direction: row; 
 
    flex: 0 1 35%; 
 
    border: 1px solid dimgrey; 
 
    border-radius: 3px; 
 
    text-decoration: none; 
 
    color: #000; 
 
} 
 

 
.tool-grid a:hover { 
 
    box-shadow: 3px 3px 5px #888; 
 
    transition: .3s; 
 
} 
 

 
.tool-grid-cell { 
 
    display: flex; 
 
    flex: 0 1 35%; 
 
    padding: 0 10px; 
 
    color: #000; 
 
} 
 

 
.tool-grid-cell img { 
 
    align-self: center; 
 
    max-width: 32px; 
 
    max-height: auto; 
 
}
<div class="tool-grid"> 
 
    <a href="#"> 
 
    <div class="tool-grid-cell"> 
 
     <img src="source"> 
 
     <p>Text</p> 
 
     <p>More text</p> 
 
    </div> 
 
    </a> 
 
</div>

答えて

0

デフォルトdisplay: flex;が水平にあなたが別のdivの中に自分の子要素の両方をラップする必要があり、これを防ぐために、デフォルトでは直接の子要素を整列させるためです。 Flexの動作は、2番目の子レベルを超えて何も拡張しません。

はdivの中にテキストをラップしてみてください。

<div class="tool-grid-cell"> 
    <img src="source"> 
    <div> 
     <p>Text</p> 
     <p>More text</p> 
    </div> 
</div> 
+0

感謝。ウィンドウが縮小し始めるまで、それは機能します。多分700pxマークの周りに、テキストは "ヘッダー"テキストのすぐ隣にジャンプします。それがメディアクエリーで解決されるかどうかはわかりません。 – DD1229

+0

私はあなたのCSSを上書きしている他のメディアクエリがあると思いますが、あなたが提供したスニペットからうまく機能しました – Vincent1989

+0

あなたは見ているものは確かではありませんが、テキストはすべて一緒に走っています。 – DD1229

0

一緒にコンテンツをプッシュするいくつかのことがあります。

  1. はすでにできる限りあなたはA-タグにdisplay:flexを必要としませんクラスtool-grid-cellでdivを使用して子を配置します。
  2. flex: 0 1 35%;は、aタグとtool-grid-cellの両方に使用します。この結果、aタグの内容は35%の幅しかなくなり、要素をいっしょに押し上げることになります。

また、space-betweenも追加しました。この要素は、コンテナ内にうまく配置され、探している結果を提供します。

.tool-grid { 
 
    padding: 0 1rem 1rem 0; 
 
    display: flex; 
 
    justify-content: flex-start; 
 
} 
 

 
.tool-grid a { 
 
    border: 1px solid dimgrey; 
 
    border-radius: 3px; 
 
    text-decoration: none; 
 
    color: #000; 
 
    width: 35%; 
 
} 
 

 
.tool-grid a:hover { 
 
    box-shadow: 3px 3px 5px #888; 
 
    transition: .3s; 
 
} 
 

 
.tool-grid-cell { 
 
    display: flex; 
 
    padding: 0 10px; 
 
    color: #000; 
 
    justify-content:space-between; 
 
} 
 

 
.tool-grid-cell img { 
 
    align-self: center; 
 
    max-width: 32px; 
 
    max-height: auto; 
 
}
<div class="tool-grid"> 
 
    <a href="#"> 
 
     <div class="tool-grid-cell"> 
 
      <img src="http://via.placeholder.com/50x50"> 
 
      <p>Text</p> 
 
      <p>More text</p> 
 
     </div> 
 
    </a> 
 
</div>

+0

Gotcha。私が探している結果は、イメージとヘッダーが互いに隣り合っていて、その下に説明テキストが並んでいる場所であることを明確にする必要があります。 – DD1229

+0

私はそれがスクリーンショットで所望の出力がどのようになるかはかなり明らかでした。 – DD1229

関連する問題