Setting column width in Angular Material TableIn this article, we will discuss how to define the

<mat-tab class="StatusTab" label="Status">
  <mat-table class="table mat-elevation-z10" [dataSource]="statusDetails">
    <ng-container matColumnDef="id">
      <mat-header-cell *matHeaderCellDef>Staff-id</mat-header-cell>
      <mat-cell *matCellDef="let staff">{{staff.staff_id}}</mat-cell>
    </ng-container>
    <ng-container matColumnDef="name">
      <mat-header-cell *matHeaderCellDef>Name</mat-header-cell>
      <mat-cell *matCellDef="let staff">{{staff.name}}</mat-cell>
    </ng-container>
    <ng-container style="width: 10px;" matColumnDef="status">
      <mat-header-cell *matHeaderCellDef>Status</mat-header-cell>
      <mat-cell *matCellDef="let staff">{{staff.status}}</mat-cell>
    </ng-container>
    <mat-header-row *matHeaderRowDef="columns"></mat-header-row>
    <mat-row *matRowDef="let staff;columns:columns"></mat-row>
 </mat-table>
</mat-tab>

CSS:

.table {
    width: 100%;
    margin:50px;
}

.mat-column-id {
    width: 32px;
    border-right: 1px solid black;
}

The length of the default width makes it scrollable to the right, and I need to adjust the width.

I attempted to utilize .mat-column-COLUMNNAME with no success. This method only seems to work with <table mat-table>.

Answer №1

Utilizing the max-width CSS property is essential in defining the maximum width of a column.

.mat-column-name {
  width: 50px;
  border-right: 1px solid gray;
  max-width: 50px;
}

Check out the live demonstration on StackBlitz

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

In Angular, when a component is clicked, it is selecting entire arrays instead of just a single item at a

I am currently working on implementing a rating feature using Angular. This component will be used to rate different languages based on how proficient I am with them. My issue lies in the fact that when I click on one array element, it automatically selec ...

Hovering over a white background will darken the CSS styling

A stunning image on a dark background Displayed on Hover (right) An elegant picture with a white background Activated on hover (incorrectly) I would like it to have a darkened effect on the white background as well. CSS Styling .photo background: n ...

When I apply a percentage to the height of a div element, it shrinks down to a height

I have several lists with a flex layout. Each column contains 3 list items, and the flex-basis is set to one-third. Within each li element, there is a div for a background image and another div to display text, which should be positioned below the image. ...

Looking to achieve a scroll effect with mix-blend-mode using JavaScript?

I am seeking a method to adjust the background color of a specific element based on the background itself. While CSS offers the mix-blend-mode property, I am looking to specify the color manually. Ideally, I would like to achieve the same effect using an ...

What measures can be taken to ensure a div does not extend beyond the boundaries of the screen?

Currently, I am facing an issue with a div that needs to be wider than the viewport width in order to achieve the desired effect. However, I do not want this div to extend beyond the right side of the screen and cause a horizontal scroll bar to appear. Des ...

What is the best way to design a table to allow for changing the colors of specific boxes in the table when clicked?

I am looking to create a feature where the elements in this table change color from the background color to red and back to the default color when they are clicked. Can anyone help me achieve this? <table align="center" style="height: 355px;" width=" ...

simplest method to brighten the image in this specific instance

I have a simple question. We are looking to enhance some static images by adding a lightening effect with an overlay. For example, when hovering over an image like on this website: (just for the lightening effect). What is the best approach to achieve thi ...

The alignment of the elements within the jumbotron is off

Hey there! I'm currently struggling to align the jumbotron with my calendar icon. Unfortunately, the elements of the jumbotron are not lining up properly. Could someone lend a hand in guiding me through this issue? Any ideas would be greatly appreciat ...

Adaptable arrow-shaped progress bar featuring sleek transparent borders

I am currently working on creating a progress bar similar to those commonly found in checkout processes. One issue I have encountered is that the borders between the arrows appear transparent, and the entire design needs to be responsive. So far, I have m ...

When viewing in full screen, the page cuts off abruptly in the middle

Having trouble creating a login page for my capstone project as the form I designed isn't filling up the fullscreen. I created a login form with Bootstrap columns but it only takes up half of the screen, leaving the other half white. body { ...

Using jQuery to dynamically disable links based on their HTML content

I am looking for a way to disable links based on the content within their HTML tags. In my website, there are several classified sections that may not always have content filled out. My goal is to visibly indicate to viewers when a classified section is em ...

Discover the step-by-step guide to implementing pagination using NG-ZORRO-Andt in your Angular

I am currently using NG-ZORRO Ant Design pagination on my HTML page and it is displaying correctly in my browser. However, I am struggling with linking the data from the API to the pagination feature. Here is the snippet of my HTML code: <div class ...

Utilizing Jquery Masonry to create a visually appealing layout with dynamically sized items

Greetings, I am currently facing an issue on my blog where the grid resizes when clicking on an item, but the masonry layout doesn't adjust accordingly and causes items to become disorganized. If you'd like to see an example of this issue in act ...

Tips for displaying a collection of items received from an asynchronous API request

I'm having a little trouble with an Angular (Javascript) issue. I am trying to retrieve a list of roles such as Admin, Viewer, and Guest from an API and display them on the user interface. Here are the things I've attempted: TS: ngOnInit() { ...

Prevent jQuery UI default styling from being applied

I'm curious about how to prevent jQuery UI from adding any classes when initializing $.tabs(). This is the structure of my HTML: <link href="smoothness/jquery-ui-1.8.20.custom.css" rel="stylesheet" type="text/css" /> ... <link href="estilos ...

What criteria does the browser use to select the media type for filtering CSS links?

One of the pages on my website includes a link to a stylesheet specifically for printing purposes. <link rel="stylesheet" href="../print.css" type="text/css" media="print" /> While most browsers ignore this link and its styles when rendering for sc ...

Angular project is missing both links and labels from dagre-d3 visualization

I've been working on integrating dagre-d3 with Angular, but I've hit a roadblock. Challenges: The links between nodes are not showing up. The labels on the nodes are not being displayed. Visit this link for reference I&ap ...

What is the best way to position the underline to appear beneath the second line in mobile view?

I have successfully incorporated a code to add a blue underline to the company name. However, in mobile view, the blue line appears on the first line. How can I adjust it so that it starts from the second line? Below is my CSS code: label { margin: 0; ...

Quick tip: Showing a default Font Awesome icon in Vue, Angular, or React when the desired icon is not found

Utilizing the <fa-icon> fontawesome component, I implement the library approach as follows: export const faIconsDefinitionsToRegister: IconDefinition[] = [ ...proRegularFaIcons, ...proSolidFaIcons, ...proLightFaIcons, ...proThinFaIcons, ... ...

Having difficulty altering the font in the WordPress tinymce editor

I've been attempting to update the font in the WordPress tinymce editor, but I'm running into issues. First, I created a tinymce-custom-editor.css file with the following code: @import url(https://fonts.googleapis.com/css?family=Open+Sans:400,7 ...