laravel5-7にbootstrapを入れる

簡易的にcdnで実装したい。jqueryはbody内。

<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css">
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/js/bootstrap.min.js"></script>

resources/views/layouts のdefault.blade.phpを編集する。

<!DOCTYPE>
<html>
<head>
	<meta charset="utf-8">
	<title>@yield('title')</title>
	<link rel="stylesheet" href="/css/styles.css">
	<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css">
</head>
<body>
  <div class="container">
	@yield('content')
  </div>
  <script src="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/js/bootstrap.min.js"></script>
</body>
</html>

[vagrant@localhost laravel]$ php artisan serve –host 192.168.35.10

おいおい、おかしなことになってる。
まあbootstrapが動くことは分かったのでOK

Bootstrap tooltip, popover

<!DOCTYPE html>
<html lang="ja">
  <head>
    <meta charset="utf-8">
    <title>Bootstrap Practice</title>
    <link href="css/bootstrap.min.css" rel="stylesheet">
  </head>
  <body>

    <div class="container" style="padding:20px 0">

      <p><a href="#" data-toggle="tooltip" title="説明">this</a> and <a href="#" data-toggle="popover" title="説明" data-content="さらに説明">that</a>.</p>

    </div>
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
    <script src="js/bootstrap.min.js"></script>
    <script>
      $(function(){
        $("[data-toggle=tooltip]").tooltip({
          placement: 'bottom'
        });
        $("[data-toggle=popover]").popover();
      });
    </script>
  </body>
</html>

%e7%84%a1%e9%a1%8c

Bootstrap navbar レスポンシブル対応

トグルボタンを追加します。

<!DOCTYPE html>
<html lang="ja">
  <head>
    <meta charset="utf-8">
    <title>Bootstrap Practice</title>
    <link href="css/bootstrap.min.css" rel="stylesheet">
  </head>
  <body>

  <nav class="navbar navbar-default navbar-fixed-top">
    <div class="navbar-header">
      <button class="navbar-toggle" data-toggle="collapse" data-target=".target">
      <span class="icon-bar"></span>
      <span class="icon-bar"></span>
      <span class="icon-bar"></span>
      </button>
      <a class="navbar-brand" href="">Hello world</a>
    </div>

    <div class="collapse navbar-collapse target">
    <ul class="nav navbar-nav">
      <li class="active"><a href="">link1</a></li>
      <li><a href="">link2</a></li>
      </ul>
      <ul class="nav navbar-nav navbar-right">
        <li><a href="">link3</a></li>
      </ul>
    </div>
  </nav>

    <div class="container" style="padding:20px 0">
    <p>こんにちは</p>
    <p>こんにちは</p>
    <p>こんにちは</p>
    <p>こんにちは</p>
    <p>こんにちは</p>
    <p>こんにちは</p>
    <p>こんにちは</p>
    <p>こんにちは</p>
    <p>こんにちは</p>
    <p>こんにちは</p>
    <p>こんにちは</p>
    <p>こんにちは</p>
    <p>こんにちは</p>
    <p>こんにちは</p>
    <p>こんにちは</p>
    </div>
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
    <script src="js/bootstrap.min.js"></script>
  </body>
</html>

%e7%84%a1%e9%a1%8c

Bootstrap navbar

ヘッダー固定はnavbar-fixed-topのclassを追加します。

<!DOCTYPE html>
<html lang="ja">
  <head>
    <meta charset="utf-8">
    <title>Bootstrap Practice</title>
    <link href="css/bootstrap.min.css" rel="stylesheet">
  </head>
  <body>

  <nav class="navbar navbar-default navbar-fixed-top">
    <div class="navbar-header">
      <a class="navbar-brand" href="">Hello world</a>
    </div>
    <ul class="nav navbar-nav">
      <li class="active"><a href="">link1</a></li>
      <li><a href="">link2</a></li>
      </ul>
      <ul class="nav navbar-nav navbar-right">
        <li><a href="">link3</a></li>
      </ul>
  </nav>

    <div class="container" style="padding:20px 0">
    <p>こんにちは</p>
    <p>こんにちは</p>
    <p>こんにちは</p>
    <p>こんにちは</p>
    <p>こんにちは</p>
    <p>こんにちは</p>
    <p>こんにちは</p>
    <p>こんにちは</p>
    <p>こんにちは</p>
    <p>こんにちは</p>
    <p>こんにちは</p>
    <p>こんにちは</p>
    <p>こんにちは</p>
    <p>こんにちは</p>
    <p>こんにちは</p>
    </div>
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
    <script src="js/bootstrap.min.js"></script>
  </body>
</html>

%e7%84%a1%e9%a1%8c

bootstrap パン屑、pagination、pager

<!DOCTYPE html>
<html lang="ja">
  <head>
    <meta charset="utf-8">
    <title>Bootstrap Practice</title>
    <link href="css/bootstrap.min.css" rel="stylesheet">
  </head>
  <body>
    <div class="container" style="padding:20px 0">

    <ul class="breadcrumb">
      <li><a href="">Home</a></li>
      <li><a href="">User</a></li>
      <li class="active">@walking</li>
    </ul>

    <ul class="pagination">
      <li class="disabled"><a href="">&laquo:</a></li>
      <li class="active"><a href="">1</a></li>
      <li><a href="">2</a></li>
      <li><a href="">3</a></li>
      <li><a href="">&raquo:</a></li>
    </ul>

    <ul class="pager">
      <li class="previous"><a href="">前へ</a></li>
      <li class="next"><a href="">次へ</a></li>
    </ul>

    </div>
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
    <script src="js/bootstrap.min.js"></script>
  </body>
</html>

%e7%84%a1%e9%a1%8c

Bootstrap dropdown menu

<!DOCTYPE html>
<html lang="ja">
  <head>
    <meta charset="utf-8">
    <title>Bootstrap Practice</title>
    <link href="css/bootstrap.min.css" rel="stylesheet">
  </head>
  <body>
    <div class="container" style="padding:20px 0">
      <div class="btn-group">
        <button class="btn btn-primary">Action </span>
        <button class="btn btn-primary dropdown-toggle" data-toggle="dropdown">
        <span class="caret"></span>
        </button>
        <ul class="dropdown-menu">
        <li><a href="">Action</a></li>
        <li><a href="">Action</a></li>
        <li class="divider"></li>
        <li><a href="">Action</a></li>
        </ul>
      </div>

    </div>
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
    <script src="js/bootstrap.min.js"></script>
  </body>
</html>

%e7%84%a1%e9%a1%8c

Bootstrap Glyphicons

Bootstrapには標準で、アイコンやボタンが用意されています。

<!DOCTYPE html>
<html lang="ja">
  <head>
    <meta charset="utf-8">
    <title>Bootstrap Practice</title>
    <link href="css/bootstrap.min.css" rel="stylesheet">
  </head>
  <body>
    <div class="container" style="padding:20px 0">
      
    <p><i class="glyphicon glyphicon-book">Book</i></p>
    <div class="btn-group">
    <button class="btn btn-primary">Push Me!</button>
    <button class="btn btn-success">Push Me!</button>
    <button class="btn btn-info">Push Me!</button>
    </div>
    </div>
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
    <script src="js/bootstrap.min.js"></script>
  </body>
</html>

%e7%84%a1%e9%a1%8c

Bootstrap table装飾, form

<!DOCTYPE html>
<html lang="ja">
  <head>
    <meta charset="utf-8">
    <title>Bootstrap Practice</title>
    <link href="css/bootstrap.min.css" rel="stylesheet">
  </head>
  <body>
    <div class="container" style="padding:20px 0">
  <table class="table table-striped table-bordered table-hover ">
    <thead>
    <tr>
    <th>ID</th><th>Score</th>
    </tr>
    </thead>
    <tbody>
      <tr><td>@yamada</td><td>200</td></tr>
      <tr><td>@sato</td><td>150</td></tr>
      <tr><td>@mori</td><td>230</td></tr>
      </tbody>
  </table>
    </div>
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
    <script src="js/bootstrap.min.js"></script>
  </body>
</html>
<!DOCTYPE html>
<html lang="ja">
  <head>
    <meta charset="utf-8">
    <title>Bootstrap Practice</title>
    <link href="css/bootstrap.min.css" rel="stylesheet">
  </head>
  <body>
    <div class="container" style="padding:20px 0">
      
      <form class="form-horizontal" style="margin-bottom:15px">
      <div class="form-group">
        <label class="control-label col-sm-2" for="email">Email</label>
          <div class="col-sm-4">
          <input type="text" id="email" class="form-control" placeholder="email">
          </div>
        </div>
        <div class="form-group">
        <div class="col-sm-offset-2 col-sm-4">
          <input type="submit" value="submit" class="btn btn-primary">
        </div>
        </div>
      </form>


    </div>
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
    <script src="js/bootstrap.min.js"></script>
  </body>
</html>

Bootstrap col-sm-6

bootstrapでは、横幅を12に区切って、区画を設定していきます。

<!DOCTYPE html>
<html lang="ja">
  <head>
    <meta charset="utf-8">
    <title>Bootstrap Practice</title>
    <link href="css/bootstrap.min.css" rel="stylesheet">
  </head>
  <body>
    <div id="header" class="container" style="background-color:red;">header</div>

    <div class="container">
    <div class="row">
      <div class="col-sm-3 hidden-xs" style="background-color:gray;">side1</div>
      <div class="col-sm-6 col-xs-6" style="background:green;">Main</div>
      <div class="col-sm-3 col-xs-6" style="background:orange;">side2</div>
    </div>
    </div>

    <div id="footer" class="container" style="background: blue;">footer</div>
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
    <script src="js/bootstrap.min.js"></script>
  </body>
</html>

%e7%84%a1%e9%a1%8c