obela06
obela06

Reputation: 335

Problem to align all buttons right position

I use angular material(10.2.5) toolbar component and I want to have my three buttons to right, but i can't

<mat-toolbar color="primary">
    <mat-toolbar-row>
      <h3 [style.color]="'white'">Portail admin</h3>
  <div class="parent">
    <div class="children right-children">
      <div class="child"><a mat-flat-button >Liste des livres</a></div>
      <div class="child"><a mat-flat-button >Ajouter un livre</a></div>
      <div class="child"><a mat-flat-button >Deconnexion</a></div>
    </div>
  </div>
    </mat-toolbar-row>
  </mat-toolbar>

.parent {
    display: flex;
    width: 100%;
    height: 100px;
    align-items: center; 
    justify-content: space-between; 
  }
  
  .children {
    display: flex;
  }
  
  .child {
    margin: 0 5px;
    padding: 0 5px;
    font-size: 10px;
    color: #000;
  }

enter image description here

Any idea ? I want to align my three buttons to the left of a tolbar but I really can't do it.

For my html and css code, I used flexbox css.

Upvotes: 1

Views: 988

Answers (3)

Arman Amini
Arman Amini

Reputation: 31

just add this

  .child {  
    display: inline-block;
    margin: 0 5px;
    padding: 0 5px;
    font-size: 10px;
    color: #000;
  } 
  .right-children{
    position: relative;
    bottom:80px;   
    display: inline-block;
    margin-left:1000px ;
  }

Result: https://i.sstatic.net/6JD3h.png

Upvotes: 0

devdgehog
devdgehog

Reputation: 625

I tried to touch the less your css and use flex as you mentionned using them and not grid.

Basically, your mat-toolbar-row will be an horizontal flex. And your parent class will have justify-content: end;

mat-toolbar-row {
  display: flex;
  flex-direction: row;
  align-items: center;
  justify-content: space-between; 
}

h3 {
  white-space: nowrap;
}

.parent {
    display: flex;
    flex: 1;
    height: 100px;
    align-items: center; 
    justify-content: end; 
    white-space: nowrap;
  }
  
  .children {
    display: flex;
  }
  
  .child {
    margin: 0 5px;
    padding: 0 5px;
    font-size: 10px;
    color: #000;
  }
<mat-toolbar color="primary">
  <mat-toolbar-row>
    <h3 [style.color]="'white'">Portail admin</h3>
    <div class="parent">
      <div class="children right-children">
        <div class="child"><a mat-flat-button >Liste des livres</a></div>
        <div class="child"><a mat-flat-button >Ajouter un livre</a></div>
        <div class="child"><a mat-flat-button >Deconnexion</a></div>
      </div>
    </div>
  </mat-toolbar-row>
</mat-toolbar>

Upvotes: 1

AdDev
AdDev

Reputation: 476

Answer

.parent {
    display: flex;
    width: 100%;
    height: 100px;
    align-items: center; 
    justify-content: space-between; 
    
  }
  
  .children {
    display: flex;
}
  
  .child {
    margin: 0 5px;
    padding: 0 5px;
    font-size: 10px;
    color: black;
  }

.right-children{
  position:absolute;
  right:0;
}
<mat-toolbar color="primary">
    <mat-toolbar-row>
      <h3 [style.color]="'white'">Portail admin</h3>
  <div class="parent">
    <div class="children right-children">
      <div class="child"><a mat-flat-button >Liste des livres</a></div>
      <div class="child"><a mat-flat-button >Ajouter un livre</a></div>
      <div class="child"><a mat-flat-button >Deconnexion</a></div>
    </div>
  </div>
    </mat-toolbar-row>
  </mat-toolbar>

Added:

.right-children{
position:absolute;
right:0;
}

Upvotes: 2

Related Questions