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>
Related
I am using Bulma CSS (Ver. 0.9.4) for a responsive top and fixed navigation bar with dropdown and custom background color. Below is the code and the css. I dont know any javascript or jquery. My problem is:
1) The link with dropdown item does not have the same hover effect as the other links. How to have the same hover and text-color effect for the dropdown item?
2) How can I retain the same css style (background and hover) effect when on mobile mode?
3) The script tag has both javascript and jquery code. I had like to have either javascript or jquery code to help me understand the code better for future also.
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Index</title>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bulma#0.9.4/css/bulma.min.css" />
<link rel="stylesheet" href="index.css" />
<script src="https://code.jquery.com/jquery-3.6.1.js" integrity="sha256-3zlB5s2uwoUzrXK3BT7AX3FyvojsraNFxCc2vC/7pNI=" crossorigin="anonymous"></script>
<style>
* {
margin: 0px;
padding: 0px;
}
body {
background-color: #7e909a;
}
.bg-color {
background-color: #488a99;
}
.navbar-item {
color: white;
}
.box-shadow-y {
box-shadow: 0px 2px 10px rgba(0, 0, 0, 0.25);
}
.brandlogo {
margin-right: 10px;
}
</style>
</head>
<body>
<nav class="navbar bg-color box-shadow-y" role="navigation" aria-label="main navigation">
<div class="navbar-brand">
<a class="navbar-item" href="#">
<img src="water_elements.svg" width="40" height="64" /> BrandName
</a>
<a role="button" class="navbar-burger" aria-label="menu" aria-expanded="false" data-target="navbarBasicExample">
<span class="has-text-white" aria-hidden="true"></span>
<span class="has-text-white" aria-hidden="true"></span>
<span class="has-text-white" 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 class="navbar-item has-dropdown is-hoverable">
<a class="navbar-link has-text-white"> More </a>
<div class="navbar-dropdown bg-color is-hidden-mobile is-boxed">
<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">
<a class="navbar-item"> Logout </a>
</div>
</div>
</nav>
<script>
$(document).ready(function() {
$(".navbar-burger").click(function() {
$(".navbar-burger").toggleClass("is-active");
$(".navbar-menu").toggleClass("is-active");
});
});
document.querySelectorAll(".navbar-link").forEach(function(navbarLink) {
navbarLink.addEventListener("click", function() {
navbarLink.nextElementSibling.classList.toggle("is-hidden-mobile");
});
});
</script>
</body>
</html>
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.
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>
My header background color overflows past the page. I am wondering how to adjust its width so that it automatically fills whatever screen size without overflowing. I assume this has something to do with my width property on the "white" class, or because it is within a container. Basically it causes a horizontal scroll due to the background color extending, instead of just stopping at 100% width of the page. I appreciate any help I get for this, thanks a lot.
.white {
background-color: #fff;
position: relative;
}
.white:before {
content: "";
background-color: #fff;
position: absolute;
height: 100%;
width: 200vw;
left: -100vw;
z-index: -1;
}
<div class="container">
<nav class="navbar navbar-light navbar-expand-lg white row">
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarTogglerDemo01" aria-controls="navbarTogglerDemo01"
aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarTogglerDemo01">
<!-- Logo -->
<div class="logo">
<a href="#" class="navbar-brand">
<img src="{% static 'accounts/logo/logo.png' %}" height="40" width="40">
</a>
</div>
<!-- Search Box -->
<div class="search_wrapper">
<input type="text" placeholder="Search" class="search_input">
<button class="search_button">🔍</button>
</div>
<!-- Nav List -->
<ul class="navbar-nav ml-auto">
<span class="middle">
<li class="nav-item">
<a href="#" class="nav-link">
<img src="{% static 'accounts/blah/blah.png' %}" height="20" width="20" id="home"> Random
</a>
</li>
<li class="nav-item">
<a href="#" class="nav-link">
<img src="{% static 'accounts/blah/blah.png' %}" height="20" width="20" id="lessons"> Random
</a>
</li>
<li class="nav-item">
<a href="#" class="nav-link">
<img src="{% static 'accounts/blah/blah.png' %}" height="30" width="30" id="teacher"> Random
</a>
</li>
<li class="nav-item">
<a href="#" class="nav-link">
<img src="{% static 'accounts/icons/blue.png' %}" height="20" width="30" id="msg"> Random
</a>
</li>
</span>
<!-- Avatar Dropdown -->
<span class="right">
<li class="nav-item dropdown">
<a class="nav-link dropdown-toggle" href="#" id="navbarDropdown" role="button" data-toggle="dropdown" aria-haspopup="true"
aria-expanded="false">
<img src="{% static 'accounts/blah/blah.png' %}" height="30" width="25"> Blah
</a>
<div class="dropdown-menu" aria-labelledby="navbarDropdown">
<a class="dropdown-item" href="#">Random</a>
<a class="dropdown-item" href="#">Random</a>
<a class="dropdown-item" href="#">Random</a>
<div class="dropdown-divider"></div>
<a class="dropdown-item" href="#">Random</a>
</div>
</li>
</span>
</ul>
</div>
</nav>
Use <div class="container-fluid"> instead of <div class="container">
This is vanilla CSS without bootstrap since this is what I'm using.
I can't guarantee that this works the same with bootstrap.
You are trying to use
width: 200vw;
since 1vw is relative to 1% of the width of the viewport you are giving your content a width of 2 times the width of th viewport.
width: 100vw;
margin: 0;
padding: 0;
should make it span the whole width of the screen.
You just have to make sure that there are no paddings or margins either on the left or tight side.
Here a small refreshment for the units.
https://www.w3schools.com/cssref/css_units.asp
You could also try some negative margin:
.white {
background-color: #343434;
position: relative;
width:100vw;
margin: -10px;
}
should work fine for you
codepen: https://codepen.io/ironlors/pen/bjYOpQ
I'm making a website for my game coming up soon and it'll serve as a commercial piece (one-page website) for the game itself.
I am in the starting phase and is working on the navbar at the top (Yes I am using Bootstrap) but the font-awesome glyphs that I use don't seem to center up right compared to the text in the body:
As you see on the picture the Android and Apple icons are off-center compared to the text underneath. I get that it might be because of the icons I have on the right and left throwing it off center but I am fairly new to web development so I just request some help to fix that up :)
<div class="header">
<div class="well" style="height: 100%">
<nav class="navbar navbar-default navbar-fixed-top">
<div class="container-fluid">
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse"
data-target=".navHeaderCollapse"
aria-expanded="false"> <span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
</div>
<div class="collapse navbar-collapse navHeaderCollapse">
<ul class="nav navbar-nav navbar-left">
<li>
<a href="index.html">
<span><img alt="Dynamic Realities" width="42" height="42" src="img/Cogfire-notext.png"></span>
</a>
</li>
</ul>
<ul class="nav navbar-nav">
<li>
<a target="_blank" href="#">
<span class="fa fa-android" style="color: #5cb85c; font-size: 42px;"></span>
</a>
</li>
<li>
<a target="_blank" href="#">
<span class="fa fa-apple" style="color: #c0c0c0; font-size: 42px;"></span>
</a>
</li>
</ul>
<ul class="nav navbar-nav navbar-right">
<li>
<a target="_blank" href="http://www.twitter.com/DynRealities">
<span class="fa fa-twitter-square" style="color: #31b0d5; font-size: 42px;"></span>
</a>
</li>
<li>
<a target="_blank" href="http://www.facebook.com/DynamicRealities">
<span class="fa fa-facebook-square" style="color: #204d74; font-size: 42px;"></span>
</a>
</li>
<li>
<a target="_blank" href="http://www.youtube.com/DynamicRealities">
<span class="fa fa-youtube-square" style="color: #c12e2a; font-size: 42px;"></span>
</a>
</li>
<li>
<a target="_blank" href="#">
<span class="fa fa-tumblr-square" style="color: #204d74; font-size: 42px;"></span>
</a>
</li>
</ul>
</div>
</div>
</nav>
</div>
</div>
With the following CSS applied:
#media (min-width: 768px) {
.navbar .navbar-nav {
display: inline-block;
float: none;
vertical-align: top;
}
.navbar .navbar-collapse {
text-align: center;
}
}
Have a look at my fiddle, only added padding to make the logo center
http://fiddle.jshell.net/Jinukurian7/oqyvprxz/