问题
In the following runnable code snippet I have setup a basic Bulma layout with a navbar. The navbar is breaking to hamburger very early for the amount/size of links I have.
How can I make this break on smaller screens only? e.g. Hamburger only on phones.
(function() {
let burger = document.querySelector('.burger');
let nav = document.querySelector('#' + burger.dataset.target);
burger.addEventListener('click', function() {
burger.classList.toggle('is-active');
nav.classList.toggle('is-active');
});
})();
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Hello Bulma!</title>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/bulma/0.7.1/css/bulma.min.css">
<script defer src="https://use.fontawesome.com/releases/v5.1.0/js/all.js"></script>
</head>
<body>
<nav class="navbar is-black is-desktop">
<div class="container">
<div class="navbar-brand">
<a href="#" class="navbar-item">
title
</a>
<span class="navbar-burger burger" data-target="navMenu">
<span></span>
<span></span>
<span></span>
</span>
</div>
<div id="navMenu" class="navbar-menu">
<div class="navbar-end">
<a href="#" class="navbar-item is-active">Home</a>
<a href="#" class="navbar-item">Two</a>
<a href="#" class="navbar-item">Three</a>
<a href="#" class="navbar-item">Four</a>
<a href="#" class="navbar-item">Five</a>
</div>
</div>
</div>
</nav>
<section class="section">
<div class="container">
<h1 class="title">
Hamburger Help!
</h1>
<p class="subtitle">
How do i get the nav links to show on tablet instead of the hamburger?
</p>
</div>
</section>
</body>
</html>
回答1:
You can set $navbar-breakpoint
variable to tablet. By default navbar breakpoint is set to desktop.
In your main.scss, update Bulma's $navbar-breakpoint
variable.
// Import only what you need from Bulma
@import "../node_modules/bulma/sass/utilities/_all.sass";
@import "../node_modules/bulma/sass/base/_all.sass";
@import "../node_modules/bulma/sass/elements/button.sass";
@import "../node_modules/bulma/sass/elements/container.sass";
@import "../node_modules/bulma/sass/elements/form.sass";
@import "../node_modules/bulma/sass/elements/title.sass";
$navbar-breakpoint: $tablet;
@import "../node_modules/bulma/sass/components/navbar.sass";
@import "../node_modules/bulma/sass/layout/hero.sass";
@import "../node_modules/bulma/sass/layout/section.sass";
@import "../node_modules/bulma/sass/grid/columns.sass";
I'm setting $navbar-breakpoint
variable to the value of $tablet
after importing _all.sass utilities. You need to do that because $tablet
variable has to get set first.
After that you need to set$navbar-breakpoint
variable before importing navbar component, otherwise default desktop value will be used.
来源:https://stackoverflow.com/questions/52467626/bulma-show-uncollapsed-navbar-on-tablet