I have a bulma navbar I'm manipulating with react. Below is the generated code. On desktop the menu displays correctly and opens and closes the dropdown menus as expected.
On mobile however all the dropdowns are open by default and although the class "is-active" is being added and removed when I click on the "navbar-link" the menu isn't opening and closing as expected.
<nav class="navbar" role="navigation" aria-label="main navigation">
<div class="navbar-brand">
<a role="button" class="navbar-burger burger" aria-label="menu" aria-expanded="false" data-target="navbar">
<span aria-hidden="true"></span>
<span aria-hidden="true"></span>
<span aria-hidden="true"></span>
</a>
</div>
<div id="navbar" class="navbar-menu is-active">
<div class="navbar-start">
<div class="navbar-item has-dropdown">
<a class="navbar-link">Data Types</a>
<div class="navbar-dropdown">
<div class="types">
Select Content
</div>
</div>
</div>
</div>
</div>
</nav>
The "is-active" in the code above is from the burger menu opening the menu. What am I doing wrong?
I needed to add the sass
.navbar-item {
&.has-dropdown {
.navbar-dropdown {
display: none;
}
&.is-active {
.navbar-dropdown {
display: block;
}
}
}
}
under #mobile in my sass. Then the mobile behaves like the desktop.
THIS WORKED for me like a charm--->
/** The jQuery will trigger only at mobile viewport */
if (window.matchMedia("(max-width: 767px)").matches) {
const $navDropdowns = document.querySelectorAll(".navbar-item.has-dropdown");
if ($navDropdowns.length > 0) {
// HIDE THE DROP-DOWN ON THE INITIAL LOAD
$navDropdowns.forEach((el) => {
const target = el.dataset.target;
const $target = document.getElementById(target);
$target.style.display = "none";
//Register the click event on the dropdown list
el.addEventListener("click", () => {
// Get the target from the "data-target" attribute
const target = el.dataset.target;
const $target = document.getElementById(target);
if ($target.style.display === "block") {
$target.style.display = "none";
} else {
$target.style.display = "block";
}
});
});
}
}
Collapsed Menu
Expanded Menu
Here's the HTML for the navbar:
<nav class="navbar" role="navigation" aria-label="main navigation">
<div class="navbar-brand">
<a class="navbar-item" href="https://bulma.io">
<img src="https://bulma.io/images/bulma-logo.png" width="112" height="28" />
</a>
<a role="button" class="navbar-burger" #click="toggle" aria-label="menu" aria-expanded="false" data-target="navbarBasicExample">
<span aria-hidden="true"></span>
<span aria-hidden="true"></span>
<span aria-hidden="true"></span>
</a>
</div>
<div id="navbarBasicExample" class="navbar-menu">
<div class="navbar-start">
<a class="navbar-item">
Home
</a>
<a class="navbar-item">
Documentation
</a>
<div data-target="more" class="navbar-item has-dropdown is-hoverable">
<a class="navbar-link">
More
</a>
<div class="navbar-dropdown" id="more">
<a class="navbar-item">
About
</a>
<a class="navbar-item">
Jobs
</a>
<a class="navbar-item">
Contact
</a>
<hr class="navbar-divider" />
<a class="navbar-item">
Report an issue
</a>
</div>
</div>
<div data-target="new" class="navbar-item has-dropdown is-hoverable">
<a class="navbar-link">
New
</a>
<div class="navbar-dropdown" id="new">
<a class="navbar-item">
About
</a>
<a class="navbar-item">
Jobs
</a>
<a class="navbar-item">
Contact
</a>
<hr class="navbar-divider" />
<a class="navbar-item">
Report an issue
</a>
</div>
</div>
</div>
<div class="navbar-end">
<div class="navbar-item">
<div class="buttons">
<a class="button is-primary">
<strong>Sign up</strong>
</a>
<a class="button is-light">
Log in
</a>
</div>
</div>
</div>
</div>
</nav>
Notice the data-target="more", data-target="new" and the ids passed in the child elements. By the way, this is an implementation on a Vuejs app, but this will work everywhere.
The css code only hide the dropdown links but you can't reach them anymore on mobile.
I also grappled with this issue so decided to give Buefy a try. This isn't exactly a pure Bulma answer but it could be considered close by default and it worked first-time.
I'm using Nuxt, initially with Bulma as a nuxtjs module and the installation/conversion from Bulma to Buefy was simple: https://buefy.org/documentation/start/#nuxtjs.
For a completely fresh integration I removed the Bulma module from nuxt-config, deleted node_modules/package-lock.json, and followed the above guide.
I tweaked the Buefy Navbar component to my requirements and it just works - shows/hides the dropdown properly - and it also adds the correct Aria attrs automatically:
<template>
<b-navbar>
<template slot="brand">
<h1>
<nuxt-link to="/" class="navbar-item is-size-4" id="homelink">
Brand link here
</nuxt-link>
</h1>
</template>
<template slot="end">
<b-navbar-item tag="div">
<div class="buttons">
<nuxt-link class="navbar-item" to="/projects">Projects</nuxt-link>
<nuxt-link class="navbar-item" to="/about">About/Contact</nuxt-link>
</div>
</b-navbar-item>
</template>
</b-navbar>
</template>
By default the $navbar-breakpoint is set to break at $desktop.
You can override your initial bulma variables in your own mystyles.scss like bulma describes here https://versions.bulma.io/0.7.0/documentation/overview/customize/.
It might look something like this if you never want it to break: $navbar-breakpoint: 0px
Based on #psykx 's answer, I came up with the following:
#charset "utf-8";
#import "./bulma/bulma";
#include mobile{
.navbar-item {
&.has-dropdown {
.navbar-dropdown {
display: none;
}
&.is-active {
.navbar-dropdown {
display: block;
}
}
}
}
}
Works very well.
Related
I'm experimenting with bulma css.
I really like it, but there's few things I don't get it.
I made a simple landing page for testing and I can't succeed having a transparent nav bar.
I want the nav bar to be transparent and then become white on scrolling. I can make it white and fixed on scrolling but not transparent.
This is my navbar. the full page is loaded on codepen
<nav class="navbar is-transparent is-fixed-top" role="navigation" aria-label="main navigation">
<div class="navbar-brand pl-4">
<a class="navbar-item" href="https://bulma.io">
<img src="https://bulma.io/images/bulma-logo.png" width="112" height="28" />
</a>
<a
role="button"
class="navbar-burger"
aria-label="menu"
aria-expanded="false"
data-target="navbarBasicExample"
>
<span aria-hidden="true"></span>
<span aria-hidden="true"></span>
<span aria-hidden="true"></span>
</a>
</div>
<div id="navbarBasicExample" class="navbar-menu">
<div class="navbar-start"></div>
<div class="navbar-end pr-4">
<a class="navbar-item"> Home </a>
<a class="navbar-item"> About </a>
<a class="navbar-item"> Contact </a>
</div>
</div>
</nav>
Can you please help me find the issue?
The navbar class has its own background-color: #fff; therefore you always see a white background on the navbar. You can override this property with plain CSS.
index.html
<nav class="navbar is-fixed-top" role="navigation" aria-label="main navigation">
....
</nav>
style.css
.navbar {
background-color: hsl(0 100% 100% / 0.4);
}
UPDATED
For the opposite:
Remove class="has-navbar-fixed-top" from the body tag.
To scrolling we need JS to intercept scroll values and change the opacity on the navbar.
document.addEventListener('DOMContentLoaded', function() {
const navbar = document.querySelector('.navbar');
window.addEventListener('scroll', () => {
// Get scroll position values
const trigger = window.scrollY;
// The top position when we change the opacity
const navbarHeight = navbar.clientHeight;
if (trigger >= navbarHeight) {
navbar.setAttribute('style', 'background-color: hsl(0 100% 100% / 1)');
} else {
navbar.setAttribute('style', 'background-color: hsl(0 100% 100% / 0.7)');
}
});
});
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bulma#0.9.4/css/bulma.min.css" />
<nav class="navbar is-fixed-top" role="navigation" aria-label="main navigation" style="background-color: hsl(0 100% 100% / 0.7)">
<div class="navbar-brand pl-4">
<a class="navbar-item" href="https://bulma.io">
<img src="https://bulma.io/images/bulma-logo.png" width="112" height="28" />
</a>
<a role="button" class="navbar-burger" aria-label="menu" aria-expanded="false" data-target="navbarBasicExample">
<span aria-hidden="true"></span>
<span aria-hidden="true"></span>
<span aria-hidden="true"></span>
</a>
</div>
<div id="navbarBasicExample" class="navbar-menu">
<div class="navbar-start"></div>
<div class="navbar-end pr-4">
<a class="navbar-item"> Home </a>
<a class="navbar-item"> About </a>
<a class="navbar-item"> Contact </a>
</div>
</div>
</nav>
<div class="headerContainer" style="
height: 700px;
background-image: url('http://placeimg.com/1000/768/nature');
background-position: center;
background-repeat: no-repeat;
background-size: cover;
"></div>
When I open bulma dropdown it gets opened on the right and some part is even outside from screen. How can I force it to pen dropdown on the left?
Currently, it looks like this:
So the goal is to open it on the left from the Account item
<nav class="navbar" role="navigation" aria-label="dropdown navigation">
<div class="navbar-item has-dropdown is-active">
<a class="navbar-link">
Docs
</a>
<div class="navbar-dropdown">
<a class="navbar-item">
Overview
</a>
<a class="navbar-item">
Elements
</a>
<a class="navbar-item">
Components
</a>
<hr class="navbar-divider">
<div class="navbar-item">
Version 0.9.1
</div>
</div>
</div>
</nav>
How can be it solved?
According to the documention about the dropdown component, you can add the is-right class to have a right-aligned dropdown, so the overflow will be on the left side.
It also works on navbar's dropdowns, your code should look like this :
<nav class="navbar" role="navigation" aria-label="dropdown navigation">
<div class="navbar-item has-dropdown is-active">
<a class="navbar-link">
Docs
</a>
<div class="navbar-dropdown is-right">
<a class="navbar-item">
Overview
</a>
<a class="navbar-item">
Elements
</a>
<a class="navbar-item">
Components
</a>
<hr class="navbar-divider">
<div class="navbar-item">
Version 0.9.1
</div>
</div>
</div>
</nav>
Result :
There is one way to convert a sidebar Menu to burger menu with Bulma.
With the navbar menu (horizontal on top) i can do this very easy with this code:
HTML
<nav class="navbar is-fixed-top" role="navigation" aria-label="main navigation">
<div class="navbar-brand">
<a href="#" class="navbar-item">
<img src="https://bulma.io/images/bulma-logo-white.png" width="112" height="28">
</a>
<a role="button" class="navbar-burger burger" aria-label="menu" aria-expanded="false" data-target="navbar-example">
<span aria-hidden="true"></span>
<span aria-hidden="true"></span>
<span aria-hidden="true"></span>
</a>
</div>
<div id="navbar-example" class="navbar-menu">
<div class="navbar-start">
<a class="navbar-item is-tab">Home</a>
<a class="navbar-item is-tab ">Features</a>
<a class="navbar-item is-tab">Documentation</a>
</div>
<div class="navbar-end">
<div class="navbar-item">
<div class="buttons">
<a class="button is-light">
Log in
</a>
</div>
</div>
</div>
</div>
</nav>
JS
const $navbarBurgers = Array.prototype.slice.call(document.querySelectorAll('.navbar-burger'), 0);
if ($navbarBurgers.length > 0) {
$navbarBurgers.forEach( el => {
el.addEventListener('click', () => {
const target = el.dataset.target; const $target = document.getElementById(target);
el.classList.toggle('is-active');
$target.classList.toggle('is-active');
});
});
}
I want eliminate this navbar, use only my side menu and convert it to burger in small screens.
I'm trying that and is not working:
HTML
<div class="columns is-fullheight">
<a role="button" class="navbar-burger burger" aria-label="menu" aria-expanded="false" data-target="navbar-example">
<span aria-hidden="true"></span>
<span aria-hidden="true"></span>
<span aria-hidden="true"></span>
</a>
<aside class="sidebar">
<nav id="navbar-example" class="menu">
<p class="menu-label">
Liturgia
</p>
<ul class="menu-list">
<li>
<a class="is-active">Breviario</a>
<ul>
<li><a class="action" id="mixto">Mixto</a></li>
<li><a class="action" id="oficio">Oficio</a></li>
</ul>
</li>
<li>
<a class="is-active">Misa</a>
<ul>
<li><a class="action" id="lecturas">Lecturas</a></li>
<li><a class="action" id="rito">Rito completo</a></li>
</ul>
</li>
</ul>
<p class="menu-label">
Tradición
</p>
<ul class="menu-list">
<li><a class="is-disable">Homilías</a></li>
<li><a class="action" id="comentarios">Comentarios</a></li>
</ul>
<p class="menu-label">
Hagiografía
</p>
<ul class="menu-list">
<li>Santo del día</li>
</ul>
</nav>
</aside>
</div>
JS
const $navbarBurgers = Array.prototype.slice.call(document.querySelectorAll('.navbar-burger'), 0);
if ($navbarBurgers.length > 0) {
$navbarBurgers.forEach( el => {
el.addEventListener('click', () => {
const target = el.dataset.target; const $target = document.getElementById(target);
el.classList.toggle('is-active');
$target.classList.toggle('is-active');
});
});
}
How i can achieve this?
I'm currently struggling with the bulma navbar. This is my header:
<header class="navbar">
<div class="container">
<div class="navbar-brand">
<a class="navbar-item">
<span class="icon has-text-primary is-large">
<i class="mdi mdi-36px mdi-hexagon-multiple"></i>
</span>
<!-- <h1 class="title is-1">DNW</h1> -->
</a>
<span class="navbar-burger burger" data-target="navbarMenuHeroC">
<span></span>
<span></span>
<span></span>
</span>
</div>
<div class="navbar-menu">
<div class="navbar-end">
<a class="navbar-item">
Home
</a>
<a class="navbar-item">
Forum
</a>
<a class="navbar-item">
Spiele
</a>
<div class="navbar-item has-dropdown is-hoverable is-arrowless">
<div class="navbar-link">
<img class="nav-profilepic" src="https://static.wixstatic.com/media/1bfda4_6f8ae00a346644a89245f331fc6c6b8e~mv2_d_3476_5214_s_4_2.jpeg?dn=">
Tränenreich
</div>
<div class="navbar-dropdown">
<a class="navbar-item">
Profil
</a>
<a class="navbar-item">
Nachrichten
</a>
<a class="navbar-item">
Rangliste
</a>
<hr class="navbar-divider">
<a class="navbar-item">
Hilfe
</a>
<a class="navbar-item">
Einstellungen
</a>
<a class="navbar-item">
Mod-Forum
</a>
</div>
</div>
</div>
</div>
</div>
</header>
The dropdown menu should show a blue arrow. But it doesn't show in Chrome nor in Firefox. Any ideas how to fix this?
I'd expect the output to show a dropdown arrow on the right next to "Tränenreich". Hovering works perfectly fine.
Greetings
Your code combined with an unedited Bulma file is showing an arrow next to the dropdown item. See demo below (you'll have to see full page perhaps because nav is changed to hamburger menu from tablet down).
My guess is either you've edited the Bulma CSS in a way that is breaking the arrow OR you have some custom CSS that is conflicting with it.
The arrow is created using a :after pseudo element.
.navbar-link:not(.is-arrowless)::after,
.select:not(.is-multiple):not(.is-loading)::after {
border: 3px solid transparent;
border-radius: 2px;
border-right: 0;
border-top: 0;
content: " ";
display: block;
height: .625em;
margin-top: -.4375em;
pointer-events: none;
position: absolute;
top: 50%;
-webkit-transform: rotate(-45deg);
transform: rotate(-45deg);
-webkit-transform-origin: center;
transform-origin: center;
width: .625em;
}
Check your custom CSS to see if you have anything that is styling :after elements that is affecting the nav-item.
<link href="https://cdnjs.cloudflare.com/ajax/libs/bulma/0.7.4/css/bulma.min.css" rel="stylesheet"/>
<header class="navbar">
<div class="container">
<div class="navbar-brand">
<a class="navbar-item">
<span class="icon has-text-primary is-large">
<i class="mdi mdi-36px mdi-hexagon-multiple"></i>
</span>
<!-- <h1 class="title is-1">DNW</h1> -->
</a>
<span class="navbar-burger burger" data-target="navbarMenuHeroC">
<span></span>
<span></span>
<span></span>
</span>
</div>
<div class="navbar-menu">
<div class="navbar-end">
<a class="navbar-item">
Home
</a>
<a class="navbar-item">
Forum
</a>
<a class="navbar-item">
Spiele
</a>
<div class="navbar-item has-dropdown is-hoverable is-arrowless">
<div class="navbar-link">
<img class="nav-profilepic" src="https://static.wixstatic.com/media/1bfda4_6f8ae00a346644a89245f331fc6c6b8e~mv2_d_3476_5214_s_4_2.jpeg?dn=">
Tränenreich
</div>
<div class="navbar-dropdown">
<a class="navbar-item">
Profil
</a>
<a class="navbar-item">
Nachrichten
</a>
<a class="navbar-item">
Rangliste
</a>
<hr class="navbar-divider">
<a class="navbar-item">
Hilfe
</a>
<a class="navbar-item">
Einstellungen
</a>
<a class="navbar-item">
Mod-Forum
</a>
</div>
</div>
</div>
</div>
</div>
</header>
Using bulma there's an option to set a brand logo for the website. This brand, however, is being displayed differently across browsers. The image on discussion has the size of 640x160 and the fault is shown down below on Mozilla Firefox and Google Chrome respectively. The logo image is stretched vertically on chrome making it look ugly.
I inspected the DOM and I found that disabling a rule on .navbar-brand (display: flex) it corrects the brand size but it has other effects as in the mobile version the .navbar-burguer is located on another row (as it has a block display) and on Moz Firefox the links presented inside the navbar-menu disappear. What is causing this weird behavior over navbar-brand?
Edit
I use a static generator for the HTML pages, so you should see some liquid code for the navbar, and it is written as follows:
<nav class="navbar is-spaced has-text-weight-light" role="navigation">
<div class="container">
<div class="navbar-brand">
<img class="navbar-item" src="/assets/img/logos/direc.png" width="164" height="41">
<a role="button" class="navbar-burger" data-target="nav-menu">
<span aria-hidden="true"></span>
<span aria-hidden="true"></span>
<span aria-hidden="true"></span>
</a>
</div>
<ul id="nav-menu" class="navbar-menu">
{% for link in site.navigation %}
<li>{{ link.text }}</li>
{% endfor %}
<div class="navbar-end">
<li>LOGIN</li>
</div>
</ul>
</div>
</nav>
The image must be surrounded by a hyperlink.
<a class="navbar-item" href="#">
<img class="navbar-item" src="..." width="164" height="41">
</a>
The structure of the Bulma navbar is:
<nav class="navbar" role="navigation" aria-label="main navigation">
<div class="navbar-brand">
<a class="navbar-item" href="https://bulma.io">
<img src="https://bulma.io/images/bulma-logo.png" width="112" height="28">
</a>
<a role="button" class="navbar-burger burger" aria-label="menu" aria-expanded="false" data-target="navbarBasicExample">
<span aria-hidden="true"></span>
<span aria-hidden="true"></span>
<span aria-hidden="true"></span>
</a>
</div>
<div id="navbarBasicExample" class="navbar-menu">
<div class="navbar-start">...</div>
<div class="navbar-end">...</div>
</div>
</nav>
In total
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/bulma/0.7.2/css/bulma.min.css">
<nav class="navbar is-spaced has-text-weight-light" role="navigation">
<div class="container">
<div class="navbar-brand">
<a class="navbar-item" href="https://bulma.io">
<img class="navbar-item" src="http://via.placeholder.com/160/640" width="164" height="41">
</a>
<a role="button" class="navbar-burger" data-target="nav-menu">
<span aria-hidden="true"></span>
<span aria-hidden="true"></span>
<span aria-hidden="true"></span>
</a>
</div>
<div id="nav-menu" class="navbar-menu">
<div class="navbar-start">
<ul>
{% for link in site.navigation %}
<li>{{ link.text }}</li>
{% endfor %}
</ul>
</div>
<div class="navbar-end">
<a class="navbar-item" href="/login.html" class="button is-info">LOGIN</a>
</div>
</div>
</div>
</nav>