Navbar brand being stretched on bulma - html

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>

Related

Transparent Navbar with Bulma Css not working

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>

How to set bulma navbar dropdown open on the left not on the right?

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 :

bulma navbar menu open by default on mobile

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.

Bootstrap 3 navbar not rendering properly in Microsoft Edge

I have a navbar in my project which renders as expected in chrome, FF and IE 11, but somehow Internet Edge is special.
Below is the html code which defines the navbar:
<nav class="navbar navbar-default navbar-static-top" style="margin-bottom: 0px" id="mainNavbar">
<div class="container-fluid">
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar" aria-expanded="false" aria-controls="navbar">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a href="desktop.aspx">
<img id="Image1" style="padding-top:0px; padding-left:0px;width:200px;height:44px;" src="logo.png"/>
</a>
</div>
<div id="navbar" class="navbar-collapse collapse">
<ul class="nav navbar-nav navbar-right">
<li>
<a href="affected.aspx"><img src="log-incident-icon.svg" style="height:25px;"/>
<span style="margin-left:5px;">Log an incident</span></a></li>
<li id="adminMenuItem">
<a href="myIncidents.aspx">
<img src="my-incidents-icon.svg" style="height:25px;"/>
<span style="margin-left:5px;">My Incidents</span>
</a>
</li>
<li>
<a href="incidentRegister.aspx">
<img src="allocate-incident-icon.svg" style="height:25px;"/>
<span style="margin-left:5px;">Allocate incident</span>
</a>
</li>
<li>
<a href="dashboard.aspx">
<img src="dashboard-icon.svg" style="height:25px;"/>
<span style="margin-left:5px;">Dashboard</span>
</a>
</li>
<li>
<a href="admin.aspx">
<img src="settings-icon.svg" style="height:25px;"/>
<span style="margin-left:5px;">Admin</span>
</a>
</li>
<li>
<a href="default.aspx">
<img src="logout-icon.svg" style="height:25px;"/>
<span style="margin-left:5px;">Log out</span>
</a>
</li>
</ul>
</div>
</div>
</nav>
Below is what the navbar should look like:
And here is what Microsoft Edge spits out:
The link tags seem to be taking up all the space, but I can't figure out a way to make them shrink to the width of the content without breaking the layout further. Any suggestions?
I've just found out that I have the same issue.
When I removed the svg icons, it worked. Try using .png, .jpg or whatever. Must do the same for items with icons inside the menu!
Header file is written to IE compatibility guide. Create a new CSS file, dedicated to deal with Internet explorer browser compatibility problems.

Bootstrap Collapse menu not collapsing?

Ok My Site is freaking done!! I just have to make my menu responsive.... and the hover effects on my site won't allow the links to be responsive so I want to make this a collapse menu but for some reason its not working. I displays properly but once I go to view it on my mobile device it shows the button with the bars in it but it doesn't toggle my menu can you help me figure out what's wrong?
<nav class="navbar navbar-default navbar-fixed-top">
<div class="container-fluid">
<div class="col-sm-2 col-md-2"></div>
<div class="col-sm-8 col-md-8" style=" border-radius:5px; border-bottom-color:Silver; border:3px; border-top-color: transparent !important; background-color:rgba(0,0,0,.8)">
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#homenav">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
</div>
<div class="collapse navbar-collapse" id="homenav">
<ul class="nav navbar-nav">
<li><a href="pages/home.html" class="menu_nav demo-4">
<span>
<span>Home</span>
<span>-Home-</span>
<span></span>
</span>
</a></li>
<li> <a href="pages/artist.html" class="menu_nav demo-4">
<span>
<span>Roster</span>
<span>-Roster-</span>
<span></span>
</span>
</a></li>
<li>
<a href="pages/order.html" class="menu_nav demo-4">
<span>
<span>Brands</span>
<span>-Brands-</span>
<span></span>
</span>
</a>
</li> <li>
<a href="pages/music.html" class="menu_nav demo-4">
<span>
<span>Music</span>
<span>-Music-</span>
<span></span>
</span>
</a>
</li>
<li>
<a href="pages/videos.php" class="menu_nav demo-4">
<span>
<span>Videos</span>
<span>-Videos-</span>
<span></span>
</span>
</a> </li>
<li>
<a href="pages/videos.php" class="menu_nav demo-4">
<span>
<span>Store</span>
<span>-Store-</span>
<span></span>
</span>
</a>
</li>
<li>
<a href="pages/services.html" class="menu_nav demo-4">
<span>
<span>Services</span>
<span>-Services-</span>
<span></span>
</span>
</a>
</li>
<li>
<a href="#" class="menu_nav demo-4">
<span>
<span>Resources</span>
<span>-Resources-</span>
<span></span>
</span>
</a> </li>
</ul>
</div>
<div class="col-sm-2 col-md-2"></div>
</div>
</nav>
<!--End Of Navigation-->
I think you are missing javascript files. Include this to your project and it should work.
<script src="https://code.jquery.com/jquery-1.12.0.js"></script>
<!-- Latest compiled and minified JavaScript -->
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js" integrity="sha384-0mSbJDEHialfmuBBQP6A4Qrprq5OVfW37PRR3j5ELqxss1yVqOtnepnHVP9aJ7xS" crossorigin="anonymous"></script>