Today I have this code, basically when I click on Details button it opens a mat-menu but somehow I can not modify padding or width values of the menu :
<div id="box-upload" [hidden]="hiddenBoxUpload" *ngIf="filesExist">
<button mat-raised-button color="primary" [matMenuTriggerFor]="listFiles">Details</button>
<mat-menu class="filesList" #listFiles="matMenu">
<div *ngFor="let key of listkey">
<div *ngIf="detailsExist">
<!-- some stuff like mat-progress-bar and span>
</div>
</div>
</mat-menu>
</div>
css code :
.filesList {
width: auto;
padding: 15px;
}
What are the ways to change default padding and width of a mat-menu ?
You can either put the following in your global styles.css
.mat-menu-content {
padding: 30px;
}
Or you can use ::ng-deep in your component style sheet
::ng-deep .mat-menu-content {
padding: 30px;
}
Either solution above will allow you to modify the default padding of
all mat-menu's in your project.
Per this SO answer, until an alternative or replacement is provided for ::ng-deep the recommendation is to continue using it...
What to use in place of ::ng-deep
If you want to control only a specific mat-menu you will need to use your custom class in your CSS selectors
::ng-deep .filesList .mat-menu-content{
padding: 30px;
}
Revision
To adjust the width of the mat-menu without creating a scroll bar you need adjust the width of the root container cdk-overlay-pane... by adjusting the width of the mat-menu-content you are making that container wider than the root container, and because it is within the root container cdk-overlay-pane it creates a scroll bar by design. Try the following to widen the mat-menu without creating a scroll bar.
::ng-deep .cdk-overlay-pane .filesList{
min-width:600px;
}
Related
I am using angular material sidenav for some application settings functionality to achieve something like we have in Google.
The difference is I am calling this sidenav from another component and wrapping the router too so that it should open below the application Header.
<mat-sidenav-container class="main-sidenav">
<app-sidenav></app-sidenav>
<router-outlet></router-outlet>
</mat-sidenav-container>
The problem is when I open the sidenav It does not disable the background. It should automatically implement the backdrop style. Is there any way I can explicitly provide some style for the same or should we consider some different component? Please suggest. Below is the sample stackblitz example for the same scenario
Stackblitz link
Set the hasBackdrop flag to true in your html:
<mat-sidenav-container class="main-sidenav" hasBackdrop="true">
<app-sidenav></app-sidenav>
<router-outlet></router-outlet>
</mat-sidenav-container>
Per Material doc of sidenav:
Using your stackblitz, I have confirmed the backdrop renders by inspecting the elements:
But you are not seeing the dark shadow, because of missing css. To fix this, add following in your styles.css file.
.mat-drawer-backdrop {
background-color: rgba(0, 0, 0, 0.6);
}
Also, to make the sidenav appear like the screenshot in your question, you need to add some css properties in sidenav class.
.sidenav {
margin-top: 35px;
margin-left: 25px;
display: block;
width: 200px;
height: 100%;
position: fixed;
background: #FFF;
}
Result:
Stackblitz Demo
I am using an imported component which I can't change.
This component has a lot of nested divs.
Somewhere deep in these divs, I need to add a bottom margin to it.
Via Chrome DevTools, I am able to add the margin in one of the divs and achieve the
margin I want. But unable to get it to work when I try to add my css into my scss file.
How can I do this?
const MyComponent = props => {
return (
<div>
{/* This component is not in my control. I can't modify this component*/}
<ImportedComponent/>
</div>
);
};
When I see it in Chrome DevTools, the CSS is something like this.
If I were to add a margin style near the aCssClass or within the block of aCssClass via Chrome,
I get the margin I need. But as said, able to achieve in Chrome DevTools, but not via my scss file.
<div class="my-own-class">
<!-- This is all coming from ImportedComponent, each div has some css class -->
<div>
<div>
<div class="aCssClass anotherClass"> <!-- i want to be able to add my margin here, able to do it but only via Chrome dev tools-->
<div>
<div>
Some data
</div>
</div>
</div>
</div>
</div>
</div>
These are the styles I tried which makes no difference.
.my-own-class {
margin-bottom : 1em;
}
.my-own-class > div:nth-child(3) {
margin-bottom : 22px;
}
.my-own-class body .aCssClass {
margin-bottom: 22px;
}
body .aCssClass {
margin-bottom: 22px;
}
body > .aCssClass {
margin-bottom: 22px;
}
.my-own-class .aCssClass {
margin-bottom: 22px;
}
.my-own-class > .aCssClass {
margin-bottom: 22px;
}
Screenshot
At the highlighted portion, I added margin-bottom 10px under body .sc_marginRight_0 on the right panel which works.
i think it's just a specificity problem, try adding !important and it will work just fine.
.my-own-class .aCssClass {
margin-bottom: 22px !important;
}
Hello friend i am using Bootstrap-vue to display my data that query from database and i want it to display with the overflow-y like thisenter image description here
so how should i do. please tell me if you guy know how to solve it and here it is my code
<b-table
:items="search_transfer"
:fields="columnsheader"
:current-page="currentPage"
:per-page="perPage"
class="tbsearch"
></b-table>
and here it is what i get.
enter image description here
Hi simple solution is to make it display:inline-block;
add the below css to it
.tbsearch > tbody > tr > td:nth-child(4){
height: 65px;
overflow: auto;
display: inline-block;
}
Table cells in general can be a pain to apply some stylings to (due to their default display: table-cell)
Based on your first image, it looks like they are using a wrapper element around their cell content (based on the padding present around the outside of the scrollable area).
Use a custom slot for the cell rendering, and wrap your content in a <div> element that has your overflow-y class:
<template>
<b-table
:items="search_transfer"
:fields="columnsheader"
:current-page="currentPage"
:per-page="perPage"
>
<!--
I am making an assumption that the field you want to scroll is `description`
-->
<template v-slot:cell(description)="scope">
<div class="my-cell-overflow-y">
{{ scope.value }}
</div>
</template>
</b-table>
</template>
<style>
.my-cell-overflow-y: {
max-height: 2rem;
overflow-y: auto
}
</style>
See https://bootstrap-vue.js.org/docs/components/table#custom-data-rendering for details on custom data cell rendering.
I'm new Angular, CSS and Html.
I have used MatTabsModule(import { MatTabsModule } from '#angular/material/tabs';) to create tabs but I'm able to adjust/change height, background etc. In short I'm not able to override default properties of MatTabsModule's classes. Please help me.
Below is my CSS and Html code. I hope Typescript code is not needed.
HTML: -
<mat-card>
<mat-card-content>
<mat-tab-group class="tab-group" dynamicHeight>
<mat-tab *ngFor="let obj of tags">
<ng-template mat-tab-label>{{ obj.name }}</ng-template>
<div class="tab-content">
{{ obj.name }}
</div>
</mat-tab>
</mat-tab-group>
</mat-card-content>
CSS: -
.tab-group {
border: 1px solid #e8e8e8;
margin-bottom: 30px;
.unicorn-dark-theme & {
border-color: #464646;
}
}
.tab-content {
padding: 16px;
}
mat-card{
padding: 0px;
}
.mat-tab-label .mat-ripple {
min-width: 0;
height: 30px;
}
I'm not able to change height width background colour of these tabs.. :(
You cannot access the styles of child components from your css-file as the ViewEncapsulation.Emulated prevents styles from leaking to the rest of the app (as it should, don't change it).
If you use the ng-deep-selector like this: :host ::ng-deep mat-tab { ... } you can override default material styles that cannot be configured in any other way. I say that because making css leak from a component is considered a bad practice and if possible you should use #Input to pass on styles.
By the way, the :host is there so the styles leak only to this components children and not to the rest of the app
To override default style of angular material elements you need to prefix ::ng-deep in CSS style.
This is how you can control height and width of tabs
::ng-deep .mat-tab-label{
height: 27px !important;
min-height: 0px!important;
margin: 3px!important;
}
I have a bootstrap modal. There are two bootstrap tabs in that modal. "Work" button is the active tab. "Hire" button is the other tab. This modal wrapped with .col-md-8 class with these styles
#media (min-width: 992px) {
.col-md-8 {
width: 87%;
margin-top: 37px;
margin-bottom: 31px;
}
}
The problem is that the "Hire" tab content has a higher width than "Work" content. So it's looking his way.
I need to show "Hire" tab original width when someone click "Hire" tab. I know this happened because I wrapped with .col-md-8 class. Don't have any option to hide that main class on click and show "Hire" tab original width? I'm using meteor and react.
If you want to achieve this the best way is to use jquery.
You have to give id to work, hire button and work-content and hire-content.
for e.g.
HTML:
<button id="work-btn">Work</button> <button id="hire-btn">Hire</button>
<div id="work-content"> The content goes here </div>
<div id="hire-content"> The content goes here </div>
CSS:
.hire-content {
display:none;
}
Jquery:
$(document).ready(function(){
$("#hire-btn").click(function() {
$("#work-content").hide();
$("#hire-content").show();
});
});
Hope this helps. If you have any query feel free to ask.
You can increase width of modal-dialog by adding class.you can add class modal-lg. then you can expand width of modal when clicking Hire tab.