神戸学院大学 経営学部 林坂ゼミ

HTML 入門トップページ

« 戻る 次へ »

Bootstrap によるレスポンシブ Web デザイン

カードを配置する

ここではカードを配置します.これも Bootstrap のページからコードをコピーして貼り付けるだけで簡単に配置できます.貼り付けたあとに画像の srcalt 属性は指定しましょう.

index.html(抜粋)<div class="card" style="width: 18rem;">
  <img src="ink.png" class="card-img-top" alt="ink">
  <div class="card-body">
    <h5 class="card-title">Card title</h5>
    <p class="card-text">Some quick example text to build on the card title and make up the bulk of the card's content.</p>
    <a href="#" class="btn btn-primary">Go somewhere</a>
  </div>
</div>

ブラウザでの表示結果

ink
Card title

Some quick example text to build on the card title and make up the bulk of the card's content.

Go somewhere

ここで説明したグリッドシステムと組み合わせると,スマートフォンでは4つのカードが縦に並び,PC 等の幅の広いブラウザでは2行2列に配置されるようにできます.コードが少し長くなって見にくいですが,row の中に2つの col-md-6 があり,その col-md-6 一つひとつの中にさらに card が配置されているという構造になっていることを確認してください.なおカードの幅は 18rem から 14rem に調整しています.

index.html(抜粋)<div class="row">
  <div class="col-md-6">
    <div class="card" style="width: 14rem;">
      <img src="ink.png" class="card-img-top" alt="ink">
      <div class="card-body">
        <h5 class="card-title">Card title</h5>
        <p class="card-text">Some quick example text to build on the card title and make up the bulk of the card's content.</p>
        <a href="#" class="btn btn-primary">Go somewhere</a>
      </div>
    </div>
  </div>
  <div class="col-md-6">
    <div class="card" style="width: 14rem;">
      <img src="ink.png" class="card-img-top" alt="ink">
      <div class="card-body">
        <h5 class="card-title">Card title</h5>
        <p class="card-text">Some quick example text to build on the card title and make up the bulk of the card's content.</p>
        <a href="#" class="btn btn-primary">Go somewhere</a>
      </div>
    </div>
  </div>
</div>
<div class="row">
  <div class="col-md-6">
    <div class="card" style="width: 14rem;">
      <img src="ink.png" class="card-img-top" alt="ink">
      <div class="card-body">
        <h5 class="card-title">Card title</h5>
        <p class="card-text">Some quick example text to build on the card title and make up the bulk of the card's content.</p>
        <a href="#" class="btn btn-primary">Go somewhere</a>
      </div>
    </div>
  </div>
  <div class="col-md-6">
    <div class="card" style="width: 14rem;">
      <img src="ink.png" class="card-img-top" alt="ink">
      <div class="card-body">
        <h5 class="card-title">Card title</h5>
        <p class="card-text">Some quick example text to build on the card title and make up the bulk of the card's content.</p>
        <a href="#" class="btn btn-primary">Go somewhere</a>
      </div>
    </div>
  </div>
</div>

ブラウザでの表示結果

ink
Card title

Some quick example text to build on the card title and make up the bulk of the card's content.

Go somewhere
ink
Card title

Some quick example text to build on the card title and make up the bulk of the card's content.

Go somewhere
ink
Card title

Some quick example text to build on the card title and make up the bulk of the card's content.

Go somewhere
ink
Card title

Some quick example text to build on the card title and make up the bulk of the card's content.

Go somewhere

目次に戻る