Angular FlexLayout giving different widths in phone view - css

I'm using flex layout to set material card inline on desktop view and vertically on phone view .
<div fxLayout="row" fxLayout.xs="column" fxLayoutAlign="center center" class="containercards">
<div fxFlex fxFlex.xs="100">
<mat-card class="container">
<mat-card-title>
Jeu Puissance 4 </mat-card-title>
<img mat-card-image src="../../assets/icons/puissance4.png">
<mat-card-content>
<p> Javascript, HTML/CSS </p>
</mat-card-content>
<mat-card-actions>
<button mat-button (click)="Puissance4Href()">Github</button>
<button mat-raised-button color="primary" (click)="openDialog('Puissance4')">Détails</button>
</mat-card-actions>
</mat-card>
</div>
<div fxFlex fxFlex.xs="100">
<mat-card class="container">
<mat-card-title>
Post-it </mat-card-title>
<img mat-card-image src="../../assets/icons/post-it.png">
<mat-card-content>
<p>Silex(PHP), HTML/CSS, AJAX </p>
</mat-card-content>
<mat-card-actions>
<button mat-button (click)="PostitHref()">Github</button>
<button mat-raised-button color="primary" (click)="openDialog('Postit')">Détails</button>
</mat-card-actions>
</mat-card>
</div>
<div fxFlex fxFlex.xs="100">
<mat-card class="container">
<mat-card-title>
Gestionnaire de tâches </mat-card-title>
<img mat-card-image src="../../assets/icons/planning.png">
<mat-card-content>
<p>Angular 4 , NodeJS , ExpressJS, Angular Material Components</p>
</mat-card-content>
<mat-card-actions>
<button mat-button (click)="PlannerHref()">Github</button>
<button mat-raised-button color="primary" (click)="openDialog('Gestionnaire')">Détails</button>
</mat-card-actions>
</mat-card>
</div>
</div>
The problem is that in phone view, I don't get cards with the same width size even if I set fxLayout.xs to 100.
Here's a stackblitz example.
Here I get the first and second with a smaller width, in my app only the first card have a smaller width.
Here's what I get in local

Your stackblitz doesn't include flex-layout as a dependency (and of course doesn't import FlexLayoutModule). When you include it, the flex layout code you've added will be applied and your problem will show.
You are trying to set the width of all your cards using width="70%" applied to <mat-card> but flex layout is adjusting the size of the parent <div>. And because your fxLayoutAlign setting is "center center", flex layout adjusts the widths of the divs for the row layout but not for the column layout. So the cards are actually 70%, but the divs are not. You need to apply a specific width to the divs for xs layouts. You might find that adding the xs specific layout alignment fxLayoutAlign.xs="start stretch" is all you need to do or at least a starting point. This will make all the divs full width, leaving all the cards at a consistent 70%.

Related

Angular Flex Layout row wrap with grid align not working

I've Angular v13 application with #angular/flex-layout also v13. The issue is Flex layout of type row wrap with Grid alignment is not working as expected. Below is the html code block. The application is hosted in stackblitz. If I remove the grid from fxLayoutGap, the layout is getting rendered without gutter space for second/subsequent rows.
<div class="cards-container" style="width: 100%; syntax: 100%;">
<div
fxLayout="row wrap"
fxLayoutAlign="start start"
fxLayoutGap="32px 12px grid"
>
<ng-container *ngFor="let item of cards">
<mat-card>
<mat-card-header>
<mat-card-title>{{ item }}</mat-card-title>
<mat-card-subtitle>subtitle</mat-card-subtitle>
</mat-card-header>
<img
mat-card-image
height="240px"
width="240px"
src="https://material.angular.io/assets/img/examples/shiba2.jpg"
alt="Photo of a Shiba Inu"
/>
<mat-card-content> </mat-card-content>
<mat-divider inset></mat-divider>
<mat-card-actions>
<button mat-button>Ok</button>
</mat-card-actions>
<mat-card-footer>
<mat-progress-bar mode="indeterminate"></mat-progress-bar>
</mat-card-footer>
</mat-card>
</ng-container>
</div>
</div>
How to configure #angular/flex-layout row wrap with grid?
EDIT
Here is the solution, updated code can be accessed at stackblitz. Basically we need to wrap a div around mat-card and add fxFlex with percentage. In my case I had set it to 25 so that 4 cards come in first raw.
<div class="cards-container" style="width: 100%; syntax: 100%;">
<div
fxLayout="row wrap"
fxLayoutAlign="start start"
fxLayoutGap="32px 12px grid"
>
<ng-container *ngFor="let item of cards">
<div fxFlex="25">
<mat-card>
<mat-card-header>
<mat-card-title>{{ item }}</mat-card-title>
<mat-card-subtitle>subtitle</mat-card-subtitle>
</mat-card-header>
<img
mat-card-image
height="240px"
width="240px"
src="https://material.angular.io/assets/img/examples/shiba2.jpg"
alt="Photo of a Shiba Inu"
/>
<mat-card-content> </mat-card-content>
<mat-divider inset></mat-divider>
<mat-card-actions>
<button mat-button>Ok</button>
</mat-card-actions>
<mat-card-footer>
<mat-progress-bar mode="indeterminate"></mat-progress-bar>
</mat-card-footer>
</mat-card>
</div>
</ng-container>
</div>
</div>

Flex layout display problem with Safari IOS using fx-layout="column"

We are currently using Angular as a front-end with fx-layout api for responsiveness.
When we are using the fxLayout="column" all elements are collapsed and doesn't seem to have any height.
What are the best practice when using fx-layout/flex to handle these scenarios ?
Using angular 9.0.0rc with flex-layout": "^8.0.0-beta.27
Browserslist setting
0.5%
last 2 versions
Firefox ESR
not dead
# IE 9-11
Here an image from IOS Safari (12)
Here an image from chrome
Here the repeated container which display the list seen in the image above
<div *ngIf="!(dataSource.loading$ | async)">
<mat-card class="pointer mb-2" *ngFor="let quotation of dataSource.quotations$ | async"
(click)="onClickRow(quotation)">
<mat-card-content fxLayout="row" fxLayoutGap.gt-xs="15px" fxLayout.xs="column" fxLayoutAlign="start center"
fxLayoutAlign.xs="center center">
<div fxLayout="column" fxLayoutAlign="center center">
<img class="profile-picture" *ngIf="authSvc.currentUser.hasSalesRights && quotation.customer.photoUrl"
[src]="quotation.customer.photoUrl" alt="">
<img class="profile-picture" *ngIf="authSvc.currentUser.hasCustomerRights && quotation.salesRep.photoUrl"
[src]="quotation.salesRep.photoUrl" alt="">
<img class="profile-picture" *ngIf="authSvc.currentUser.hasSalesRights && !quotation.customer.photoUrl"
src="https://storage.googleapis.com/edcommerce/businesslogic/images/placeholder/avatar.jpg" alt="">
</div>
<div fxLayout="column" fxFlex fxLayoutAlign.xs="center center">
<div fxLayout="row" *ngIf="authSvc.currentUser.hasSalesRights">
<span class="mat-body">{{quotation.createdDate | edDate}}</span>
</div>
<div fxLayout="row" fxLayoutAlign.xs="center center">
<span class="mat-h2 m-0">{{quotUtils.getVehicleDescription(quotation)}}</span>
</div>
<div fxLayout="row" fxLayoutGap="10px" *ngIf="authSvc.currentUser.hasSalesRights"
fxLayoutAlign="start center">
<span class="mat-body">{{ts('common.user.text.roles.customer')}}</span>
<span class="mat-body">{{quotation.customer.fullName}}</span>
</div>
<div fxLayout="row" fxLayoutGap="10px" *ngIf="authSvc.currentUser.hasBuyerRights"
fxLayoutAlign="start center">
<span class="mat-body">{{ts('common.user.text.roles.sales_rep')}}</span>
<span class="mat-body">{{quotation.salesRep.fullName}}</span>
</div>
<div fxLayout="row" fxLayout.xs="column" fxLayoutGap.gt-xs="10px" fxLayoutAlign="start center">
<span class="mat-body">{{ts('page.quotations.text.step_required')}}</span>
<span
class="mat-body-2 color-primary">{{enumUtils.Quotation.getStatusDescByRole(quotation.status,statusTypes)}}</span>
</div>
</div>
</mat-card-content>
</mat-card>
</div>
The problem with safari occur on this element (second container in the mat-card-content):
<div fxLayout="column" fxFlex fxLayoutAlign.xs="center center">
The flex on safari resulted with a weird exponential number in the CSS something like this : flex: 1 1 1.12e-16
Changing fxFlex for fxFlex="grow" generated on safari this css flex : 1 1 100% which fix the height !

flex layout not working properly

i am using flex layout module in angular 4, i trying card layout in desktop mode side by side need to show and the same when mobile mode it should be one below one, but its not working for me plz suggest proper code.
below is my code:
<div fxLayout="row" fxLayout-gt-xs="column">
<mat-card fxflex fxflex-gt-xs="100" fxFlex="33.33%">
<h2>Card title #1</h2>
<mat-card-content>
<p>Some content</p>
</mat-card-content>
</mat-card>
<mat-card fxflex fxflex-gt-xs="100" fxFlex="33.33%">
<h2>Card title #2</h2>
<mat-card-content>
<p>Some content</p>
</mat-card-content>
</mat-card>
using this version: #angular/flex-layout: ^2.0.0-beta.9
By default, block elements are placed in different rows. You just need to handle the orientation for xs screens.
Use this:-
<div fxLayout.xs="column">
<mat-card fxflex fxflex-gt-xs="100" fxFlex="33.33%">
<h2>Card title #1</h2>
<mat-card-content>
<p>Some content</p>
</mat-card-content>
</mat-card>
<mat-card fxflex fxflex-gt-xs="100" fxFlex="33.33%">
<h2>Card title #2</h2>
<mat-card-content>
<p>Some content</p>
</mat-card-content>
</mat-card>
</div>

How can I left align the text in an Angular Material stretched md-button?

Without tinkering too much with my own CSS, Is there an attribute or configuration I can use to left align the text in a md-button that is stretched a bit to fit a menu for example?
This is my current view
<md-sidenav md-is-locked-open="$mdMedia('gt-md')" layout="column">
<md-toolbar>
<h1 class="md-toolbar-tools">
<a ng-href="/" layout="row" href="/">
<div class="docs-logotype">Material Design</div>
</a>
</h1>
</md-toolbar>
<md-content flex role="navigation" layout="column">
<md-button>Button1</md-button>
<md-button>Button2</md-button>
</md-content>
</md-sidenav>
<md-content flex layout="column">
<md-toolbar>
<div class="md-toolbar-tools">
<button class="md-icon-button md-button" aria-label="Settings">
<md-icon md-svg-icon="images/icons/menu.svg" aria-hidden="true"></md-icon>
<div class="md-ripple-container"></div>
</button>
<md-button>Button1</md-button> <!-- how to left align this text inside a stretched button -->
<md-button>Button2</md-button>
<span flex=""></span>
<md-button>Right side button</md-button>
<button class="md-icon-button md-button" aria-label="More">
<md-icon md-svg-icon="images/icons/more_vert.svg" aria-hidden="true"></md-icon>
<div class="md-ripple-container"></div>
</button>
</div>
</md-toolbar>
<md-content flex>
Some content !!
</md-content>
</md-content>
Use empty <span> tag with a flex attribute, as shown below. You can even specify a value to the flex attribute to get a more specific location.
<div layout="row" layout-align="start center" flex>
<md-button>button 1 </md-button>
<span flex></span>
</div>
If you just want to align text inside a button, try setting the style attribute like this:
<md-button style="text-align:left">button </md-button>
You can do this if using within md-toolbar(Angular 4) Angular 6+:
Html
<mat-toolbar id="toolbar" color="primary" >
<mat-button>button 1 </mat-button>
<span class="spacing"></span>
<mat-button>button 2 </mat-button>
</mat-toolbar>
OR
<mat-toolbar id="toolbar" color="primary">
<mat-button>button 1 </mat-button>
<span style="flex: 1 1 auto;"></span>
<mat-button>button 2 </mat-button>
</mat-toolbar>
Your CSS if no styling in HTML:
.spacing {
flex: 1 1 auto;
}
Hope this helps someone.
in VueJS (nuxt-vue-material)
.md-button .md-ripple {
justify-content: unset;
}

Issue on Hiding Overflow in Bootstrap CSS

Can you please take a look at This Demo and let me know why the css overflow:hidden rule is not working for .switch class?
Please be informed that I do not want to change any thing in buttons and Switch mark ups and need to keep them as they are (Must not change the col-lg-x sizes)
<div class="panel panel-default">
<div class="panel-heading">Switch</div>
<div class="panel-body">
<div class="row">
<div class="switch col-lg-offset-1 col-md-offset-1 col-sm-offset-1 col-xs-offset-1 col-lg-10 col-md-10 col-sm-10 col-xs-10">
<button class="btn btn-primary norightradius col-lg-1 col-md-1 col-sm-1 col-xs-1">Yes</button>
<button class="btn btn-primary noradius col-lg-11 col-md-11 col-sm-11 col-xs-11">New Model</button>
<button class="btn btn-primary noleftradius col-lg-1 col-md-1 col-sm-1 col-xs-1">No</button>
</div>
</div>
</div>
</div>
Here is a shot of the required result
The Bootstrap grid system is based upon 12 columns. If you add up the columns consumed by your Yes button, title bar, and No button, you'll see that you've got 13 columns.
Just resize the title bar to be 10 columns instead of 11.
Change
<button class="btn btn-primary noradius col-lg-11 col-md-11 col-sm-11 col-xs-11">New Model</button>
To
<button class="btn btn-primary noradius col-lg-10 col-md-10 col-sm-10 col-xs-10">New Model</button>
See http://jsfiddle.net/wilsonjonash/Fz4CW/6/
And if you'd like the button to be hidden at certain screen sizes, try using the responsive utility classes(like hidden-sm or hidden-xs): http://getbootstrap.com/css/#responsive-utilities
Oh, and why does it wrap? The bootstrap grid classes use float:left to arrange the grid items. overflow:hidden only has the effect of containing floats, not hiding them.

Resources