Bootstrapのレスポンシブ テンプレート
はじめに
- すぐにコピペで動かせるようにBootstrapはCDN(
<link>
と</body>
前のjqueryとかの<script>
)にしました。 - スタイルの部分は、ファイルを作って移したりしてください。
- 公式サイトのカードのサンプルを動かすとカードが崩れるのでwidthを指定しました。
注意
Classのcardのサイズを指定し辛い
クラスのcardはBootstrapに定義されている名前なので
無理やりサイズを変更できず、[width]を指定しても無駄でした。
なので[min-width]と[max-width]を指定することで
少しの変化だけにすることができます。
変化させない方法もありますがそれだと余白がとても大きくなるため
ほんの少し、変化させるようにしました。
ソースコード
bootstrap.html
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<title>Bootstrap_test</title>
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" integrity="sha384-MCw98/SFnGE8fJT3GXwEOngsV7Zt27NXFoaoApmYm81iuXoPkFOJwJ8ERdknLPMO" crossorigin="anonymous">
<style>
.header {
background: #a29bfe;
text-align: center;
}
.card {
min-width: 220px;
max-width: 270px;
margin-bottom: 10px !important;
margin: auto;
}
.sidebar {
min-height: 500px;
}
</style>
</head>
<body>
<h1 class="header">Bootstrap_test</h1>
<div class="container">
<div class="row">
<div class="col-lg-9 col-md-12" style="background-color: #ff7675;">col-lg-9 col-md-12<br>
<div class="card-deck">
<div class="card" style="width: 250px;">
<div class="card-img-top" style="height: 220px; background: #aaa;"></div>
<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 class="card" style="width: 250px;">
<div class="card-img-top" style="height: 220px; background: #aaa;"></div>
<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 class="card" style="width: 250px;">
<div class="card-img-top" style="height: 220px; background: #aaa;"></div>
<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 class="card" style="width: 250px;">
<div class="card-img-top" style="height: 220px; background: #aaa;"></div>
<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="sidebar col-lg-3" style="background-color: #74b9ff;">col-lg-3</div>
</div>
</div>
<!-- Bootstrap jquery-->
<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.3/umd/popper.min.js" integrity="sha384-ZMP7rVo3mIykV+2+9J3UJ46jBk0WLaUAdn689aCwoqbBJiSnjAK/l8WvCWPIPm49" crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/js/bootstrap.min.js" integrity="sha384-ChfqqxuZUCnJSK3+MXmPNIyE6ZbWh2IMqE241rYiqJxyMiZ6OW/JmZQ5stwEULTy" crossorigin="anonymous"></script>
</body>
</html>