Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add margin with Angular Flex Layout?

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

like image 287
Christian Avatar asked Jan 08 '18 19:01

Christian


People also ask

What is Flex layout gap?

fxLayoutGap is used to specify gap between flex children items inside flex container. fxLayoutGap is an optional API. fxLayoutGap directive should be added to parent container i.e, flex container.

How do I use angular Flex layout?

Installation of Angular Flex-Layout Use the following command to use Angular Flex layouts in your projects. After installing flex layout we need to import flexLayoutModule in our app. module. ts file as shown below.

Is angular Flex layout deprecated?

2.0. This has been deprecated and removed.

How do I add Flex layout in Angularjs 11?

From your project folder, run the following command to install Flex Layout: npm install @angular/flex-layout @10.0. 0-beta. 32.


2 Answers

you may use fxLayoutGap="20px"

like image 63
Nelson Bwogora Avatar answered Sep 22 '22 14:09

Nelson Bwogora


You can use [style.margin] attribute.

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

like image 34
Santandar Avatar answered Sep 23 '22 14:09

Santandar