13

How can I add margin or padding to a container when using the Flex Layout Module?

Template:

<div class="container">
  hell
  <div fxLayout="column" fxLayoutAlign="center center">
    <mat-card fxFill>Simple card test</mat-card>
  </div>
</div>

Style:

.container{
    margin: 60px;
}

I noticed it doesn't seem to be adding the correct amount of margin. You'll be able to see in the screenshot, the flex container has less margin than the text outside of it.

enter image description here

Christian
  • 2,676
  • 3
  • 15
  • 25

5 Answers5

12

You can use [style.margin] attribute.

div fxLayout="row" fxLayoutGap="12px" [style.margin-top]="'12px'" [style.margin-left]="'10px'"

Santandar
  • 121
  • 1
  • 3
7

You can use multiple flexbox container for that.

See fxLayoutGap too : https://github.com/angular/flex-layout/wiki/fxLayoutGap-API

aksjer
  • 71
  • 1
  • 4
7

you may use fxLayoutGap="20px"

Nelson Bwogora
  • 2,225
  • 1
  • 18
  • 21
1

No Worries!

you can add as below,

<div class="container">
  hell
  <div fxLayout="column" fxLayoutAlign="center center" [style.marginBottom.px]="10" [style.marginTop.px]="10">
    <mat-card fxFill>Simple card test</mat-card>
  </div>
</div>

[style.marginBottom.px]="10" [style.marginTop.px]="10"

Sounds like this work.

Srinivasan N
  • 733
  • 8
  • 9
0

just to make sure that you have referenced your css in your component:

import {Component} from '@angular/core';

@Component({
  selector: 'card-overview-example',
  templateUrl: './card-overview-example.html',

  <-- make sure your css is referenced- -->
  styleUrls: ['./card-overview-example.css']
})

export class CardOverviewExample {}

Alternatively you could try an inline style like:

<div style="margin:60px">
  hell
  <div fxLayout="column" fxLayoutAlign="center center">
    <mat-card fxFill>Simple card test</mat-card>
  </div>
</div>

Then debug with F12:

enter image description here

Daniel
  • 9,491
  • 12
  • 50
  • 66
  • fire up the developer toolbar - F12 - in Chrome an debug your container class. I updated the answer – Daniel Jan 08 '18 at 20:33