28
26

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.

iPadでBootstrapのnavbarをcollapseさせる

Last updated at Posted at 2015-09-28

レスポンシブデザインなウェブサイトの場合、スマホだけでなくタブレットに対応させることも多いです。

CSSフレームワークのBootstrapを使って、ナビゲーション(navbar)を導入する場合、すこし細工が必要。Bootstrapのデフォルトだと、iPadでnavbarがcollapseしてくれません。メニュー項目が多くなってくると、collapseしてくれないとレイアウト崩れが起きたりもしますよね。

iPadでBootstrapのnavbarをcollapseさせるには、CSSに下記のコードを追加すればOKです。

/* navbar collapse for iPad (bootstrap) */
@media (max-width: 991px) {
    .navbar-header {
        float: none;
    }
    .navbar-toggle {
        display: block;
    }
    .navbar-collapse {
        border-top: 1px solid transparent;
        box-shadow: inset 0 1px 0 rgba(255,255,255,0.1);
    }
    .navbar-collapse.collapse {
        display: none!important;
    }
    .navbar-nav {
        float: none!important;
        margin: 7.5px -15px;
    }
    .navbar-nav>li {
        float: none;
    }
    .navbar-nav>li>a {
        padding-top: 10px;
        padding-bottom: 10px;
    }
    .navbar-text {
        float: none;
        margin: 15px 0;
    }
    .navbar-collapse.collapse.in {
        display: block!important;
    }
    .collapsing {
        overflow: hidden!important;
    }
}
28
26
2

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
28
26

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?