LoginSignup
0
0

More than 3 years have passed since last update.

SASS版Bootstrapのナビバーにてスマホ幅時でもスマホ用表示に切り替えさせない

Posted at

Bootstrapのナビバーにて中の要素としてアイコンが2つだけしかないような場合、スマホでもハンバーガーメニューに切り替えるのは微妙なのでPCと同じ表示にしたい
今回はsass版で実装


// ナビバー以外のコンポーネント読み込み
@import "node_modules/bootstrap/scss/functions";
@import "node_modules/bootstrap/scss/variables";
@import "node_modules/bootstrap/scss/mixins";
@import "node_modules/bootstrap/scss/reboot";
@import "node_modules/bootstrap/scss/type";
@import "node_modules/bootstrap/scss/grid";
@import "node_modules/bootstrap/scss/nav";


// ブレイクポイントの変数を一時コピーして保存
$tmp-grid-breakpoints: $grid-breakpoints;
// ブレイクポイントを一時全部無効に
$grid-breakpoints: (
        xs: 0,
        sm: 0,
        md: 0,
        lg: 0,
        xl: 0
);
// navbarのスタイルを出力
@import "node_modules/bootstrap/scss/navbar";
// 変数戻す
$grid-breakpoints: $tmp-grid-breakpoints;

ブレイクポイントをナビバーのときだけ無効にしてスタイルを吐き出させてる感じですね。
CDNで導入されたようなCSS版Bootstrapでやろうとすると結構面倒な案件なんですがsassなら手軽に実現できました。

今回は4系のナビバーですが多分5系の方やナビバー以外のコンポーネントでも同じようなことができると思います。

0
0
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
0
0