Mat-Toolbar Align Items (left, center and right) - css

I developed a toolbar but I can't align elements on the same line, left, center and right.
Does anyone know how I can align these elements?
I notice that the elements with the name Align left are aligned to the left, the align center aligned to the center and the align right aligned to the right.
Thanks
Demo
Code
<mat-sidenav-content fxFlexFill>
<mat-toolbar color="primary">
<mat-toolbar-row>
<button mat-icon-button (click)="sidenav.toggle()" fxShow="true" fxHide.gt-sm>
<mat-icon>menu</mat-icon>
</button>
<div fxShow="true" fxHide.lt-md>
<a href="#" mat-button>Align left</a>
<a href="#" mat-button>Align left</a>
<a href="#" mat-button>Align center</a>
<a href="#" mat-button>Align center</a>
<a href="#" mat-button>Align right</a>
<a href="#" mat-button>Align right</a>
</div>
</mat-toolbar-row>
</mat-toolbar>

css. This expands to occupy max available space.
.flexExpand {
flex: 1 1 auto;
}
in your template use flexExpand utility to separate the items
<mat-toolbar>
<mat-toolbar-row>
<div >
<a mat-button [routerLink]="'/accounts'"> Accounts </a>
<a mat-button [routerLink]="'/create-account'"> Create Account </a>
</div>
<span class="flexExpand"></span>
<div >
<a mat-button [routerLink]="'/logout'"> Logout </a>
</div>
<mat-toolbar-row>
</mat-toolbar>

Are you looking for something like this ?
<div fxShow="true" fxHide.lt-md fxFlex fxLayout>
<!-- The following menu items will be hidden on both SM and XS screen sizes -->
<div fxFlex>
<a href="#" mat-button>Align left</a>
<a href="#" mat-button>Align left</a>
</div>
<div fxFlex fxLayoutAlign="center center">
<a href="#" mat-button>Align center</a>
<a href="#" mat-button>Align center</a>
</div>
<div fxFlex fxLayoutAlign="flex-end center">
<a href="#" mat-button>Align right</a>
<a href="#" mat-button>Align right</a>
</div>
</div>

Related

Display css line horizontally on a material toolbar

I want to put a horizontal icon sepation line on a "material toolbar" but it is always displayed vertically. here is the code :
<mat-toolbar color="primary">
<mat-toolbar-row>
<a> <img src="https://img.icons8.com/material-sharp/96/000000/link.png" class="logo" alt="logo" /></a>
<span class="example-spacer"></span>
<span flex></span>
<div>
<div class="md-toolbar-tools menu">
<a mat-button class="home"> <img
src="https://img.icons8.com/material-sharp/24/000000/cloud-network.png"></a>
<a class="cp"> <img src="https://img.icons8.com/material-sharp/24/000000/cloud-network.png"></a>
<a mat-button class="p"> <img
src="https://img.icons8.com/material-sharp/24/000000/cloud-network.png"></a>
<a mat-button class="cl"> <img
src="https://img.icons8.com/material-sharp/24/000000/cloud-network.png"></a>
<div class="separation-line"></div>
<a mat-button class="mu"> <img
src="https://img.icons8.com/material-sharp/24/000000/cloud-network.png"></a>
</div>
</div>
</mat-toolbar-row>
HTML has a built in horizontal rule tag (<hr>). You can learn more about it here.

Bulma CSS burger button position broken?

I am implementing a website with Meteor + Blaze + Bulma. I've basically created a navigation menu and got the burger button working for small devices. But the problem is, that the position of the burger button is messed up.
I would like to have it on the far right and vertically aligned with the logo. But the burger is right next to the logo and also slightly lower. I've tried "position: absolute; right:0;" but it keeps jumping back.
Is Bulma not suited for use with Blaze and Meteor? I have no other CSS files so far and just added Bulma in the header tags. So what could be the issue?
<template name="navigation">
<nav class="navbar is-transparent" role="navigation" aria-label="main navigation">
<div class="container">
<!-- Logo/Home -->
<div class="navbar-brand">
<a class="" href="{{pathFor route='Home'}}">
<img src="logo.svg" width="200" height="29" />
</a>
<!-- Burger Menu Button -->
<a role="button" class="navbar-burger burger" aria-label="menu" aria-expanded="false" data-target="navlist">
<span aria-hidden="true"></span>
<span aria-hidden="true"></span>
<span aria-hidden="true"></span>
</a>
</div>
<!-- Navigation Conent -->
<div id="navlist" class="navbar-menu">
<div class="navbar-start">
<a class="navbar-item" href="{{pathFor route='1'}}">
1
</a>
<a class="navbar-item" href="{{pathFor route='2'}}">
2
</a>
<a class="navbar-item" href="{{pathFor route='3'}}">
3
</a>
<a class="navbar-item" href="{{pathFor route='4'}}">
4
</a>
<a class="navbar-item" href="{{pathFor route='5'}}">
5
</a>
</div>
<!-- Navbar social -->
<div class="navbar-end">
<a class="navbar-item icon is-large" href="https://www.meetup.com/...">
<i class="fab fa-lg fa-meetup"></i>
</a>
<a class="navbar-item icon is-large" href="https://www.facebook.com/...">
<i class="fab fa-lg fa-facebook"></i>
</a>
<a class="navbar-item icon is-large" href="https://www.youtube.com/...">
<i class="fab fa-lg fa-youtube"></i>
</a>
</div>
</div>
</div>
</nav>
You need to add the class navbar-item to the container of your logo like that :
<div class="navbar-brand">
<a class="navbar-item" href="{{pathFor route='Home'}}"> <!-- Adding the class navbar-item -->
<img src="logo.svg" width="200" height="29" />
</a>
<!-- Burger Menu Button -->
<a role="button" class="navbar-burger burger" aria-label="menu" aria-expanded="false" data-target="navlist">
<span aria-hidden="true"></span>
<span aria-hidden="true"></span>
<span aria-hidden="true"></span>
</a>
</div>
Result on my own project :
Without navbar-item :
With navbar-item :

Bootstrap toggle sub menu flex column glitch from row to column on show

I made a submenu displayed in column when clicking on a button. The submenu is working and is shown in column, but there is a small glitch that show it in row during a second then switching it to a column.
Is there something missing in my code ?
<div class="container">
<div class="row">
<div class="col-6">
<div class="card">
<a class="p-0 text-decoration-none" data-toggle="collapse" href="#sub-menu" role="button">
<h6 class="card-header"><i class="fa fa-folder mr-2"></i>Open sub-menu</h6>
</a>
<div id="sub-menu" class="collapse nav flex-column bg-transparent">
<a class="nav-link btn btn-light mt-1 mb-1" href="#">First Link</a>
<a class="nav-link btn btn-light mb-1" href="#">Second Link</a>
<a class="nav-link btn btn-light mb-1" href="#">Third Link</a>
<a class="nav-link btn btn-light mb-1" href="#">Forth Link</a>
<a class="nav-link btn btn-light mb-1" href="#">Fifth Link</a>
</div>
</div>
</div>
Here is a fiddle of the example: https://jsfiddle.net/mp9007/4rm0fsvx/5/
Thanks
Just remove the nav class from the #sub-menu div. Probably the collapse and .nav are having style conflicts because .nav adds a display: flex to the element.

Mobile responsive top menu

I m using Clarity Design System with angular and the top menu is not mobile response
<header class="header-2">
<div class="branding">
<a class="nav-link">
<clr-icon shape="home" size="24"></clr-icon>
<span class="title">title</span>
</a>
</div>
<div class="header-nav">
<a class="nav-link nav-text" routerLink="/home">Home</a>
<a class="active nav-link nav-text"
routerLink="/login">Login</a>
</div>
</header>
I m expecting the top menu to turn into few lines (button) when the width is reduce
Or should I use different tags ?
To use responsive navigation, see the documentation on it at https://v2.clarity.design/navigation. You need to use the clr-main-container and clr-header elements to enable this behavior.
Given your markup, it should be something like the following.
<clr-main-container>
<clr-header class="header-2">
<div class="branding">
<a class="nav-link">
<clr-icon shape="home" size="24"></clr-icon>
<span class="title">title</span>
</a>
</div>
<div class="header-nav" [clr-nav-level]="1">
<a class="nav-link nav-text" routerLink="/home">Home</a>
<a class="active nav-link nav-text" routerLink="/login">Login</a>
</div>
</clr-header>
<div class="content-container">
<main class="content-area">
... the main body content goes here, probably a router-outlet
</main>
<nav class="sidenav" [clr-nav-level]="2">
... if you want a sidenav that is, or omit this
</nav>
</div>
</clr-main-container>
Yes it is working perfect now, it solved the behavior
So now is:
<clr-main-container>
<clr-header class="header-2">
<div class="branding">
<a class="nav-link">
<clr-icon shape="home" size="24"></clr-icon>
<span class="title">{{title}}</span>
</a>
</div>
<div class="header-nav" [clr-nav-level]="1">
<div class="header-nav">
<a class="nav-link nav-text" routerLink="/home">Home</a>
<a class="active nav-link nav-text" routerLink="/login">Login</a>
</div>
</div>
</clr-header>
Thank you very much

Bootstrap 4: Get full width dropdown of the main-menu container

I would like to have the dropdown show from the initial position for all menus and maintain the width of say 600px.
So even if i try to open the dropdown of say Main Menu 2 or Main Menu 3 or Main Menu 4, the dropdown should start from Main Menu 1 position. Here's a screen I made to understand better.
PS: This is on ng-Bootstrap 4 and hence some Angular related codes. Also, this is the generated HTML.
<ul class="nav justify-content-end">
<li class="nav-item">
<div class="d-inline-block dropdown" ngbdropdown="">
<button aria-haspopup="true" class="nav-link btn btn-link text-uppercase dropdown-toggle" id="dropdownBasic0" ngbdropdowntoggle="" aria-expanded="false">Main Menu 1</button>
<div aria-labelledby="dropdownBasic0" ngbdropdownmenu="" class="dropdown-menu" x-placement="bottom-left">
<div class="" ngbdropdownitem="">
<div class="row">
<div class="col-lg-4">
<h2 _ngcontent-c4="">Submenu 1</h2>
<a routerlink="/" ng-reflect-router-link="/" href="/">Menu A</a>
<a routerlink="/" ng-reflect-router-link="/" href="/">Menu B</a>
<a routerlink="/" ng-reflect-router-link="/" href="/">Menu C</a>
</div>
<div class="col-lg-4">
<h2 _ngcontent-c4="">Submenu 2</h2>
<a routerlink="/" ng-reflect-router-link="/" href="/">Menu D</a>
<a routerlink="/" ng-reflect-router-link="/" href="/">Menu E</a>
</div>
<div class="col-lg-4">
<h2 _ngcontent-c4="">Submenu 3</h2>
<a routerlink="/" ng-reflect-router-link="/" href="/">Menu F</a>
<a routerlink="/" ng-reflect-router-link="/" href="/">Menu G</a>
<a routerlink="/" ng-reflect-router-link="/" href="/">Menu H</a>
</div>
</div>
</div>
</div>
</div>
</li>
<li class="nav-item">
<div class="d-inline-block dropdown" ngbdropdown="">
<button aria-haspopup="true" class="nav-link btn btn-link text-uppercase dropdown-toggle" id="dropdownBasic1" ngbdropdowntoggle="" aria-expanded="false">Main Menu 2</button>
<div aria-labelledby="dropdownBasic1" ngbdropdownmenu="" class="dropdown-menu" x-placement="bottom-left">
<div class="" ngbdropdownitem="">
<div class="row">
<div class="col-lg-4">
<h2 _ngcontent-c4="">Submenu 1</h2>
<a routerlink="/" ng-reflect-router-link="/" href="/">Menu A</a>
<a routerlink="/" ng-reflect-router-link="/" href="/">Menu B</a>
<a routerlink="/" ng-reflect-router-link="/" href="/">Menu C</a>
<a routerlink="/" ng-reflect-router-link="/" href="/">Menu D</a>
<a routerlink="/" ng-reflect-router-link="/" href="/">Menu E</a>
</div>
<div class="col-lg-4">
<h2 _ngcontent-c4="">Submenu 2</h2>
<a routerlink="/" ng-reflect-router-link="/" href="/">Menu F</a>
<a routerlink="/" ng-reflect-router-link="/" href="/">Menu G</a>
<a routerlink="/" ng-reflect-router-link="/" href="/">Menu H</a>
<a routerlink="/" ng-reflect-router-link="/" href="/">Menu I</a>
<a routerlink="/" ng-reflect-router-link="/" href="/">Menu J</a>
<a routerlink="/" ng-reflect-router-link="/" href="/">Menu K</a>
<a routerlink="/" ng-reflect-router-link="/" href="/">Menu L</a>
</div>
<div class="col-lg-4">
<h2 _ngcontent-c4="">Submenu 3</h2>
<a routerlink="/" ng-reflect-router-link="/" href="/">Menu M</a>
<a routerlink="/" ng-reflect-router-link="/" href="/">Menu N</a>
<a routerlink="/" ng-reflect-router-link="/" href="/">Menu O</a>
</div>
</div>
</div>
</div>
</div>
</li>
</ul>
This is the Angular Code:
<ul class="nav justify-content-end">
<li class="nav-item">
<div ngbDropdown class="d-inline-block">
<button class="nav-link" id="dropdownBasic0"
ngbDropdownToggle>Main Menu 1</button>
<div ngbDropdownMenu aria-labelledby="dropdownBasic0">
<div class="" ngbDropdownItem>
<div class="row">
<div class="col-lg-4">
<a routerLink="/">Sub Menu 1</a>
<a routerLink="/">Sub Menu 2</a>
<a routerLink="/">Sub Menu 3</a>
</div>
<div class="col-lg-4">
<a routerLink="/">Sub Menu 1</a>
<a routerLink="/">Sub Menu 2</a>
<a routerLink="/">Sub Menu 3</a>
</div>
<div class="col-lg-4">
<a routerLink="/">Sub Menu 1</a>
<a routerLink="/">Sub Menu 2</a>
<a routerLink="/">Sub Menu 3</a>
</div>
</div>
</div>
</div>
</div>
</li>
<li class="nav-item">
<div ngbDropdown class="d-inline-block">
<button class="nav-link" id="dropdownBasic1"
ngbDropdownToggle>Main Menu 2</button>
<div ngbDropdownMenu aria-labelledby="dropdownBasic1">
<div class="" ngbDropdownItem>
<div class="row">
<div class="col-lg-12">
<a routerLink="/">Sub Menu 1</a>
<a routerLink="/">Sub Menu 2</a>
<a routerLink="/">Sub Menu 3</a>
<a routerLink="/">Sub Menu 4</a>
<a routerLink="/">Sub Menu 5</a>
<a routerLink="/">Sub Menu 6</a>
</div>
</div>
</div>
</div>
</div>
</li>
<li class="nav-item">
<div ngbDropdown class="d-inline-block">
<button class="nav-link" id="dropdownBasic2"
ngbDropdownToggle>Main Menu 3</button>
<div ngbDropdownMenu aria-labelledby="dropdownBasic2">
<div class="" ngbDropdownItem>
<div class="row">
<div class="col-lg-6">
<a routerLink="/">Sub Menu 1</a>
<a routerLink="/">Sub Menu 2</a>
<a routerLink="/">Sub Menu 3</a>
</div>
<div class="col-lg-6">
<a routerLink="/">Sub Menu 1</a>
<a routerLink="/">Sub Menu 2</a>
<a routerLink="/">Sub Menu 3</a>
</div>
</div>
</div>
</div>
</div>
</li>
</ul>
Since you are using ngbDropdown - i thought about going about the question in Angular;
instead of fixed width to an arbitary 600px, i am using BS4 classes so that we get a responsive solution where 50% of width is for logo, the other 50% for our navigation buttons
Since we had to take the contents of the dropdown menu away from the default position (which is now commented in SB) of just under the toggle button, we had to manage the toggle effect ourselves;
also did some styling to get the effect that we wanted
You can see a working demo here
relevant HTML code:
<div class="row">
<div class="col-6">
LOGO AREA
</div>
<div class="col-3 ">
<div ngbDropdown class="fullWidth">
<button class="btn btn-outline-primary" id="dropdownBasic1" ngbDropdownToggle (click)="toggleShow1()">dropdown1</button>
</div>
</div>
<div class="col-3 ">
<div ngbDropdown class="fullWidth">
<button class="btn btn-outline-primary" id="dropdownBasic2" ngbDropdownToggle (click)="toggleShow2()">dropdown2</button>
</div>
</div>
</div>
<div class='row'>
<div class='col-6'>
</div>
<div class='col-6'>
<div class='dropdown-menu show' *ngIf="show1" >
<button ngbDropdownItem>Action - 1</button>
<button ngbDropdownItem>Another Action</button>
<button ngbDropdownItem>Something else is here</button>
</div>
<div class='dropdown-menu show' *ngIf="show2">
<button ngbDropdownItem>Action - 2</button>
<button ngbDropdownItem>Another Action</button>
<button ngbDropdownItem>Something else is here</button>
</div>
</div>
</div>
relevant TS code:
import { Component } from '#angular/core';
#Component({
selector: 'ngbd-dropdown-basic',
templateUrl: './dropdown-basic.html',
styles: [`
.fullWidth .btn {width:100%;}
.dropdown-menu.show{ position: initial; width: inherit;}
`]
})
export class NgbdDropdownBasic {
show1: boolean = false;
show2: boolean = false;
toggleShow1() {
if (this.show1) { this.show1 = false; }
else {
this.show1 = true;
(this.show2) ? this.show2 = false : '';
}
}
toggleShow2() {
if (this.show2) { this.show2 = false }
else {
this.show2 = true;
(this.show1) ? this.show1 = false : '';
}
}
}

Resources