WEBデザイン基礎(7)Bootstrap(3)

画像1

カード(Cards)を作ろう。

画像2

商品を写真やキャプションを使って紹介したいときに便利なカードを作ってみましょう。
カードには、いろいろなスタイルを選べますが、以下のコードは、上の画像のような、写真、タイトル、説明文、ボタンが入ったものです。

<div class="card" style="width:15rem;">
<img src="cake.png" class="img-fluid" alt="チーズケーキ">
 <div class="card-body">
   <h5 class="card-title">スフレチーズケーキ</h5>
   <p class="card-text">シンプルな材料を熟練の技術で焼き上げたやわらかい触感のチーズケーキです。</p>
   <a href="#" class="btn btn-primary">お店へ行く</a>
 </div>
</div>

演習 カードをカスタマイズしてみよう。

以下にカードの様々なスタイル、使用方法が書かれています。
写真を入れ替えたり、色を変更して、カードをカスタマイズしよう。

応用 Masonryのようなカードのレイアウト

画像3

Masonryのようなカードの整列もできます。つまり、高さが違う大きさのカードでも石積みのように積み上げていくようなレイアウトができます。
以下は参考コードとファイルです。

<div class="card-columns">
 <div class="card">
   <svg class="bd-placeholder-img card-img-top" width="100%" height="160" xmlns="http://www.w3.org/2000/svg" preserveAspectRatio="xMidYMid slice" focusable="false" role="img" aria-label="Placeholder: Image cap"><title>Placeholder</title><rect width="100%" height="100%" fill="#868e96"/><text x="50%" y="50%" fill="#dee2e6" dy=".3em">Image cap</text></svg>
   <div class="card-body">
     <h5 class="card-title">Card title that wraps to a new line</h5>
     <p class="card-text">This is a longer card with supporting text below as a natural lead-in to additional content. This content is a little bit longer.</p>
   </div>
 </div>
 <div class="card p-3">
   <blockquote class="blockquote mb-0 card-body">
     <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Integer posuere erat a ante.</p>
     <footer class="blockquote-footer">
       <small class="text-muted">
         Someone famous in <cite title="Source Title">Source Title</cite>
       </small>
     </footer>
   </blockquote>
 </div>
 <div class="card">
   <svg class="bd-placeholder-img card-img-top" width="100%" height="160" xmlns="http://www.w3.org/2000/svg" preserveAspectRatio="xMidYMid slice" focusable="false" role="img" aria-label="Placeholder: Image cap"><title>Placeholder</title><rect width="100%" height="100%" fill="#868e96"/><text x="50%" y="50%" fill="#dee2e6" dy=".3em">Image cap</text></svg>
   <div class="card-body">
     <h5 class="card-title">Card title</h5>
     <p class="card-text">This card has supporting text below as a natural lead-in to additional content.</p>
     <p class="card-text"><small class="text-muted">Last updated 3 mins ago</small></p>
   </div>
 </div>
 <div class="card bg-primary text-white text-center p-3">
   <blockquote class="blockquote mb-0">
     <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Integer posuere erat.</p>
     <footer class="blockquote-footer text-white">
       <small>
         Someone famous in <cite title="Source Title">Source Title</cite>
       </small>
     </footer>
   </blockquote>
 </div>
 <div class="card text-center">
   <div class="card-body">
     <h5 class="card-title">Card title</h5>
     <p class="card-text">This card has a regular title and short paragraphy of text below it.</p>
     <p class="card-text"><small class="text-muted">Last updated 3 mins ago</small></p>
   </div>
 </div>
 <div class="card">
   <svg class="bd-placeholder-img card-img" width="100%" height="260" xmlns="http://www.w3.org/2000/svg" preserveAspectRatio="xMidYMid slice" focusable="false" role="img" aria-label="Placeholder: Card image"><title>Placeholder</title><rect width="100%" height="100%" fill="#868e96"/><text x="50%" y="50%" fill="#dee2e6" dy=".3em">Card image</text></svg>
 </div>
 <div class="card p-3 text-right">
   <blockquote class="blockquote mb-0">
     <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Integer posuere erat a ante.</p>
     <footer class="blockquote-footer">
       <small class="text-muted">
         Someone famous in <cite title="Source Title">Source Title</cite>
       </small>
     </footer>
   </blockquote>
 </div>
 <div class="card">
   <div class="card-body">
     <h5 class="card-title">Card title</h5>
     <p class="card-text">This is another card with title and supporting text below. This card has some additional content to make it slightly taller overall.</p>
     <p class="card-text"><small class="text-muted">Last updated 3 mins ago</small></p>
   </div>
 </div>
</div>

演習 Masonryのようなレイアウトをカスタマイズしてみよう。

カードの高さを変えて、ブラウザで表示のされ方を確認してみよう。

以下参考サイト


この記事が気に入ったらサポートをしてみませんか?