Movatterモバイル変換


[0]ホーム

URL:


LoginSignup
9

Go to list of users who liked

10

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 5 years have passed since last update.

コピペでできるBootstrap3、簡単レスポンシブ(Grid System)させてみよう【グリッドシステム】

Last updated atPosted at 2016-03-10

いま仕事で使ってるけど忘れないように書いておきます。

コピペでBootstrapとJQuery導入

まずは空HTMLファイル用意して以下コピペしてみましょう。

index.html
<!DOCTYPE html><htmllang="ja"><head><metacharset="utf-8"><metahttp-equiv="X-UA-Compatible"content="IE=edge"><metaname="viewport"content="width=device-width, initial-scale=1"><title>タイトルタイトル</title><linkhref="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css"rel="stylesheet"><scriptsrc="https://ajax.googleapis.com/ajax/libs/jquery/2.2.4/jquery.min.js"></script><scriptsrc="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script></head><body></body></html>

これでBootstrapとJQueryが導入できました。
必要でしたらローカルにJSとCSSをダウンロードしましょう。

レスポンシブさせてみる

ブラウザ幅判定して要素の位置を変更させてくれるのがレスポンシブです。
まずはグリッドの列数は12と覚えましょう。横に12個要素が入りますみたいなイメージです。
グリッドは<div>col-md-3</div>みたいなやつです。
とりあえず
bodyに以下追加してみましょう。

<divclass="container"><divclass="row"><divclass="col-md-3">ノーパソ3</div><divclass="col-md-3">ノーパソ3</div><divclass="col-md-3">ノーパソ3</div><divclass="col-md-3">ノーパソ3</div></div></div>

ブラウザの幅広げると横4つグリッド入って一定以下になると縦1列になりますよね。
これにはBootstrapには折り返し地点が決められています。

Bootstrapの折り返し地点と対応クラス名

ウインドウ幅デバイスの種類クラス名
0px以上スマートフォンcol-xs-N
768px以上タブレットcol-sm-N
992px以上ノートPCcol-md-N
1200px以上大画面PCcol-lg-N

これを基準に進めていきます。Nの部分に数字入れてclassで指定してあげます。
画像でイメージ出すとこんな感じです。
html5app11_13.jpg


先ほどの例だとグリッドのcol-md-3×4で12なので992px以下になると折り返されます。

次にタブレット幅の場合は2つ横にグリッド表示されるよう書き換えてみましょう。

<divclass="container"><divclass="row"><divclass="col-sm-6 col-md-3">タブ6ノーパソ3</div><divclass="col-sm-6 col-md-3">タブ6ノーパソ3</div><divclass="col-sm-6 col-md-3">タブ6ノーパソ3</div><divclass="col-sm-6 col-md-3">タブ6ノーパソ3</div></div></div>

これで768px以下で横1つ、768~992pxの場合横2つ、992px以上で横4つになります。

こんな感じでレスポンシブ対応ができます。

9

Go to list of users who liked

10
0

Go to list of comments

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
9

Go to list of users who liked

10

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?


[8]ページ先頭

©2009-2025 Movatter.jp