2016-06-21 14 views
1

私はそれがまったく見当たりませんが、フレックスボックスのように見えるような私のテキストには問題があります。フレックスボックスには3つのイメージがありますが、それぞれの下に小さな「キャプション」を配置したいと思います(p要素ではなく、紫色ですが、私は白の上に置きます。紫色のボックス(p要素)。私は、子要素を追加することによって、その要素が少なくともそれより上の要素と垂直に並んでいると思っていましたが、間違っていると思います。画像は250個のピクセルですが、私はそれ50個のピクセルを作ったので、私は、スニペットに対処したかったが、それはおそらく無関係です。フレックスボックスのテキストを写真の下に配置する

#footer { 
 
    display: flex; 
 
    height: 130px; 
 
    width: 100%; 
 
    background-color: #862d59; 
 
    clear: both; 
 
} 
 

 
#footer, #wrapper:after{ 
 
    height: 130px; 
 
} 
 

 
.wrap { 
 
    margin: 0 auto; 
 
    width: 100%; 
 
    display: flex; 
 
    align-items: center; 
 
    flex-wrap: nowrap; 
 
} 
 

 
.sub { 
 
    padding: 12px; 
 
    width: 32%; 
 
    height: 100px; 
 
    color: white; 
 
    border-right: solid white 1px; 
 
} 
 

 
.sub:last-child { 
 
    border: 0px; 
 
} 
 

 
html { 
 
    height: 100%; 
 
} 
 

 
body { 
 
    height: 100%; 
 
    margin:0; 
 
    font-family: courier; 
 
    font-size: 22px; 
 
    color: white; 
 
} 
 

 
#wrapper { 
 
    position: relative; 
 
    margin-left: auto; 
 
    margin-right: auto; 
 
    width: 85%; 
 
    min-height: 100%; 
 
    margin-top: -130px; 
 
} 
 

 
#inner { 
 
    position:absolute; 
 
    display:flex; 
 
    flex-wrap: wrap; 
 
    height: 600px; 
 
    top:50%; 
 
    align-items: center; 
 
    justify-content: space-between; 
 
    margin-top: -300px; 
 
    align-content: center; 
 
    width: 100%; 
 
} 
 

 
#inner p { 
 
    background-color: #26004d; 
 
    padding: 60px; 
 
    border-radius: 9px; 
 
} 
 

 
#inner img { 
 
    border-radius: 8px; 
 
}
<div id="wrapper"> 
 
    <div id="inner"> 
 
    <p><img src="cat1.jpeg" alt="Picture of a cat" width="50" height="50"></p> 
 
    <p><img src="dog1.jpg" alt="Picture of a cat" width="50" height="50"></p> 
 
    <p><img src="park.jpg" alt="Picture of a cat" width="50" height="50"></p> 
 
    </div> 
 
</div> 
 
<div id="footer"> 
 
    <div class="wrap"> 
 
    <div class="sub"></div> 
 
    <div class="sub"></div> 
 
    <div class="sub"></div> 
 
    </div> 
 
</div>
追加情報/画像なし

+0

達成しようとしているもののスクリーンショットを追加します。現在、少し不明です(特にスニペットを見て)。プレースホルダ画像を使用してスニペットでレイアウトを一致させることもできます:https://placehold.it/ –

+0

テキストを配置し、各p要素の下に(各紫色のボックスの下に)配置します。したがって、テキストは紫色の外側にありますが、各p要素の下に中心があります。それは完全に紫色の外にあるが、各箱のすぐ下にあるように。このように https://snag.gy/LtCew1.jpg –

答えて

1

、ここsolutioですn私は思い付くことができた。各画像/キャプションをまとめてグループ化したい場合は、別の親にまとめてくださいdiv。次に、その下にあるキャプション(block要素)を追加し、画像の下に意図したとおりに表示する必要があります。以下のスニペット。

#footer { 
 
    display: flex; 
 
    height: 130px; 
 
    width: 100%; 
 
    background-color: #862d59; 
 
    clear: both; 
 
} 
 

 
#footer, #wrapper:after{ 
 
    height: 130px; 
 
} 
 

 
.wrap { 
 
    margin: 0 auto; 
 
    width: 100%; 
 
    display: flex; 
 
    align-items: center; 
 
    flex-wrap: nowrap; 
 
} 
 

 
.sub { 
 
    padding: 12px; 
 
    width: 32%; 
 
    height: 100px; 
 
    color: white; 
 
    border-right: solid white 1px; 
 
} 
 

 
.sub:last-child { 
 
    border: 0px; 
 
} 
 

 
html { 
 
    height: 100%; 
 
} 
 

 
body { 
 
    height: 100%; 
 
    margin:0; 
 
    font-family: courier; 
 
    font-size: 22px; 
 
    color: white; 
 
} 
 

 
#wrapper { 
 
    position: relative; 
 
    margin-left: auto; 
 
    margin-right: auto; 
 
    width: 85%; 
 
    min-height: 100%; 
 
} 
 

 
#inner { 
 
    position:absolute; 
 
    display:flex; 
 
    flex-wrap: wrap; 
 
    height: 600px; 
 
    top:50%; 
 
    align-items: center; 
 
    justify-content: space-between; 
 
    margin-top: -300px; 
 
    align-content: center; 
 
    width: 100%; 
 
} 
 

 
#inner p { 
 
    background-color: #26004d; 
 
    padding: 60px; 
 
    border-radius: 9px; 
 
} 
 

 
#inner p.caption { 
 
    color: #000; 
 
    background-color: transparent; 
 
    border-radius: 0; 
 
} 
 

 
#inner img { 
 
    display: block; 
 
    border-radius: 8px; 
 
}
<div id="wrapper"> 
 
    <div id="inner"> 
 
    <div class="image-wrapper"> 
 
     <p> 
 
     <img src="http://placehold.it/100x100" alt="Picture of a cat"> 
 
     </p> 
 
     <p class="caption">Caption</p> 
 
    </div> 
 
    <div class="image-wrapper"> 
 
     <p> 
 
     <img src="http://placehold.it/100x100" alt="Picture of a cat"> 
 
     </p> 
 
     <p class="caption">Caption</p> 
 
    </div> 
 
    <div class="image-wrapper"> 
 
     <p> 
 
     <img src="http://placehold.it/100x100" alt="Picture of a cat"> 
 
     </p> 
 
     <p class="caption">Caption</p> 
 
    </div> 
 
    </div> 
 
</div> 
 
<div id="footer"> 
 
    <div class="wrap"> 
 
    <div class="sub"></div> 
 
    <div class="sub"></div> 
 
    <div class="sub"></div> 
 
    </div> 
 
</div>

ご質問があれば私に教えてください、またはこれはあなたの説明を満たしていない場合。

+0

ありがとうございます。残念なことに、高さは適応できるはずだが、フレックスボックスを破ったのだろうか、なぜそれがそれをしているのかは分からない。しかし、ここで私が得ているものは次のとおりです。https://snag.gy/fPJXdz.jpg フレックスボックスを一枚にしてキャプションを追加する方法があまりにもわかりません。 –

+0

Hmm、odd。 'フレックスボックス'が100%必要でない場合(レスキュー画面で写真の順序を並べ替えていない場合)、3つの項目すべてを 'li'の子要素として 'display:inline-おそらくあなたがそこに見ているすべての問題を避けることができます。 'Flexbox'は現時点では少し揮発性であり、より多くのクロスブラウザにも対応している試行錯誤した方法を使う方が簡単です。 –

+0

ありがとう、私はそれを行ってくれます。 –

関連する問題