I'm trying to create a page with a 20-60-20 flex fill layout but the div in the center which should make up 60% of the page is wider than its content so it makes its content look like it is off-center.
home.component.html:
<div fxLayout="row wrap" fxLayoutGap="20px grid">
<div *ngFor="let data of DUMMY_DATA">
<mat-card class="example-card" >
<img mat-card-image src="https://material.angular.io/assets/img/examples/shiba2.jpg" alt="Photo of a Shiba Inu">
<mat-card-content class="description-max-height">
<p>
{{data.description.length > 100 ? data.description.substring(0, 100) + '...' : data.description}}
</p>
</mat-card-content>
<mat-card-actions>
<button mat-button>LIKE</button>
<button mat-button>SHARE</button>
</mat-card-actions>
</mat-card>
</div>
</div>
home.component.css:
.example-card {
width: 250px;
height: 300px;
}
.description-max-height {
max-height: 30px;
}
app.component.html:
<mat-toolbar color="primary" style="margin-bottom: 20px">
<mat-toolbar-row>
<span>Some title</span>
<span class="toolbar-spacer"></span>
<button mat-button color="accent" (click)="openLoginDialog()">Log In</button>
<button mat-button color="accent" (click)="openSignupDialog()">Register</button>
</mat-toolbar-row>
</mat-toolbar>
<div fxLayout="row">
<div fxFlex="20"></div>
<router-outlet fxFlex="60"></router-outlet>
<div fxFlex="20"></div>
</div>
app.compoenent.css:
.toolbar-spacer {
flex: 1 1 auto;
}
How can I implement this so that will display the home.component.html on the center of the page without it being wider than it's contet?
You can find a Stackblitz example here
The router-outlet isn't a container. All the content routed to a router-outlet is rendered as a sibling node, not as an outlet's child node. So you should wrap the router-outlet with a 60%-width div.
Stackblitz demo
<div fxLayout="row">
<div fxFlex="20"></div>
<div fxFlex="60">
<router-outlet></router-outlet>
</div>
<div fxFlex="20"></div>
</div>
Adding fxLayoutAlign="centre" to the fxLayout div(top level div) in home-component.html should align the items/cards in centre in the container.
<div fxLayout="row wrap" fxLayoutGap="20px grid" fxLayoutAlign="center">
Related
I have created a div which shows an icon and text but I need to get the icon next to the text instead of above it. Currently looks like this:
And I need the icon to be next to the text like this (the icon needs to be displayed to the left of the text without moving the text so the header still aligns with the phone number):
Code:
<div fxLayout="row" fxLayoutAlign="space-around center">
<div>
<mat-icon svgIcon="phone-outline"> </mat-icon>
<h3>Customer Support</h3>
<label>123456</label>
</div>
<div>
<mat-icon svgIcon="email-outline"> </mat-icon>
<h3>Email</h3>
<label>test#email.com</label>
</div>
<div>
<mat-icon svgIcon="map-marker-outline"> </mat-icon>
<h3>Address</h3>
<label>address line 1</label>
</div>
</div>
I have three divs and using fxLayoutAlign aligns them next to each other accoss the page but if I put the icon into a seperate div the fxLayoutAlign moves it too far across the page. Is there a better way to align the divs?
Tried so far:
Tried putting the icon on the same line as the text but that puts the icon too close to the text:
<h3><mat-icon svgIcon="phone-outline"> </mat-icon> Customer Support</h3>
I need to have space between the icon and text and align it with the text.
Using CSS to try align still causes the icon to be too close to the text (and not aligned correctly):
.align-items { display: flex; justify-content: space-between; } .align-content { display: flex; align-items: center; }
Moving the icon in CSS using margins looks like its working but it has now moved the second line with the phone number:
The phone number should be directly under the header text (like in first screenshot above)
Here is another approach with pure css.
css
.align-items {
display: flex;
justify-content: space-between;
}
.align-content {
display: flex;
}
mat-icon {
margin-right: 10px;
}
.align-text-item {
display: flex;
flex-direction: column;
align-items: center;
}
h3 {
margin-top: 0px;
}
html
<div class="align-items ">
<div class="align-text-item">
<div class="align-content">
<mat-icon svgIcon="thumbs-up" aria-hidden="false" aria-label="Example thumbs up SVG icon"></mat-icon>
<div>
<h3>Customer Support</h3>
123456
</div>
</div>
</div>
<div class="align-text-item">
<div class="align-content">
<mat-icon svgIcon="thumbs-up" aria-hidden="false" aria-label="Example thumbs up SVG icon"></mat-icon>
<div>
<h3>Email</h3>
123456
</div>
</div>
</div>
<div class="align-text-item">
<div class="align-content">
<mat-icon svgIcon="thumbs-up" aria-hidden="false" aria-label="Example thumbs up SVG icon"></mat-icon>
<div>
<h3>Address</h3>
123456
</div>
</div>
</div>
</div>
Create a class for the divs wrapping the icon and heading. No fxLayout is needed
.align-icon{
display: flex;
align-items: flex-end;
}
You can use the matPrefix and matSuffix
<mat-form-field class="example-full-width">
<mat-icon matPrefix>mode_edit</mat-icon>
<mat-label>EXAMPLE</mat-label>
<mat-icon matSuffix>mode_edit</mat-icon>
</mat-form-field>
<div fxLayout="row" fxLayoutAlign="space-around center">
<div>
<h3>Customer Support<mat-icon svgIcon="phone-outline"> </mat-icon></h3>
</div>
<div>
<mat-icon svgIcon="email-outline"> </mat-icon>
<h3>Email</h3>
</div>enter code here
<div>
<mat-icon svgIcon="map-marker-outline"> </mat-icon>
<h3>Address</h3>
</div>
</div>
I do have the following HTML output:
so, as you can see the footer isn't matching...
my css component looks like this:
.card-equal-height {
display: flex;
flex-direction: column;
height: 100%;
}
.card-equal-height
.card-footer {
margin-top: auto;
height: 100%;
}
.card-equal-height.card-footer this part is not working somehow. I want the footer to be matching the order cards, no matter how long the description is.
html:
<div [ngClass]="{'card-highlight': product.listItemHovered}" class="card card-equal-height"
(mouseenter)="hoverListItem(product)"
(mouseleave)="hoverListItem(product)"
(click)="test(product)">
<div class="card-image">
<figure class="image is-square">
<img [src]="product.imageURL" alt="{{product.title}}">
</figure>
</div>
<div class="card-content">
<p class="title has-text-centered"> {{product.title}}</p>
<p class="subtitle">{{product.price | currency: "USD"}}</p>
</div>
<div class="card-footer">
<p class="card-footer-item">
<button (click)="removeFromCart(product); showRemoved()"
class="button is-danger is-outlined is-pulled-left is-small"> Remove
</button>
</p>
<p class="card-footer-item">
<button (click)="addToCart(product);showAdded()"
class="button is-outlined is-primary is-pulled-right is-small"> Add to Cart
</button>
</p>
</div>
</div>
I think you can achieve changing the height of "card-content" (forget change the .card-footer) using flex-grow
.card-equal-height
.card-content {
flex-grow:1;
}
For more about flex, check this link in css-tricks
Here is my HTML code snippet:
<mat-card-content>
<div fxLayout="row" fxFlex="1 0 0">
<div fxLayout="column">First</div>
<div fxLayout="column" style="margin-left:auto">Second</div>
</div>
</mat-card-content>
And CSS:
.mat-card-content {
color: rgba(0, 0, 0, 0.700);
}
I need to implement flex layouts inside the angular material card element so that two columns will responsive and will contain some text like in the magazine:
At this moment I have done mat-card-header and it's working right.
Any advice will be much appreciated.
Try like below :
<div fxLayout="row" fxLayoutGap="10">
<div fxFlex="50%">
<p> first div </p>
</div>
<div fxFlex="50%">
<p> second div </p>
</div>
</div>
2022 update :
Stackblitz demo
you have try this code its working as you want
<mat-card-content>
<div fxLayout="row" fxFlex="100" fxLayoutAlign="space-around center">
<div fxLayout="column">First</div>
<div fxLayout="column">Second</div>
</div>
</mat-card-content>
for better understanding
https://stackblitz.com/edit/angular-sozro8?file=src%2Fapp%2Fapp.component.html
If you want responsive for mobile device also, you can use flex-layout Responsive API.
<mat-card-content>
<div fxLayout.gt-sm="row" fxLayout="column" fxLayoutGap="16px">
<div fxFlex.gt-sm="50%" fxFlex>
First div
</div>
<div fxFlex.gt-sm="50%" fxFlex>
Second div
</div>
</div>
</mat-card-content>
I need to set height of data grid automatically depending og children height. I have 2 rows and 2 columns, but when I set height of card, and for example enter looooong text in "p" child, i just get hidden overflow.
Ideally it would be to have row height depending on heigher of 2 children.
Current html:
<mat-grid-list cols="2" rowHeight="200px" gutterSize="30px">
<mat-grid-tile [colspan]="1" [rowspan]="1">
<div fxFlex="100%" fxLayout="row">
<div fxFlex="20%" fxLayoutAlign="center center">
<img [src]="src" [matTooltipPosition]="'above'"/>
</div>
<div fxFlex="80%" fxLayout="column" fxLayoutAlign="center none">
<div>
<div>MY LABEL</div>
<p>loong description</p>
</div>
<div>
<a>link</a>
</div>
</div>
</div>
</mat-grid-tile>
etc..
Any ideas?
Thx...
I am using ui-view in md-content to display a list but its getting overflow i want list in md-content should be scrollable
here is my index.html
<div layout-lt-lg="row" class="screen-bg">
<div flex-lt-lg="100">
<!--header-->
<md-toolbar class="app-bar-bg" style="background-color: #9013fe;">
<div class="status-bar-bg"></div>
<div class="md-toolbar-tools">
<md-button class="md-icon-button" aria-label="Settings">
<!--<md-icon md-svg-icon="app/images/back1.svg"></md-icon>-->
</md-button>
<h2>
<span></span>
</h2>
<span flex=""></span>
<md-button class="md-icon-button" aria-label="Favorite">
<!--<md-icon md-svg-icon="app/images/a.svg"></md-icon>-->
</md-button>
</div>
</md-toolbar>
<!--content-->
<div>
<md-content>
<ui-view></ui-view>
</md-content>
</div>
</div>
</div>
here is my template
<md-list flex>
<md-list-item class="md-3-line" ng-repeat="broadCast in broadCasts">
<div class="md-list-item-text" layout="column" >
<h3>{{broadCast.name}}</h3>
<h3>{{broadCast.phone}}</h3>
</div>
</md-list-item>
</md-list>
To make the list scrollable:
Add a class to md-list.
<md-list class="make-scrollable" flex>
<md-list-item class="md-3-line" ng-repeat="broadCast in broadCasts">
<div class="md-list-item-text" layout="column">
<h3>{{broadCast.name}}</h3>
<h3>{{broadCast.phone}}</h3>
</div>
</md-list-item>
</md-list>
Style the md-list in your css file like so:
md-list.make-scrollable {
height: 600px; //Or any other height you wish
overflow-y: scroll;
}
That should make the overflowing content scrollable
You are using too many unnecessary container elements.
<div layout-lt-lg="row" flex-lt-lg="100" class="screen-bg">
<!--header-->
<md-toolbar class="app-bar-bg" style="background-color: #9013fe;">
<div class="status-bar-bg"></div> //desired controller buttons
<div class="md-toolbar-tools"></div> //desired controller buttons
</md-toolbar>
<!--content-->
<md-content flex ui-view>
</md-content>
</div>
Here is a working example. There are some changes but basic structure is almost same.