I'm working in a project where we have implemented ng-bootstrap and I'm now working on the toast-component and to it more suitible for our company.
What I'm trying to achive right now is to make a button inside of the toast to be on the far right while the text will be on the left. Right now the button comes directly after the text, which leaves a lot of space to the right of the button.
In the documentation (https://ng-bootstrap.github.io/#/components/toast/overview) they say:
We provide a dedicated ngb-toasts CSS class you could use, or write your own styles in case some specificities would be needed.
However per my understanding is that it only styles the toast it self and not the things inside of it, which is what I want to do.
I'm trying to achive this by adding in flexbox
SCSS
.toast {
display: flex;
flex-direction: row;
justify-content: space-between;
.text,
button {
align-self: center;
}
}
HTML
<ngb-toast *ngFor="let toast of toastService.toasts" [class]="toast.classname" class="toast">
<ng-template [ngIf]="isTemplate(toast)" [ngIfElse]="text" class="text">
<ng-template [ngTemplateOutlet]="toast.textOrTpl"></ng-template>
</ng-template>
<ng-template #text class="text">
<span>
{{ toast.textOrTpl }}
</span>
</ng-template>
<button class="btn ml-2" [class]="toast.classname" (click)="toastService.remove(toast)">
{{toast.button}}
</button>
</ngb-toast>
When I build the application and runs it, I can see in the browsers devtool that ng-bootstrap has added a new div with class="toast-body".
First question I have is why does it get added and for what reason?
This new div then contains my text and my button, which means that the they aren't affected by my flexbox that I added in the (now parentclass to toast-body).
I tried to address this issue in a simple way by adding in the newly created div in my style.css as well.
SCSS
.toast {
& >.toast-body {
display: flex;
flex-direction: row;
justify-content: space-between;
.text,
button {
align-self: center;
}
}
}
Sadly this approach doesn't work, the styles aren't hitting <div class="toast-body">.
What do I need to change / do in order to get the result I want?
How can I make sure that my styles trigger <div class="toast-body"> and the content inside of the div?
Related
I am trying to add a button to a mat-list-item. This is my current HTML template code:
<mat-selection-list
[multiple]="false"
[class.selected]="currentItem"
formControlName="itemListControl"
>
<mat-list-option
*ngFor="let item of items"
[value]="item.id"
>
<div style="display: flex; justify-content: space-between; align-items: center">
<div style="display: flex; align-items: center">
{{ item.name }}
</div>
<button mat-icon-button>
<mat-icon>edit</mat-icon>
</button>
</div>
</mat-list-option>
</mat-selection-list>
When I inspect the site in my browser, I can see that there is a 16px padding which moves the button to the left inside the list item:
I already tried removing it by adding this to my scss file for the component:
.mat-list-item {
padding-right: 0 !important;
}
For some reason, this does not have any effect. It seems like this is not even applied at all to the element. What am I doing wrong and how can I get rid of this padding (without causing any potentially bad side effects)?
Please use like below. It would work.
.mat-list-text {
padding-right: 0 !important;
}
Thanks!
Use the whole selector(instead of just .mat-list-text, copy all the selector part of the css highlighted in the image above) to remove the the padding, angular material is very hard to modify. Dont forget to add the !important aswell. I had to do this previously. I hope it will work for you aswell.
I am working on angular project. I am trying to make a collapse. My code is as follows
<div class="myClass">
<mat-accordion>
<mat-expansion-panel>
<mat-expansion-panel-header>
<mat-panel-title>
</mat-panel-title>
<mat-panel-description>
Description
</mat-panel-description>
</mat-expansion-panel-header>
</mat-expansion-panel>
</mat-accordion>
</div>
.myClass {
display: flex;
flex-direction: column;
margin-top: auto;
}
.mat-expansion-panel-header {
width: 99.7vw;
}
.mat-expansion-panel-header-description {
flex-grow: 1;
}
Reason for using margin-top:auto because I want this collapse at end of page. Once I click on collapse icon my collapse should open and it should look like as shown in image
Once my collapse open I want to have these types of card with my data and on opening of this collapse I want to 4-5 boxes/cards in row as shown but in case if more data is present then I want to slide using ">>" and show these box/cards. If I click "<<" on left hand side then it should move in that direction. How can I do that?
This is called a carousel. Not the easiest of things to do if you're new to angular. I would recommend just using owl carousel. There's an angular wrapper you can use. Or if you want to make a carousel on your own you can follow this guide.
For the collapsing of the carousel, you'd have to make a button that switches collapse state. Something like this-
<button (click)="collapsed = !collapsed"></button>
<div *ngIf="!collapsed" >
<carousel-component></carousel-component>
<div>
The sample code:
<div>
<mat-list fxLayout="row" dense>
<mat-list-item *ngFor="let label of labelsList"> <!-- just an array of strings -->
<button mat-button>
<mat-icon>cloud</mat-icon>
{{label}}
</button>
</mat-list-item>
</mat-list>
</div>
The result:
When I resize the browser window:
What I need: the buttons that don't "have room" to simply go on the next row.
How do I achieve this? I tried several combinations of CSS classes, properties, etc... nothing worked.
LATER EDIT: here's a complete reproducible example: https://angular-svt72k.stackblitz.io
mat-list-item is by default using the full width of its container and setting each item as display: block. To overrule this, you need to override the default Angular (Material) styling that comes with <mat-list>.
Setting .mat-list-test to display: flex and adding flex-flow: row wrap will make it go to the next line when there's not enough space available. Next to that, as said, the .mat-list-item styling is taking the full width. You can override it by setting display: initial and width: auto. Read more about flexbox at MDN.
CSS
.mat-list-test {
display: flex;
flex-flow: row wrap;
}
.mat-list-base .mat-list-item.mat-list-item-test {
display: initial;
width: auto;
}
See this example on StackBlitz to show the outcome.
I have a table, and in the tbody I have an inline edit popup that is absolute positioned.
I have a table footer that has display inline-block that contains buttons that are floated to the left and right. It looks like:
<div class="table-footer">
<div class="new-row-button">
<lightning-button variant="base" label="New Row" title="Add new row" icon-name="utility:add" onclick={addNewRow}></lightning-button>
</div>
<template if:true={changesWereMade}>
<div class="save-cancel-wrapper">
<lightning-button variant="brand" label="Ok" title="Make changes" onclick={handleSave}></lightning-button>
<lightning-button label="Cancel" title="Discard changes" onclick={revertChanges} class="slds-m-left_xx-small"></lightning-button>
</div>
</template>
</div>
What happens is I end up with this:
Even though the drop down supposedly has a z-index of 9001. The inline editor is inside the tbody tag. I have tried to raise the z-index of the tbody element, the table element, the inline editor, no luck in getting it to go over those buttons. The only thing I got to work was make the table-footer relative positioned and assign a z-index of -1. But this makes my buttons unclickable as they are now 'below' the page.
Does anyone have any css advice on how to get these buttons underneath the inline editor? (The table element and table-footer div are at the same level in the element hierarchy)
You can use the display flex css property for your footer to replace the float. Something like this :
footer {
display: flex;
flex-direction: row;
justify-content: space-between;
}
footer .button {
flex: 1;
}
footer .button:first-of-type {
align-self:start;
}
footer .button:last-of-type {
align-self:end;
}
<footer>
<button> Add me </button>
<button> Delete me </button>
</footer>
Hope to help you.
I have two React Components, Open and Save. The Save component contains an saveButton. The Open component contains an openButton, along with a stopButton and executeButton that shows up depending on the state of the component. I want my Open and Save components to be lined up next to each other, on the same row:
<div style={{display:'flex', flexDirection:'row}}>
<Save></Save>
<Open></Open>
</div>
The initial state looks like this:
The state where all four buttons show look like this:
Remember that Execute and Stop are part of the same Open component that contains the Open button. How can I align the components so that the Save/Open buttons are aligned all the way to the left, and the Execute/Stop buttons are aligned all the way to the right?
For clarification, I want the buttons formatted like this:
Save Open ------------all whitespace here--------------- Execute Stop
Edit: Here is the (very simplified) code for the components
// Save
<Button>Save</Button>
//Open
this.state = { executeFlag: false, stopFlag: false}
render(){
let stop;
let execute;
if(this.state.stopFlag) stopButton = <Button>Stop</Button>;
if(this.state.executeFlag) executeButton = <Button>Execute</Button>;
return(
<div>
<Button>Open</Button>{execute}{stop}
</div>
);
}
In your css maybe you could try setting the width of the buttons to 50% each and margin to zero. I believe flex will display on the same row as long as they can fit.
There are a few ways to do that... It really depends on the structure of your component and not just the control buttons. Here is a sample structure I usually use for something similar in plain HTML CSS for your reference
.container {
display: flex;
}
.component-b {
flex-grow: 1;
display: flex;
justify-content: space-between;
}
.sub-menu{
display: flex;
justofy-content: flex-end;
}
.button {
background: #1E88E5;
padding: 0.5rem 1rem;
margin: 0.5rem;
}
<div class="container">
<div class="component-a button">
Save
</div>
<div class="component-b">
<div class="button">
Open
</div>
<div class="sub-menu">
<div class="button">
Execute
</div>
<div class="button">
Stop
</div>
</div>
</div>
</div>
One way of achieving this is by wrapping two components set in one div and then wrapping all in div and using flex properties
<div style={{
display:'flex'
justifyContent:'space-between',
aligItems:'center'
}}
>
<div style={{display:'flex', flexDirection:'row',justifyConetent:'space-around'}}>
<Save></Save>
<Open></Open>
</div>
<div style={{display:'flex', flexDirection:'row',justifyConetent:'space-around'}}>
<Execute></Execute>
<Stop></Stop>
</div>
</div>