Reputation: 335
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;
}
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
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
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
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