Learning to fix title placement using Angular Material

I am working with a column named project in angular material, and underneath the title are some checkboxes.

However, when you scroll down in the table, the column header name also scrolls instead of staying in place.

Here is the HTML code:

<ng-container matColumnDef="projects">
    <th mat-header-cell *matHeaderCellDef (mouseover)="show = true" (mouseout)="show = false" mat-sort-header i18n>
      <div class="mat-checkbox-project">

          <div class="row" *ngFor="let item of returnProjectCodes; let i = index">
            <mat-checkbox
              (click)="$event.stopPropagation()"
              (change)="filterProjects($event, i, item); selected=i"
              [checked]="selected === i"
              >{{ item.name }}
            </mat-checkbox>
          </div>
      </div>
      <div class="mat-sort-header-button-project">Project</div>
    </th>

    <td mat-cell *matCellDef="let row">{{ row.projects }}</td>
</ng-container>

And here is the crucial CSS code:

.mat-sort-header-button-project {
  //position: relative;
  position: fixed;
}

I have used position: fixed to align the column header name with the checkboxes below it. However, now the issue is that the column header title "project" will scroll along with the table content instead of remaining fixed in its position.

How can I make sure that it stays in place as well?

Thank you!

Answer №1

To achieve a sticky column or row, you don't need to include any external CSS.

You can check out this example on stackblitz provided in the official documentation.

I trust that this information proves helpful!

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

Using CSS or HTML to create a link or anchor that corresponds to specific image coordinates

I am envisioning something akin to a reverse image map. I have a sizable image (measuring over 2000x2000) and I would like to provide clickable links to specific coordinates on the image. Essentially, I want users to be able to click on certain items wit ...

Having trouble interacting with buttons while an overlay is open

When I try to use the overlay to move the text upwards and reveal buttons, I encounter an issue where I am unable to hover or click on those buttons. As soon as I try to interact with the buttons, the overlay and text come down, blocking my access. I have ...

Tips for incorporating a background color into a specific section

Code: .headline { font: 150 50px/0.8 'Pacifico', Helvetica, sans-serif; color: #2b2b2b; text-shadow: 3px 3px 0px rgba(0, 0, 0, 0.1), 7px 7px 0px rgba(0, 0, 0, 0.05); text-align: center; } <link href='http://fonts.googleapis.com ...

Tips for keeping several buttons in the spotlight: HTML/CSS/JS

Looking for a solution to keep multiple buttons toggled on? I'm not very familiar with JavaScript, but I know that adding a class on click won't work if there's already a class set. Maybe giving the element an ID could be a possible solution ...

Unique color selection for progress bars in Bootstrap Vue

Can the color of a progress bar be customized to any specific value in hexadecimal format? The preset colors like 'success' or 'danger' are not meeting our requirements, so I need to define my own color for the progress bar using a hex ...

The div inside an iframe is not displaying the desired background color as intended from the parent page

The code snippet below is included in the <head> section of the main page: <script type="text/javascript"> $(document).ready(function () { $('#innerframe').load(function () { $(this).contents().find($(".TitleB ...

CSS: Ensure the image perfectly fills the div

As I work on optimizing a news site for mobile, I am facing the challenge of making images fit within the entire width of the div container dynamically. The original image size is 240px in width, and I need to adjust it accordingly based on different scree ...

mention colleague(parent) instruction request

I have been exploring the use of metadata for setting HTML input attributes. After reading through the Attribute Directives Guide (https://angular.io/docs/ts/latest/guide/attribute-directives.html), I have developed the following implementation: import "r ...

Save the outcome of an HTML radio button selection and insert it into a MySQL database using PHP

My goal is to develop a dynamic web page with four radio buttons structured as follows: - Do you want to sleep? Yes No (buttons) and a submit button. - Do you want to eat? Yes No (buttons) and a submit button. After collecting the user's responses, ...

When the window size is minimized, containers are colliding with each other

On smaller window sizes or certain small screen phones, the buttons are overlapping the heading. Take a look at the code below: <style> body { font-family: Arial, Helvetica, sans-serif; } .x2 { position: absolute; left: 50%; top: 50%; tran ...

Resolve Bootstrap 4 responsive table header alignment glitch

Utilizing the d-none and d-md-block classes on a responsive table to hide certain columns at smaller screen sizes has been successful overall. However, there is one issue - the hidden columns seem to be slightly misaligned with the rest of the table. Despi ...

My attempts to troubleshoot the JavaScript function have all been unsuccessful

I am completely new to JavaScript and feeling a bit embarrassed that I'm struggling with this. My goal is to build a website that takes first and last names as input and generates email addresses based on that information. Despite my attempts, moving ...

Tips for troubleshooting an unresponsive navbar menu in Bootstrap

I created a homepage for my web development class, but when I try to click on the navigation menu links, they don't seem to work. I'm not sure what's causing this issue, so I would really appreciate some help. Here is the code I used: <n ...

Converting HTML Forms to Arrays

Hey there, I've been working on a pizza ordering program lately. My approach involved creating a form with different inputs and then attempting to collect that information into an array. Unfortunately, things didn't quite work out as expected, an ...

Concealing information from mobile email apps while showing it on non-media query reading desktops?

I need a reliable method to conceal content from mobile email clients. The ideal solution would hide content by default on devices that don't read media queries, but display on desktop clients that also don't read media queries. Currently, I am ...

Issue with nested grid layouts within the 960 grid system

I recently started working on a personal hobby website and decided to utilize the 960 css grid system for organizing my HTML elements on the page. After grasping the basic concept, I went ahead and created a preliminary version of the website, which is ho ...

What steps should I take to ensure my button remains intact and undamaged?

I'm encountering an issue with a CSS-styled button that appears distorted and displayed oddly across multiple lines when it is set as a link. However, if I change the button to an input element, it looks flawless. How can I ensure my link button displ ...

the use of double quotes within the value attribute of an HTML element

I have a variable: <?php $val = 'abc"def\'ad'; ?> My HTML code is as follows: <input type="text" value="<?php echo $val; ?>" name="xyz" /> Unfortunately, the input field does not display all of the text due to the ...

Create a stunning wave CSS effect using the :after and :before pseudo-elements

Hey there! I'm currently experimenting with creating a wave effect using CSS, specifically utilizing 'before' and 'after'. However, I've encountered an issue where I can't seem to position my waves correctly at the top a ...

The content is unclipped with a border-radius and hidden overflow

As I work on incorporating stylistic text inside rounded divs, I encounter a challenge where the text touches the top of the container. While I have successfully managed to customize various content elements such as nested divs and background images, this ...