Angular Material: Prevent Slider from Overlapping with Menu - css

I am just getting started with Angular Material and experiencing the problem that the slider component overlaps with my menu.
How can I make sure the slider is displayed below the menu - is there some non-overlapping flag I can set to accomplish this?
May html code looks like this:
<button mat-button [matMenuTriggerFor]="aboveMenu">Above</button>
<mat-menu #aboveMenu="matMenu" yPosition="above">
<button mat-menu-item>Item 1</button>
<button mat-menu-item>Item 2</button>
</mat-menu>
<button mat-button [matMenuTriggerFor]="belowMenu">Below</button>
<mat-menu #belowMenu="matMenu" [overlapTrigger]="false" yPosition="below">
<button mat-menu-item>Item 1</button>
<button mat-menu-item>Item 2</button>
</mat-menu>
<button mat-button [matMenuTriggerFor]="beforeMenu">Before</button>
<mat-menu #beforeMenu="matMenu" xPosition="before">
<button mat-menu-item>Item 1</button>
<button mat-menu-item>Item 2</button>
</mat-menu>
<button mat-button [matMenuTriggerFor]="afterMenu">After</button>
<mat-menu #afterMenu="matMenu" xPosition="after">
<button mat-menu-item>Item 1</button>
<button mat-menu-item>Item 2</button>
</mat-menu>
<mat-slider min="1" max="100" step="1" value="1"></mat-slider>
Thank you very much for your help!
Best regards, Sam

You could try to use flex-wrap in your styles this way:
display: flex; flex-wrap: wrap;
Here is a simple snippet adding it as an inline style but I do suggest that you add them in a separate file and reference the divs with classes.
I hope It helps you!
<div style="display: flex; flex-wrap: wrap;">
<div style="width: 100%;">
<button mat-button [matMenuTriggerFor]="aboveMenu">Above</button>
<button mat-button [matMenuTriggerFor]="belowMenu">Below</button>
<button mat-button [matMenuTriggerFor]="beforeMenu">Before</button>
<button mat-button [matMenuTriggerFor]="afterMenu">After</button>
</div>
<div style="width: 100%;">
<input type="range" min="1" max="100" value="50">
</div>
</div>
More information about flex and flex-wrap:
https://developer.mozilla.org/en-US/docs/Web/CSS/flex-wrap

Related

How to change mat-menu-item font size to small in Angular?

<button [matMenuTriggerFor]="menu" mat-button>Options</button>
<mat-menu class="mat-menu" #ServicesButton #menu="matMenu">
<button class="mat-menu-item" mat-menu-item>Option 1</button>
<button class="mat-menu-item" mat-menu-item>Option 2</button>
<button class="mat-menu-item" mat-menu-item>Option 3</button>
<button class="mat-menu-item" mat-menu-item>Option 4</button>
</mat-menu>
Right now the css for this menu is angular's default. I want to change it but it's not working through css class.
I have tried using css class. No results.
I have tried inline style. I was only able to change background color. Font size is not working.
Are you sure ? Check this.
css
.mat-menu-item{
font-size: 9px;
}
html
<button [matMenuTriggerFor]="menu" mat-button>Options</button>
<mat-menu class="mat-menu" #ServicesButton #menu="matMenu">
<button class="mat-menu-item" mat-menu-item>Option 1</button>
<button class="mat-menu-item" mat-menu-item>Option 2</button>
<button class="mat-menu-item" mat-menu-item>Option 3</button>
<button class="mat-menu-item" mat-menu-item>Option 4</button>
</mat-menu>
https://stackblitz.com/edit/mat-menu?file=app%2Fmenu-icons-example.html,app%2Fmenu-icons-example.css

Make a responsive stepper with 24 steps using Angular material? Is there any alternate responsive stepper option for the same?

How to make a 24 steps stepper responsive using Angular material? Is there any alternate responsive stepper option to achieve the same?
I have tried container-fluid but nothing works after a certain point I can view only 6 steps on small screen.
I have used below StackBlitz to create the MatStepper.
This a sample code what if I need 28 steps and how to make in responsive on small screen?
<mat-horizontal-stepper [linear]="isLinear" #stepper class="container-fluid" style="width: 100%;">
<mat-step [stepControl]="firstFormGroup">
<form [formGroup]="firstFormGroup">
<span>Name</span>
<mat-form-field>
<mat-label>Name</mat-label>
<input matInput placeholder="Last name, First name" formControlName="firstCtrl" required>
</mat-form-field>
<div>
<button mat-button matStepperNext>Next</button>
</div>
</form>
</mat-step>
<mat-step [stepControl]="secondFormGroup">
<form [formGroup]="secondFormGroup">
<mat-form-field>
<mat-label>Address</mat-label>
<input matInput formControlName="secondCtrl" placeholder="Ex. 1 Main St, New York, NY" required>
</mat-form-field>
<div>
<button mat-button matStepperPrevious>Back</button>
<button mat-button matStepperNext>Next</button>
</div>
</form>
</mat-step>
<mat-step>
<p>You are now done.</p>
<div>
<button mat-button matStepperPrevious>Back</button>
<button mat-button (click)="stepper.reset()">Reset</button>
</div>
</mat-step>
add your steps in html
<mat-step [stepControl]="thirdFormGroup">
<form [formGroup]="thirdFormGroup">
<mat-form-field>
<mat-label>something</mat-label>
<input matInput formControlName="thirdCtrl" placeholder="Ex. 1 Main St, New York, NY" required>
</mat-form-field>
<div>
<button mat-button matStepperPrevious>Back</button>
<button mat-button matStepperNext>Next</button>
</div>
</form>
</mat-step>
........
and add in your .ts the list of steps:
firstFormGroup: FormGroup;
secondFormGroup: FormGroup;
thirdFormGroup: FormGroup;
forthFormGroup: FormGroup;
cinqFormGroup: FormGroup;
sixFormGroup: FormGroup;
septFormGroup: FormGroup;
huitFormGroup: FormGroup;
......
add the list of action and ctrl in ngOInnit like this:
this.firstFormGroup = this._formBuilder.group({
firstCtrl: ['', Validators.required]
});
this.secondFormGroup = this._formBuilder.group({
secondCtrl: ['', Validators.required]
});
this.thirdFormGroup = this._formBuilder.group({
thirdCtrl: ['', Validators.required]
});
this.forthFormGroup = this._formBuilder.group({
forthreCtrl: ['', Validators.required]
});
this.cinqFormGroup = this._formBuilder.group({
cinqCtrl: ['', Validators.required]
});
.......
and it will work
my english is too bad , i come to you again to see if you resolved your problem ?
i tried my solution verticaly and horizontaly and i gave more than 10 sections
and i thinked about it , why you dont do a menu bar ? like this :
<mat-toolbar color="primary">
<button mat-button [mat-menu-trigger-for]="menu" fxHide="false" fxHide.gt-sm>
<mat-icon>menu</mat-icon>
</button>
<mat-menu x-position="before" #menu="matMenu">
<button mat-menu-item routerLink="/1">1</button>
<button mat-menu-item routerLink="/2">2</button>
<button mat-menu-item routerLink="/3">3</button>
<button mat-menu-item routerLink="/4"> 4</button>
<button mat-menu-item routerLink="/5">5 </button>
<button mat-menu-item routerLink="/6"> 6 </button>
<button mat-menu-item routerLink="/7"> 7 </button>
<button mat-menu-item routerLink="/8"> 8</button>
<button mat-menu-item routerLink="/9"> 9 </button>
<button mat-menu-item routerLink="/10">10 </button>
<button mat-menu-item routerLink="/11"> 11 </button>
<button mat-menu-item routerLink="/12"> 12 </button>
<button mat-menu-item routerLink="/13"> 13 </button>
<button mat-menu-item routerLink="/14"> 14 </button>
<button mat-menu-item routerLink="/15"> 15 </button>
<button mat-menu-item routerLink="/16"> 16 </button>
<button mat-menu-item routerLink="/17"> 17 </button>
<button mat-menu-item routerLink="/18">18 </button>
<button mat-menu-item routerLink="/19">19</button>
<button mat-menu-item routerLink="/20">20 Croisé</button>
<button mat-menu-item routerLink="/21">21</button>
<button mat-menu-item routerLink="/22">2</button>
<button mat-menu-item routerLink="/23">23</button>
<!--<button mat-menu-item>Help</button>-->
</mat-menu>
</mat-toolbar>
you just have to organise your rooting and you can have same fonctionality ?

How can i center a button inside of a div tag, to make it responsive for toggle device toolbar in Angular 8

I have the following problem: i have a <div> and inside of that tag i have a button, but i cant center the button vertically and horizontally inside the <div> also i want the button to be center for phones for that i saw it toggle device toolbar
Really dont know how to solve it, im new using Angular
Below i will let the code of my <div> that has the button inside, the picture of how the button is displayed also i'm using Angular material
Div tag code
<div *ngIf="nav_bar==false" class="colour large">
<button mat-icon-button [matMenuTriggerFor]="menu" aria-label="Example icon-button with a menu">
<mat-icon>more_vert</mat-icon>
</button>
<mat-menu #menu="matMenu">
<button mat-menu-item [routerLink]="'/'">
<mat-icon>dialpad</mat-icon>
<span>Inicio</span>
</button>
<button mat-menu-item [routerLink]="['/nosotros']">
<mat-icon>voicemail</mat-icon>
<span>Nosotros</span>
</button>
<button mat-menu-item [routerLink]="['/contacto']">
<mat-icon>notifications_off</mat-icon>
<span>Contacto</span>
</button>
</mat-menu>
<button class="mat-button col-xs-3" (click)="nav_bar=!nav_bar">
<img src="./assets/icons/baseline_visibility_white_18dp.png" class="mdc-icon-button__icon"/>
</button>
</div>
It's not an angular thing, it's an html/css thing. If you're going to use bootstrap you might want to check out the grid documentation a bit to better familiarize yourself with how it works, along with the utility classes. Something like this would probably be more what you're looking for.
<div *ngIf="nav_bar==false" class="colour large d-flex align-items-center">
<button mat-icon-button [matMenuTriggerFor]="menu" aria-label="Example icon-button with a menu">
<mat-icon>more_vert</mat-icon>
</button>
<mat-menu #menu="matMenu">
<button mat-menu-item [routerLink]="'/'">
<mat-icon>dialpad</mat-icon>
<span>Inicio</span>
</button>
<button mat-menu-item [routerLink]="['/nosotros']">
<mat-icon>voicemail</mat-icon>
<span>Nosotros</span>
</button>
<button mat-menu-item [routerLink]="['/contacto']">
<mat-icon>notifications_off</mat-icon>
<span>Contacto</span>
</button>
</mat-menu>
<button class="mat-button mx-auto" (click)="nav_bar=!nav_bar">
<img src="./assets/icons/baseline_visibility_white_18dp.png" class="mdc-icon-button__icon"/>
</button>
</div>

How to align divs horizontally with html?

I need to do a toolbar that consists of a Left-arrow button, a set of image buttons then a Right-arrow button
My requirements are:
the toolbar needs to be on one row
the toolbar needs to be centered horizontally
the set can have many image buttons (N is unknown)
when the window is too small in width the middle div should hide the image buttons that don't fit
To center everything horizontally I found this to work well on chrome:
<div style="display:-webkit-box; -webkit-box-pack:center; -webkit-box-align:center;" class="toolbar">
<button>LEFT</button>
<div style="overflow:hidden;">
<button style="height:72px">1</button>
<button style="height:72px">2</button>
<button style="height:72px">3</button>
<button style="height:72px">4</button>
<button style="height:72px">5</button>
<button style="height:72px">6</button>
<button style="height:72px">7</button>
<button style="height:72px">8</button>
<button style="height:72px">9</button>
</div>
<button>RIGHT</button>
</div>
But unfortunately the box parameters breaks the overflow:hidden style that is necessary if the middle set becomes too big to fit everything.
So is there another way of centering everything horizontally ?
As long as the elements are not floated, you can use text-align: center, along with display: inline block.
<div style="text-align:center;" class="toolbar">
<button style="display: inline-block;">LEFT</button>
<div style="overflow:hidden; display:inline-block;">
<button style="height:72px">1</button>
<button style="height:72px">2</button>
<button style="height:72px">3</button>
<button style="height:72px">4</button>
<button style="height:72px">5</button>
<button style="height:72px">6</button>
<button style="height:72px">7</button>
<button style="height:72px">8</button>
<button style="height:72px">9</button>
</div>
<button style="display: inline-block;">RIGHT</button>
</div>
Check this JSFiddle
There are a few ways to do this I'm not sure exactly what is best for you.
First be sure to set the width of your div element that contains the buttons. other wise it will default to 100% and the margin:0 auto won't work;
something like this
<style>
.horizantalAlign{
width:900px;
margin:0 auto;
}
</style>
<div class="horizantalAlign">
<button style="height:72px">1</button>
<button style="height:72px">2</button>
<button style="height:72px">3</button>
<button style="height:72px">4</button>
<button style="height:72px">5</button>
<button style="height:72px">6</button>
<button style="height:72px">7</button>
<button style="height:72px">8</button>
<button style="height:72px">9</button>
</div>
The overflow:hidden will only work if you give it a set width and height.
<div style="overflow:hidden; width:213px; height:73px;">
View the JSFiddle
Above answers not met the condition
when the window is too small in width the middle div should hide the image buttons that don't fit
overflow:hidden requires size
<div style="overflow:hidden; width:10%; max-width:10%; white-space:nowrap;
max-height:72px; height:72px">
http://jsfiddle.net/VzyRm/
The "margin: 0 auto" inspired me to find a solution. thanks
I am using a table instead of a div and it's then working well
http://jsfiddle.net/G3Vu6/4/
<div style="" class="toolbar">
<table style="margin: 0 auto; max-width: 100%">
<tr>
<td style=""><button>LEFT</button></td>
<td style="" >
<div style="overflow:hidden;max-height:72px">
<button style="height:72px">1</button>
<button style="height:72px">2</button>
<button style="height:72px">3</button>
<button style="height:72px">4</button>
<button style="height:72px">5</button>
<button style="height:72px">6</button>
<button style="height:72px">7</button>
<button style="height:72px">8</button>
<button style="height:72px">9</button>
<button style="height:72px">1</button>
<button style="height:72px">2</button>
<button style="height:72px">3</button>
<button style="height:72px">4</button>
<button style="height:72px">5</button>
<button style="height:72px">6</button>
<button style="height:72px">7</button>
<button style="height:72px">8</button>
<button style="height:72px">9</button>
<button style="height:72px">1</button>
<button style="height:72px">2</button>
<button style="height:72px">3</button>
<button style="height:72px">4</button>
<button style="height:72px">5</button>
<button style="height:72px">6</button>
<button style="height:72px">7</button>
<button style="height:72px">8</button>
<button style="height:72px">9</button>
</div>
</td>
<td><button style="">RIGHT</button></td>
</tr>
</table>
Try playing with the splitters in fiddler and you will see how it reacts beautifully.

Making button go full-width?

I want a button to take up the full width of the column, but having difficulties...
<div class="span9 btn-block">
<button class="btn btn-large btn-block btn-primary" type="button">Block level button</button>
</div>
How do I make the button as wide as the column?
Bootstrap v3 & v4
Use btn-block class on your button/element
Bootstrap v2
Use input-block-level class on your button/element
Why not use the Bootstrap predefined class input-block-level that does the job?
Full-Width Button <!-- BS2 -->
Full-Width Button <!-- BS3 -->
<!-- And let's join both for BS# :) -->
Full-Width Button
Learn more here in the Control Sizing^ section.
Bootstrap / CSS
Use col-12, btn-block, w-100, form-control or width:100%
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" rel="stylesheet"/>
<button class="btn btn-success col-12">
class="col-12"
</button>
<button class="btn btn-primary w-100">
class="w-100"
</button>
<button class="btn btn-secondary btn-block">
class="btn-block"
</button>
<button class="btn btn-success form-control">
class="form-control"
</button>
<button class="btn btn-danger" style="width:100%">
style="width:100%"
</button>
In case some are noticing btn-block not working anymore in bootstrap 5.1+:
It was dropped in bootstrap 5.1 (changelog):
Breaking Dropped .btn-block for utilities. Instead of using .btn-block
on the .btn, wrap your buttons with .d-grid and a .gap-* utility to
space them as needed. Switch to responsive classes for even more
control over them. Read the docs for some examples.
You can now make a button full width by adding the class w-100, as the authors do in their official Pricing example page:
<button type="button" class="w-100 btn btn-lg btn-outline-primary">
Sign up for free
</button>
Source: https://getbootstrap.com/docs/5.1/examples/pricing/
If you want to make a stack of block buttons, the official docs recommend the following :
<div class="d-grid gap-2">
<button class="btn btn-primary" type="button">Button</button>
<button class="btn btn-primary" type="button">Button</button>
</div>
Source: https://getbootstrap.com/docs/5.1/components/buttons/#block-buttons
I simply used this:
<div class="col-md-4 col-sm-4 col-xs-4">
<button type="button" class="btn btn-primary btn-block">Sign In</button>
</div>
use
<div class="btn-group btn-group-justified">
...
</div>
but it only works for <a> elements and not <button> elements.
see: http://getbootstrap.com/components/#btn-groups-justified
You should add these styles to a CSS sheet
div .no-padding {
padding:0;
}
button .full-width{
width:100%;
//display:block; //only if you're having issues
}
Then change add the classes to your code
<div class="span9 btn-block no-padding">
<button class="btn btn-large btn-block btn-primary full-width" type="button">Block level button</button>
</div>
I haven't tested this and I'm not 100% sure what you want, but I think this will get you close.
In Bootstrap 5, the class btn-block doesn't work anymore. But instead, you can add the class w-100 to the button to make it as wide as its container.
<link href="https://cdn.jsdelivr.net/npm/bootstrap#5.0.0-beta2/dist/css/bootstrap.min.css" rel="stylesheet" />
<div class="row"><div class=" col-5 ">
<a class="btn btn-outline-primary w-100 " href="# "><span>Button 1</span></a>
</div><div class="col-5 ">
<a class=" btn btn-primary w-100 weiss " href="# "><span>Button 2</span></a>
</div></div>
I would have thought this would be the most bootstrap-esque way of doing things:
<button type='button' class='btn btn-success col-xs-12'> First buttton baby </button>
All I'm doing is adding the class col-xs-12 to the button.
<div class="col-md-9">
<button class="btn btn-block btn-primary" type="button">Block level button</button>
</div>
In Bootstrap 3, this should be all you need. I believe btn-large was overriding the width of btn-block.
Update 2022:
You have multiple ways to make button full width.
You can add the w-100 to the class.
You can add d-grid and gap-2to a container above the button:
<div class="d-grid gap-2"> <!-- Here -->
<button class="btn btn-primary" type="button">Button</button>
</div>
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" rel="stylesheet"/>
<button class="btn btn-success col-12">
class="col-12"
</button>
<button class="btn btn-primary w-100">
class="w-100"
</button>
<button class="btn btn-secondary btn-block">
class="btn-block"
</button>
<button class="btn btn-success form-control">
class="form-control"
</button>
<button class="btn btn-danger" style="width:100%">
style="width:100%"
</button>
We can Use a Block Level Full-Width Button
Create block level buttons—those that span the full width of a parent—by adding .btn-block.
<button type="button" class="btn btn-primary btn-lg btn-block">
Block level button
</button>
<button type="button" class="btn btn-secondary btn-lg btn-block">
Block level button
</button>

Resources