Bootstrap Theme "The Band"

❮ 前章へ 次章へ ❯

作成テーマ: "The Band"

このページでは、ゼロからブートストラップのテーマを作成する方法を示します。

単純な HTML ページから開始して、次に、完全に機能的で、個人的でレスポンシブなウェブサイトになるまで、 多くのコンポーネントを追加します。

結果は次のようになります。これの変更、保存、共有、利用などは全てフリーです:

Full Page Demo Full Source Code

HTML 最初のページ

次の HTML ページからスタートします:

<!DOCTYPE html>
<html lang="en">
<head>
  <title>Bootstrap Theme The Band</title>
  <meta charset="utf-8">
</head>
<body>

<div>
  <h3>THE BAND</h3>
  <p>We love music!</p>
  <p>We have created a fictional band website. Lorem ipsum..</p>
</div>

</body>
</html>

Bootstrap CDN とコンテナの追加

Bootstrap CDN と jQuery へのリンクを追加し、HTML 要素をコンテナ(.container)内に配置します:

<!DOCTYPE html>
<html lang="en">
<head>
  <title>Bootstrap Theme The Band</title>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
  <script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
</head>
<body>

<div class="container">
  <h3>THE BAND</h3>
  <p>We love music!</p>
  <p>We have created a fictional band website. Lorem ipsum..</p>
</div>

</body>
</html>

結果:

THE BAND

We love music!

We have created a fictional band website. Lorem ipsum..

Try it Yourself »

テキストの中央揃え

コンテナ内のテキストを中央揃えにするため .text-center クラスを追加し、 テキスト "We love music" をイタリック体にするため <em> 要素を使います:

<div class="container text-center">
  <h3>THE BAND</h3>
  <p><em>We love music!</em></p>
  <p>We have created a fictional band website. Lorem ipsum..</p>
</div>

結果:

THE BAND

We love music!

We have created a fictional band website. Lorem ipsum..

Try it Yourself »

パディングを追加

パディングでコンテナの見映えを良くするため CSS を使います:

.container {
    padding: 80px 120px;
}

結果:

THE BAND

We love music!

We have created a fictional band website. Lorem ipsum..

Try it Yourself »

グリッドを追加

3 つの等幅なカラム (.col-sm-4) を作成し、テキストとイメージを追加してコンテナ内に配置します:

<div class="container text-center">
  <h3>THE BAND</h3>
  <p><em>We love music!</em></p>
  <p>We have created a fictional band website. Lorem ipsum..</p>
  <br>
  <div class="row">
    <div class="col-sm-4">
      <p><strong>Name</strong></p><br>
      <img src="bandmember.jpg" alt="Random Name">
    </div>
    <div class="col-sm-4">
      <p><strong>Name</strong></p><br>
      <img src="bandmember.jpg" alt="Random Name">
    </div>
    <div class="col-sm-4">
      <p><strong>Name</strong></p><br>
      <img src="bandmember.jpg" alt="Random Name">
    </div>
  </div>
</div>

結果:

THE BAND

We love music!

We have created a fictional band website. Lorem ipsum..


Name


Random Name

Name


Random Name

Name


Random Name
Try it Yourself »

画像を円形に

.img-circle クラスにより画像の形を円形にします。

画像をもっと見映え良くするために、CSS を幾つか追加します:

.person {
    border: 10px solid transparent;
    margin-bottom: 25px;
    width: 80%;
    height: 80%;
    opacity: 0.7;
}
.person:hover {
    border-color: #f1f1f1;
}

<img src="bandmember.jpg" class="img-circle person" alt="Random Name">
<img src="bandmember.jpg" class="img-circle person" alt="Random Name">
<img src="bandmember.jpg" class="img-circle person" alt="Random Name">

結果:

Name


Random Name

Name


Random Name

Name


Random Name
Try it Yourself »

折畳み

画像を折畳み可能にします;各画像をクリックすると、隠れたコンテンツを表示します:

<div class="row">
  <div class="col-sm-4">
    <p class="text-center"><strong>Name</strong></p><br>
    <a href="#demo" data-toggle="collapse">
      <img src="bandmember.jpg" class="img-circle person" alt="Random Name">
    </a>
    <div id="demo" class="collapse">
      <p>Guitarist and Lead Vocalist</p>
      <p>Loves long walks on the beach</p>
      <p>Member since 1988</p>
    </div>
  </div>
  <div class="col-sm-4">
    <p class="text-center"><strong>Name</strong></p><br>
    <a href="#demo2" data-toggle="collapse">
      <img src="bandmember.jpg" class="img-circle person" alt="Random Name">
    </a>
    <div id="demo2" class="collapse">
      <p>Drummer</p>
      <p>Loves drummin'</p>
      <p>Member since 1988</p>
    </div>
  </div>
  <div class="col-sm-4">
    <p class="text-center"><strong>Name</strong></p><br>
    <a href="#demo3" data-toggle="collapse">
      <img src="bandmember.jpg" class="img-circle person" alt="Random Name">
    </a>
    <div id="demo3" class="collapse">
      <p>Bass player</p>
      <p>Loves math</p>
      <p>Member since 2005</p>
    </div>
  </div>
</div>

Result (click on the images to see the effect):

Name


Random Name

Guitarist and Lead Vocalist

Loves long walks on the beach

Member since 1988

Name


Random Name

Drummer

Loves drummin'

Member since 1988

Name


Random Name

Bass player

Loves math

Member since 2005

Try it Yourself »

カルーセルを追加

カルーセルを作成し、コンテナの前に追加します:

<div id="myCarousel" class="carousel slide" data-ride="carousel">
  <!-- Indicators -->
  <ol class="carousel-indicators">
    <li data-target="#myCarousel" data-slide-to="0" class="active"></li>
    <li data-target="#myCarousel" data-slide-to="1"></li>
    <li data-target="#myCarousel" data-slide-to="2"></li>
  </ol>

  <!-- Wrapper for slides -->
  <div class="carousel-inner" role="listbox">
    <div class="item active">
      <img src="ny.jpg" alt="New York">
      <div class="carousel-caption">
        <h3>New York</h3>
        <p>The atmosphere in New York is lorem ipsum.</p>
      </div>
    </div>

    <div class="item">
      <img src="chicago.jpg" alt="Chicago">
      <div class="carousel-caption">
        <h3>Chicago</h3>
        <p>Thank you, Chicago - A night we won't forget.</p>
      </div>
    </div>

    <div class="item">
      <img src="la.jpg" alt="Los Angeles">
      <div class="carousel-caption">
        <h3>LA</h3>
        <p>Even though the traffic was a mess, we had the best time.</p>
      </div>
    </div>
  </div>

  <!-- Left and right controls -->
  <a class="left carousel-control" href="#myCarousel" role="button" data-slide="prev">
    <span class="glyphicon glyphicon-chevron-left" aria-hidden="true"></span>
    <span class="sr-only">前章へ</span>
  </a>
  <a class="right carousel-control" href="#myCarousel" role="button" data-slide="next">
    <span class="glyphicon glyphicon-chevron-right" aria-hidden="true"></span>
    <span class="sr-only">Next</span>
  </a>
</div>

結果:

Try it Yourself »

カルーセルをスタイル

カルーセルのスタイルに CSS を使用します:

.carousel-inner img {
    -webkit-filter: grayscale(90%);
    filter: grayscale(90%); /* make all photos black and white */
    width: 100%; /* Set width to 100% */
    margin: auto;
}

.carousel-caption h3 {
    color: #fff !important;
}

@media (max-width: 600px) {
    .carousel-caption {
        display: none; /* Hide the carousel text when the screen is less than 600 pixels wide */
    }
}

結果:

Try it Yourself »

ツアー用のコンテナを追加

新規にコンテナを追加し、その中にリスト (.list-group.list-group-item) を追加します。

コンテナに、カスタムクラス (.bg-1) を追加し (黒の背景色)、その子に幾つかのスタイルを設定します:

<style>
.bg-1 {
    background: #2d2d30;
    color: #bdbdbd;
}
.bg-1 h3 {color: #fff;}
.bg-1 p {font-style: italic;}
</style>

<div class="bg-1">
  <div class="container">
    <h3 class="text-center">TOUR DATES</h3>
    <p class="text-center">Lorem ipsum we'll play you some music.<br> Remember to book your tickets!</p>

    <ul class="list-group">
      <li class="list-group-item">September Sold Out!</li>
      <li class="list-group-item">October Sold Out!</li>
      <li class="list-group-item">November 3</li>
    </ul>
  </div>
</div>

結果:

TOUR DATES

Lorem ipsum we'll play you some music.
Remember to book your tickets!

Try it Yourself »

ラベルとバッジを追加

tickets/sold out をハイライト出来るようにラベル (.label) とバッジ (.badge) を追加します:

<ul class="list-group">
  <li class="list-group-item">September <span class="label label-danger">Sold Out!</span></li>
  <li class="list-group-item">October <span class="label label-danger">Sold Out!</span></li>
  <li class="list-group-item">November <span class="badge">3</span></li>
</ul>

結果:

TOUR DATES

Lorem ipsum we'll play you some music.
Remember to book your tickets!

Try it Yourself »

サムネイル画像を追加

ツアーコンテナ内に、3 つの等幅カラム (.col-sm-4) を追加します:

各カラム内に画像を追加します。

次に、画像をサムネイルの形にするため、.img-thumbnail クラスを使用します。

通常は、<img> 要素に直接 .img-thumbnail クラスを追加します。 この例では、画像のテキストも指定できるように、画像を囲むように thumbnail コンテナを配置しています。

<div class="row text-center">
  <div class="col-sm-4">
    <div class="thumbnail">
      <img src="paris.jpg" alt="Paris">
      <p><strong>Paris</strong></p>
      <p>Fri. 27 November 2015</p>
      <button class="btn">Buy Tickets</button>
    </div>
  </div>
  <div class="col-sm-4">
    <div class="thumbnail">
      <img src="newyork.jpg" alt="New York">
      <p><strong>New York</strong></p>
      <p>Sat. 28 November 2015</p>
      <button class="btn">Buy Tickets</button>
    </div>
  </div>
  <div class="col-sm-4">
    <div class="thumbnail">
      <img src="sanfran.jpg" alt="San Francisco">
      <p><strong>San Francisco</strong></p>
      <p>Sun. 29 November 2015</p>
      <button class="btn">Buy Tickets</button>
    </div>
  </div>
</div>

結果:

Moustiers Sainte Marie

Paris

Fri. 27 November 2015

Moustiers Sainte Marie

New York

Sat. 28 November 2015

Moustiers Sainte Marie

San Francisco

Sun. 29 November 2015

Try it Yourself »

リスト、サムネイル、ボタンをスタイル

リストとサムネイル画像のスタイルには CSS を使用します。 この例では、リストから角丸のボーダーを削除するとともに、 各画像からボーダーをなくして、幅を 100% に設定することでカードのようなサムネイル画像を作成しようとしています。

また、黒いボタンにするため、Bootstrap の .btn クラスのデフォルト・スタイルも変更しています:

/* Remove rounded borders from list */
.list-group-item:first-child {
    border-top-right-radius: 0;
    border-top-left-radius: 0;
}

.list-group-item:last-child {
    border-bottom-right-radius: 0;
    border-bottom-left-radius: 0;
}

/* Remove border and add padding to thumbnails */
.thumbnail {
    padding: 0 0 15px 0;
    border: none;
    border-radius: 0;
}

.thumbnail p {
    margin-top: 15px;
    color: #555;
}

/* Black buttons with extra padding and without rounded borders */
.btn {
    padding: 10px 20px;
    background-color: #333;
    color: #f1f1f1;
    border-radius: 0;
    transition: .2s;
}

/* On hover, the color of .btn will transition to white with black text */
.btn:hover, .btn:focus {
    border: 1px solid #333;
    background-color: #fff;
    color: #000;
}

結果:

Moustiers Sainte Marie

Paris

Fri. 27 November 2015

Moustiers Sainte Marie

New York

Sat. 28 November 2015

Moustiers Sainte Marie

San Francisco

Sun. 29 November 2015

Try it Yourself »

モーダルを追加

まず、サムネイル内の全ボタンを <button class="btn">Buy Tickets</button> から <button class="btn" data-toggle="modal" data-target="#myModal" >Buy Tickets</button> へ変更します。これらのボタンは、実際のモーダルを開くために使用されます。

モーダルを作成するには、次のコードを見てください:

<style>
/* Add a dark gray background color to the modal header and center text */
.modal-header, h4, .close {
    background-color: #333;
    color: #fff !important;
    text-align: center;
    font-size: 30px;
}

.modal-header, .modal-body {
    padding: 40px 50px;
}
</style>


<!-- Used to open the Modal -->
<button class="btn" data-toggle="modal" data-target="#myModal">Buy Tickets</button>

<!-- Modal -->
<div class="modal fade" id="myModal" role="dialog">
  <div class="modal-dialog">

    <!-- Modal content-->
    <div class="modal-content">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal">&times;</button>
        <h4><span class="glyphicon glyphicon-lock"></span> Tickets</h4>
      </div>
      <div class="modal-body">
        <form role="form">
          <div class="form-group">
            <label for="psw"><span class="glyphicon glyphicon-shopping-cart"></span> Tickets, $23 per person</label>
            <input type="number" class="form-control" id="psw" placeholder="How many?">
          </div>
          <div class="form-group">
            <label for="usrname"><span class="glyphicon glyphicon-user"></span> Send To</label>
            <input type="text" class="form-control" id="usrname" placeholder="Enter email">
          </div>
          <button type="submit" class="btn btn-block">Pay
            <span class="glyphicon glyphicon-ok"></span>
          </button>
        </form>
      </div>
      <div class="modal-footer">
        <button type="submit" class="btn btn-danger btn-default pull-left" data-dismiss="modal">
          <span class="glyphicon glyphicon-remove"></span> Cancel
        </button>
        <p>Need <a href="#">help?</a></p>
      </div>
    </div>
  </div>
</div>

Result (click on the "Buy Tickets" button to see the effect):

Try it Yourself »

連絡先コンテナを追加

幅の異なる 2 つのカラム(.col-md-4.col-md-8)を持つ、 新しいコンテナを作成します。

最初のカラムと、2 番目のカラムのフォームコントロール内にテキスト付の情報アイコンを追加します:

<div class="container">
  <h3 class="text-center">Contact</h3>
  <p class="text-center"><em>We love our fans!</em></p>
  <div class="row test">
    <div class="col-md-4">
      <p>Fan? Drop a note.</p>
      <p><span class="glyphicon glyphicon-map-marker"></span>Chicago, US</p>
      <p><span class="glyphicon glyphicon-phone"></span>Phone: +00 1515151515</p>
      <p><span class="glyphicon glyphicon-envelope"></span>Email: mail@mail.com</p>
    </div>
    <div class="col-md-8">
      <div class="row">
        <div class="col-sm-6 form-group">
          <input class="form-control" id="name" name="name" placeholder="Name" type="text" required>
        </div>
        <div class="col-sm-6 form-group">
          <input class="form-control" id="email" name="email" placeholder="Email" type="email" required>
        </div>
      </div>
      <textarea class="form-control" id="comments" name="comments" placeholder="Comment" rows="5"></textarea>
      <div class="row">
        <div class="col-md-12 form-group">
          <button class="btn pull-right" type="submit">Send</button>
        </div>
      </div>
    </div>
  </div>
</div>

結果:

Contact

We love our fans!

Fan? Drop a note.

Chicago, US

Phone: +00 1515151515

Email: mail@mail.com


Try it Yourself »

トグル可能なタブの追加

バンドのメンバーの "quotes" の付いたタブ (.nav nav-tabs) を連絡先コンテナにを追加します:

<style>
.nav-tabs li a {
    color: #777;
}
</style>

<h3 class="text-center">From The Blog</h3>
<ul class="nav nav-tabs">
  <li class="active"><a data-toggle="tab" href="#home">Mike</a></li>
  <li><a data-toggle="tab" href="#menu1">Chandler</a></li>
  <li><a data-toggle="tab" href="#menu2">Peter</a></li>
</ul>

<div class="tab-content">
  <div id="home" class="tab-pane fade in active">
    <h2>Mike Ross, Manager</h2>
    <p>Man, we've been on the road for some time now. Looking forward to lorem ipsum.</p>
  </div>
  <div id="menu1" class="tab-pane fade">
    <h2>Chandler Bing, Guitarist</h2>
    <p>Always a pleasure people! Hope you enjoyed it as much as I did. Could I BE.. any more pleased?</p>
  </div>
  <div id="menu2" class="tab-pane fade">
    <h2>Peter Griffin, Bass player</h2>
    <p>I mean, sometimes I enjoy the show, but other times I enjoy other things.</p>
  </div>
</div>

結果:

From The Blog

Mike Ross, Manager

Man, we've been on the road for some time now. Looking forward to lorem ipsum.

Try it Yourself »

Google マップを追加

Google マップを追加します (詳細は、>Google Maps チュートリアルを参照):

マップの幅、高さ、色の設定には CSS を使用します:

<style>
#googleMap {
    width: 100%; /* Span the entire width of the screen */
    height: 400px; /* Set the height to 400 pixels */
    -webkit-filter: grayscale(100%);
    filter: grayscale(100%); /* Change the color of the map to black and white * /
}
</style>


<div id="googleMap"></div>

<!-- Add Google Maps -->
<script src="http://maps.googleapis.com/maps/api/js"></script>
<script>
var myCenter = new google.maps.LatLng(41.878114, -87.629798);

function initialize() {
var mapProp = {
center:myCenter,
zoom:12,
scrollwheel:false,
draggable:false,
mapTypeId:google.maps.MapTypeId.ROADMAP
};

var map = new google.maps.Map(document.getElementById("googleMap"),mapProp);

var marker = new google.maps.Marker({
position:myCenter,
});

marker.setMap(map);
}

google.maps.event.addDomListener(window, 'load', initialize);
</script>

結果:

Try it Yourself »

ナビゲーションバーを追加

小型の画面では折り畳まれる、ページの上部にナビゲーションバーを追加します:

<nav class="navbar navbar-default navbar-fixed-top">
  <div class="container-fluid">
    <div class="navbar-header">
      <button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#myNavbar">
        <span class="icon-bar"></span>
        <span class="icon-bar"></span>
        <span class="icon-bar"></span>
      </button>
      <a class="navbar-brand" href="#">Logo</a>
    </div>
    <div class="collapse navbar-collapse" id="myNavbar">
      <ul class="nav navbar-nav navbar-right">
        <li><a href="#home">HOME</a></li>
        <li><a href="#band">BAND</a></li>
        <li><a href="#tour">TOUR</a></li>
        <li><a href="#contact">CONTACT</a></li>
        <li class="dropdown">
          <a class="dropdown-toggle" data-toggle="dropdown" href="#">MORE
            <span class="caret"></span>
          </a>
          <ul class="dropdown-menu">
            <li><a href="#">Merchandise</a></li>
            <li><a href="#">Extras</a></li>
            <li><a href="#">Media</a></li>
          </ul>
        </li>
        <li><a href="#"><span class="glyphicon glyphicon-search"></span></a></li>
      </ul>
    </div>
  </div>
</nav>

結果:

Try it Yourself »

チップ: 右揃えのナビゲーションボタンには、navbar-right クラスを使用します。
ナビゲーションバーのリンクの 1 つに、ドロップダウンメニューのように動作させたい場合は、 .dropdown クラスを使用します


ナビゲーションバーをスタイル

ナビゲーションバーのカスタマイズに CSS を使用します:

/* Add a dark background color with a little bit see-through */
.navbar {
    margin-bottom: 0;
    background-color: #2d2d30;
    border: 0;
    font-size: 11px !important;
    letter-spacing: 4px;
    opacity:0.9;
}

/* Add a gray color to all navbar links */
.navbar li a, .navbar .navbar-brand {
    color: #d5d5d5 !important;
}

/* On hover, the links will turn white */
.navbar-nav li a:hover {
    color: #fff !important;
}

/* The active link */
.navbar-nav li.active a {
    color: #fff !important;
    background-color:#29292c !important;
}

/* Remove border color from the collapsible button */
.navbar-default .navbar-toggle {
    border-color: transparent;
}

/* Dropdown */
.open .dropdown-toggle {
    color: #fff ;
    background-color: #555 !important;
}

/* Dropdown links */
.dropdown-menu li a {
    color: #000 !important;
}

/* On hover, the dropdown links will turn red */
.dropdown-menu li a:hover {
    background-color: red !important;
}

結果:

Try it Yourself »

Scrollspy を追加

スクロールしたときにナビゲーションバーのリンクを自動的に変更する scrollspy を追加します:

<body id="myPage" data-spy="scroll" data-target=".navbar" data-offset="50">

<div id="band" class="container">
<div id="tour" class="container">
<div id="contact" class="container">
Try it Yourself »

フッターを追加

1. <footer> 要素を作り、幾つかのテキストを追加します。

2. フッターのスタイルには CSS を使用します。

3. クリックしたときにページのトップに戻れるように、フッターに「上向き矢印」アイコンを追加します。

4. ツールチップ・プラグインの初期化には jQuery を使用します:

<style>
/* Add a dark background color to the footer */
footer {
    background-color: #2d2d30;
    color: #f5f5f5;
    padding: 32px;
}

footer a {
    color: #f5f5f5;
}

footer a:hover {
    color: #777;
    text-decoration: none;
}
</style>

<footer class="text-center">
  <a class="up-arrow" href="#myPage" data-toggle="tooltip" title="TO TOP">
    <span class="glyphicon glyphicon-chevron-up"></span>
  </a><br><br>
  <p>Bootstrap Theme Made By <a href="http://www.w3schools.com" data-toggle="tooltip" title="Visit w3schools">www.w3schools.com</a></p>
</footer>

<script>
$(document).ready(function(){
    // Initialize Tooltip
    $('[data-toggle="tooltip"]').tooltip();
})
</script>

結果:

Try it Yourself »

スムーズなスクロールを追加

jQuery を使用し、スムーズなスクロールを追加します(ナビゲーションバー内のリンクをクリック時):

<script>
$(document).ready(function(){
  // Add smooth scrolling to all links in navbar + footer link
  $(".navbar a, footer a[href='#myPage']").on('click', function(event) {

  // Make sure this.hash has a value before overriding default behavior
  if (this.hash !== "") {

    // Prevent default anchor click behavior
    event.preventDefault();

    // Store hash
    var hash = this.hash;

    // Using jQuery's animate() method to add smooth page scroll
    // The optional number (900) specifies the number of milliseconds it takes to scroll to the specified area
    $('html, body').animate({
      scrollTop: $(hash).offset().top
    }, 900, function(){

      // Add hash (#) to URL when done scrolling (default click behavior)
      window.location.hash = hash;
      });
    } // End if
  });
})
</script>
Try it Yourself »

最後の仕上げ

好きなフォントを追加して、あなたのテーマを自分専用します。ここでは、Google のフォントライブラリから "Montserrat" と "Lato" を使用します。

<head> セクションでフォントへリンクします:

<link href="http://fonts.googleapis.com/css?family=Montserrat" rel="stylesheet" type="text/css">

<link href="http://fonts.googleapis.com/css?family=Lato" rel="stylesheet" type="text/css">

これで、ページに使用できるようになります:

body {
    font: 400 15px/1.8 Lato, sans-serif;
    color: #777;
}

.navbar {
    font-family: Montserrat, sans-serif;
}

いくつかの要素に、特別なスタイルを追加します:

/* Overwrite default styles of h3 and h4 */
h3, h4 {
    margin: 10px 0 30px 0;
    letter-spacing: 10px;
    font-size: 20px;
    color: #111;
}

/* Remove rounded borders on input fields */
.form-control {
    border-radius: 0;
}

/* Disable the ability to resize textareas */
textarea {
    resize: none;
}
Try it Yourself »

完成した "The Band" テーマ


Full Page Demo Full Source Code

❮ 前章へ 次章へ ❯