2
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

Bootstrap5導入

Last updated at Posted at 2022-02-16

Bootstrap5の導入するとき用にメモ

Bootstrap4からの主要な変更点

・jQueryから脱却
・IEサポートしない
・ブレークポイントxl-1200pxからxxl-1400pxに
・ガター(子要素の余白)
・CSSカスタムプロパティ
・クラス名が変更

導入方法

・BootstrapCDNで導入
・パッケージで導入
・ダウンロードして導入

BootstrapCDNで導入

・簡単
・Bootstrap側の非常事態(ダウン)などがあれば読み込めない

以下Bootstrapの公式URLにアクセスし、
https://getbootstrap.com/

ページをスクロールダウンして「jsDelivr」という項目の

・CSSリンクをコピー

index.html
<head>
<!-- CSS only -->
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-EVSTQN3/azprG1Anm3QDgpJLIm9Nao0Yz1ztcQTwFspd3yD65VohhpuuCOmLASjC" crossorigin="anonymous">
</head>

headタグ内に貼り付け

・JavaScriptリンクをコピー

index.html
<body>

<!-- JavaScript Bundle with Popper -->
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/js/bootstrap.bundle.min.js" integrity="sha384-MrcW6ZMFYlzcLA8Nl+NtUVF0sA7MsXsP1UyJoMp4YLEuNSfAP+JcXn/tWtIaxVXM" crossorigin="anonymous"></script>
</body>

</body>タグの最後に貼り付け
※bootstrap.bundle.jsではなく、bootstrap.jsを読み込む設定にする場合は、popper.jsも読み込む
※Bootstrap5はjQueryを使わないよう設計されている。使用は可能。

パッケージで導入

npm

npm パッケージを使って、Node.js を搭載したアプリに Bootstrap をインストール

$ npm install bootstrap

yarn

the yarn package を用いて Bootstrap をインストール

$ yarn add bootstrap

RubyGems

Ruby アプリ Bundler (推奨) と RubyGems で Gemfile からインストール

$ gem 'bootstrap', '~> 5.0.2'

Bundler を使ってない場合は、以下のコマンドで gem をインストール

$ gem install bootstrap -v 5.0.2

Composer

Composer を使って Bootstrap の Sass と JavaScript をインストール

$ composer require twbs/bootstrap:5.0.2

NuGet

.NET で開発しているのであれば NuGet を使って Bootstrap の CSS や Sass、JavaScript をインストール

PM> Install-Package bootstrap
PM> Install-Package bootstrap.sass

ダウンロードして導入

以下Bootstrapの公式URLにアクセスし、
https://getbootstrap.com/

Download

フォルダ内に保存し、CDNの場合と同じようにして読み込み先を保存箇所ファイルとする

2
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?