Action buttons on material cards extend beyond the boundaries of the card content on both the left and right sides

Check out this Angular 10.2 Material sample where the action buttons on the right and left extend beyond the card-content:

https://i.sstatic.net/Btxy1.png

The "Create account" button's right edge should align with the right edge of the fields, and the "Sign in" button's left edge should align with the left edge of the fields.

In the image, green represents the padding area, orange represents the margin, and blue represents the action area. Why is there misalignment between the blue/green and the orange?

The HTML code is as follows:

<mat-card class="signup-card">
  <mat-card-header>
    <mat-card-title>The title</mat-card-title>
    <mat-card-subtitle>The longer explanatory sub-title.</mat-card-subtitle>
  </mat-card-header>

  <mat-card-content>
    <form [formGroup]="form" (ngSubmit)="onSubmit()">
      <div fxLayout="column">
        <div fxLayout="row" fxLayoutGap="10px">
          <mat-form-field>
            <mat-label>First name</mat-label>
            <input matInput formControlName="firstName">
          </mat-form-field>
          <mat-form-field>
            <mat-label>Last name</mat-label>
            <input matInput formControlName="lastName">
          </mat-form-field>
        </div>
        <mat-form-field>
          <mat-label>Email</mat-label>
          <input matInput formControlName="email" required>
          <mat-error *ngIf="email.errors?.required">Email is required</mat-error>
          <mat-error *ngIf="email.errors?.email">Not a valid email</mat-error>
        </mat-form-field>
        <div fxLayout="row" fxLayoutGap="10px">
          <mat-form-field>
            <mat-label>Password</mat-label>
            <input matInput type="password" formControlName="password" required>
            <mat-error *ngIf="password.errors?.required">Password is required</mat-error>
            <mat-error *ngIf="password.errors?.minlength">Password is too short</mat-error>
          </mat-form-field>
          <mat-form-field>
            <mat-label>Confirm</mat-label>
            <input matInput type="password" formControlName="passwordConfirm" required>
            <mat-error *ngIf="passwordConfirm.errors?.required">Confirm password is required</mat-error>
            <mat-error *ngIf="passwordConfirm.errors?.mustMatch">Password and confirm must match</mat-error>
          </mat-form-field>
        </div>
      </div>
      <mat-card-actions >
        <button mat-button routerLink='/signin' routerLinkActive="active" type="button">Sign in</button>
        <div fxFlex></div>
        <button mat-flat-button routerLink='/signup' routerLinkActive="active" type="submit" color="primary">Create account</button>
      </mat-card-actions>
    </form>
  </mat-card-content>

  <mat-card-footer>
    The footer containing final parting thoughts...
  </mat-card-footer>

</mat-card>

Here is the associated CSS:

.mat-card-header {
  text-align: center;
  justify-content: center;
}

.signup-card {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
}

The intended alignment does not seem to be the default behavior, so something could be going wrong... Any thoughts on why this is happening?

Answer №1

The solution to your query:

explaining why the green padding extends beyond the orange margin. If the green padding matches the orange margin, the buttons should align correctly without the need for a workaround.

can be found in the CSS file specific to this component. The default configuration for mat-card-action is shown in the image below: https://i.sstatic.net/afNd8.png

Answer №2

Perhaps relocating this block could resolve the issue.

  <mat-card-actions >
        <button mat-button routerLink='/signin' routerLinkActive="active" type="button">Sign in</button>
        <div fxFlex></div>
        <button mat-flat-button routerLink='/signup' routerLinkActive="active" type="submit" color="primary">Create account</button>
  </mat-card-actions>

located inside the

<div fxLayout="column">
...


Why is this happening!?
Although I am not familiar with material, I encountered a similar issue with bootstrap .. it may be due to the outer layout class/element - 'row' in the case of bootstrap- potentially applying a margin like this:

margin-right: -15px;
margin-left: -15px;

and the inner class/element - 'col-md-6' in the case of bootstrap- applying a padding like this

padding-right: -15px;
padding-left: -15px;

Answer №3

Acknowledging Tomasz's solution and providing additional information here. By default, the Angular Material Card padding is set to:

@mat-card-padding: 16px !default;

Also, the margins for mat-card-actions are specified as:

.mat-card-actions {
  @extend %mat-card-section-base;
  margin-left: -$mat-card-padding / 2;
  margin-right: -$mat-card-padding / 2;
  padding: 8px 0;
}

As a result, the button edges may not perfectly align with the fields.

To ensure the buttons in card-actions align with the fields in card-content, consider the following steps:

  1. Reset the margins for mat-card-actions:
<mat-card-actions style="margin-left: 0; margin-right: 0;">
  1. Apply padding to mat-card-actions (as mentioned by Tomasz in the comments):
<mat-card-actions style="padding: 8px;">

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

Optimizing Angular 2's Efficiency: A Deep Dive into Change Detection and Performance Metrics (1000 calls measured

As a newcomer to Angular 2, I recently inherited a project using the framework. Upon assessing the app's performance, I noticed it was running quite slowly and causing issues. I investigated further and discovered that many ngIf's and ngFor&apo ...

When you add CSS font-size to the body element, how can you effectively manage the nesting of tags and the concept of inheritance within

Currently revamping a website loaded with old content. The main change in design is to make the site adaptable to different screen sizes. I am utilizing the font-size in the body element for this purpose and setting all measurements to ems. While this meth ...

Achieving Equal Height for Two Bootstrap 4 Columns with Scrollbar

I've been searching everywhere for a solution to this problem. My goal is to design a page with a video player on the left side and a chat on the right side. I am using the embed-responsive class for the video player so that it adjusts its size based ...

Border utilities in Bootstrap 4 provide easy ways to add borders

I have been searching for a solution, but I can't seem to find it. Bootstrap 4 offers utility classes for adding and removing borders, but is there a way to define the border width or style like solid or dashed? <span class="border"></span&g ...

Angular Component not reflecting changes to property when array is reversed

Within my Angular Component, I have a public array variable that is initially set to an empty array. Upon receiving a response from a service in the constructor, I attempt to update the array by using this.variable = array.reverse(). However, instead of ...

Why does my jQuery IMG center script not work in Chrome and Safari, but it works perfectly in IE?

I am experiencing an issue with centering the thumbnails of products on my e-commerce website. Despite successful centering in IE, FF, and Opera, Chrome and Safari are not aligning the thumbnails properly – they remain at the top of the div instead of be ...

Styling with CSS to create a layout similar to Facebook Messages

I am attempting to design a web layout similar to Facebook's Messages page, with a fixed height header and footer, and a flexible height main element. Within the main element, there needs to be: A div (100% height of the main elem.) that is scrolla ...

Why is there a thin line still visible on the other sides when a transparent background is used, but only on mobile devices, with a curved border on one side?

Recently, I've delved into the world of creating CSS art and stumbled upon a peculiar issue with CSS borders that has left me puzzled. When I apply a border to only one side of an element with a transparent background and rounded edges, I notice a fa ...

Display the properties of the Json object

Within my application, I am able to display data from a JSON array which includes radio buttons for each item. What I am trying to achieve is that when a radio button is clicked, the data of that specific JSON array item will be printed in HTML format in a ...

Angular 6 Encounter: "ReferenceError: alertify is not defined" - Alertify Error Detected

I recently attempted to integrate alertify.js into my project and followed a tutorial at . However, when I clicked a button in my application, I encountered an error that said ReferenceError: alertify is not defined. In order to add alertifyjs css and js ...

What is the best way to reduce the size of a Bootstrap card image back to its original dimensions when

I am currently experimenting with a bootstrap card using HTML, CSS, and Bootstrap. My main focus right now is on how to shrink the image when hovering over it. The .card-header-img has a fixed height of 150px that I do not want to modify. What I want to a ...

Exploring the synergy between Visual Studio 2015 and Angular2 Beta 2's dependency injection functionality

Currently, I am using VS2015 alongside TypeScript 1.7.3 and Angular2 Beta 2 with a target of ECMA 5. In order to enable experimental decorators in my project, I have made modifications to the csproj file by including TypeScriptExperimentalDecorators = true ...

Troubleshooting Problem with Helvetica Neue Font on Firefox

Recently, I decided to add the Helvetica Neue font to my system. However, upon doing so, I encountered a problem with Firefox browser where the font appeared double when using Helvetica Neue. Is there any available solution for this issue? Here is a scre ...

Bizarre Drop-down Peculiarities

Having a perplexing issue where the 'search' list item is oddly shifted below the dropdown box only when it is displayed. The other list items remain in their correct positions. Any advice on how to resolve this? The appearance and functionality ...

Establishing visual properties for inactive Mat-Expansion Panels

Is there a way to customize the appearance of a disabled Mat-Expansion-Panel? I have buttons in the header that toggle the panel, so I'm considering disabling the panel itself instead. However, when I disable the panel, all the items inside are greyed ...

Why is it that the border size in Chrome browser always seems to change, despite my specific requests for a set size?

I need help understanding why the border size is not matching the size I set in my CSS rules. Here is a link to the fiddle and below is the HTML code: <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>P inside B ...

Creating a split screen layout using Bootstrap

I've been working hard to create a split-screen layout using Bootstrap. After using CSS to achieve it, I realized that it's not responsive for mobile users. Therefore, I'm reworking it with Bootstrap but facing issues with resizing the image ...

Troubleshooting issue with Bootstrap's responsive scrollspy functionality

I am experiencing an issue with the responsiveness of my page. When I reduce the width of the page to half, the scrollspy disappears unexpectedly. I am unsure about the root cause of this problem. If you run the code I have shared here, you can observe th ...

Utilizing Angular to enhance tracking page views with the latest Google Analytics integration

I have been using various Angular applications to track page views, implementing a strategy similar to the one outlined in this blog post. In order to avoid third party references, I will provide the relevant code snippets here. To include the gtag depen ...

The Spring Boot REST application is unexpectedly returning HTML instead of JSON, causing confusion for the Angular application which is unable to recognize the

I am struggling with my Spring Boot application that was generated using . I am having difficulty getting it to return JSON instead of HTML. Here is a snippet of the code: [@CrossOrigin(origins="http://localhost:4200",maxAge=3600) @RestController @Request ...