What steps should I take to prevent my <mat-card> from expanding whenever messages are shown in Angular 9?

I have a <mat-card> containing a login form on my page. However, when error messages are displayed, the vertical size of the <mat-card> changes and I need it to remain the same.

Is there a way to prevent this from happening?

  • Below, you will find my HTML file, the SASS file for the error messages, as well as pictures depicting the issue.

HTML File

<div class="bg"> 
    <div class="main-div color ">
        <mat-card class="z-depth center col-sm-4 " flex="50" >
            <mat-radio-group aria-label="Select an option" [(ngModel)]="radio_btn">
                <mat-radio-button  [value]="true" >User</mat-radio-button>
                <mat-radio-button [value]="false">Admin</mat-radio-button>
            </mat-radio-group> 

                <div class="row justify-content-center " *ngIf="radio_btn==true;else form2">
                    <form class="example-form " [formGroup]="loginForm" (ngSubmit)="sendUser()">
                        <mat-form-field class="example-full-width ">
                            <input matInput formControlName="Identifier" placeholder="Identifier" >
                        </mat-form-field><br>
                        <div class=" alert-danger space" *ngIf="identifier.invalid && (identifier.dirty || identifier.touched)">
                            <div class="container-error-message " *ngIf="identifier.errors.required">
                                Identifier required
                            </div>
                            <div class="container-error-message" *ngIf="identifier.errors.minlength">
                                Identifier must be at least 7 characters long.
                            </div>
                        </div> 
                        <br>
                        <mat-form-field class="example-full-width">
                            <input matInput formControlName="Password" placeholder="Password" type="password" >
                        </mat-form-field><br>
                        <div class="alert-danger space" *ngIf="password.invalid && (password.dirty || password.touched)">
                            <div class="container-error-message" *ngIf="password.errors.required">
                                Password required
                            </div>
                            <div class="container-error-message" *ngIf="password.errors.minlength">
                                Password must be at least 5 characters long.
                            </div>
                        </div>
                        <br>
                        <button mat-raised-button [class.black]="!loginForm.invalid" [disabled]="loginForm.invalid" type="submit">Sign in</button>
                    </form>
                </div>
                <ng-template #form2> 
                    <app-home-admin></app-home-admin>
                </ng-template>

        </mat-card>
      </div>
    </div>

SASS file

@import './../../variables_scss/variables.scss';

example-icon {
    padding: 0 14px;
  }

  .example-spacer {
    flex: 1 1 auto;
  }

  .down{
    overflow-y: auto;
    .colour{
        background: $orange-bg;
        .icons {
            color: $black;
          }
      }
  }

  .container{
    align-items: center; 
  }

  .main-div{
    height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
    .center{
      width: 75%;
      margin: 10px auto;
      .mat-radio-button ~ .mat-radio-button {
        margin-left: 16px;
      }
      button {
        display: block;            
        width: 100%;
        margin: 2px;
        text-align: center;
        color: $orange !important;
        border-radius: 8px;
      }

    }
  }

.bg{
  background: $black;
  background: linear-gradient(to right, $dark_black,$light_black  );
}
.behind{
  z-index: 10;
}
.black {
  background-color:$black !important;  
 }

 .space{
  margin: $margin-errors;
  text-align: $text-align-center;
  width: $width-erros;
  border: 1px solid;
 }

* scss_variables*

$dark_black: #1b1b1b;
$light_black: #424242;
$black: #141519;
$margin-left: auto;
$orange:  #fc6407;
$colour_button :$black;
$orange-bg: linear-gradient(to right, #c43e00, #ff6f00);
$margin-errors: 0 auto;
$text-align-center: center;
$width-erros: 180px;

https://i.sstatic.net/npchK.png https://i.sstatic.net/e8B2R.png

Answer №1

After analyzing the code you provided, I did not encounter the same issue. However, I recommend setting a consistent height for the mat-card element that will accommodate all items. For example, you can set the height to 400px as demonstrated below:

mat-card {
  height: 400px;
}

Answer №2

This is my solution method

Including the following in the zone category

 max-height: 0px;
margin-top: 0px !important;  

Adding this to the center group

height: 290px;

Answer №3

To ensure a consistent height for your cards in CSS, you can set both the minimum and maximum height values to 230px like so. This solution worked well for me, as it allows for automatic scrolling when the content exceeds the specified height.

  .mat-card{
    min-height: 230px ;
    max-height: 230px ;
  }

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

Position the div in the center and enhance the function to dynamically adjust when the user attempts to resize the window

var windowHeight = $(window).height(); var windowWidth = $(window).width(); var scrollTop = $(window).scrollTop(); var scrollLeft = $(window).scrollLeft(); jQuery.fn.center = function () { this.css("position","absolute"); this.css("top", Math.max( ...

What could be causing this Ajax error I'm experiencing?

I am attempting to dynamically load pages on this website using JQuery and Ajax when a menu point is clicked. However, I am encountering errors during the loading process. What does the console message ""GET 'path to css file'" mean? (there ...

Alternate the color over time using CSS

Is there a way to dynamically change the color of a div from black to white every two seconds, and then from white to black, continuously toggling as long as the div is visible? Essentially, I want the div to only be displayed when a user clicks and drag ...

What is the best way to conceal the jqgrid entirely while it is still loading?

Having an issue with my jqgrid. As I load the table and fetch a large amount of data from the database, the loading process naturally takes a few seconds. However, during this time, I can see the column headers without any rows or styles applied to the jqg ...

Add navigation dots to the slider in order to align them with the specified div element

Visit this JSFiddle link for the code <html> <link href="./style.css" rel="stylesheet" type="text/css"> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script&g ...

Changing HTML tags programmatically in Angular while inheriting a template

In my project, I have a Component called DataGrid that represents a table with expandable rows. Each row can be expanded to show a child DataGrid table, which is similar to the parent DataGrid component. To simplify this setup, I created a base class DataG ...

Tips for effectively utilizing the 'or' operator when working with disparate data types

One of my functions requires an argument that can have one of two different types. If you're interested in TypeScript functions and types, take a look at the official documentation, as well as these Stack Overflow questions: Question 1 and Question 2 ...

Utilizing CSS to place an image on top of the upcoming <div> container

My goal is to create a layout similar to the one displayed in the linked image. https://i.stack.imgur.com/7DSE9.jpg Currently, I am using Bootstrap 3 and my HTML markup looks like this: <body class="gray-bg"> <section class="white-bg"> <d ...

In my attempt to assess the correlation between value 1 and a value in the preceding object, I am utilizing the *ngFor directive

Attempting to compare 2 entries in an *ngFor loop. The code should compare the value at the current object to a value at the previous object. <ng-container *ngFor="let item of s_1.comments[0]; index as b"> <article class="message i ...

The correct alignment of images is crucial for a website's overall aesthetics and functionality

My column displays images aligned in the center when viewed locally, but the alignment changes when hosted remotely. Here is the image when locally hosted: https://i.sstatic.net/I56Dg.png And here is the remote host image: https://i.sstatic.net/ePoAn.p ...

When I try to expand the width of a div, the display property set to inline

Visit my website At the moment, my website features the following code snippet: <div class="main-sale"> <div class="time-left">Sale Ends in: </div> <div class="sale-item"> //Highlighted Sale it ...

Identifying input value changes without needing to manually enter key values

As an example: <input class="table-input" type="number" name="qty" [(ngModel)]="cpy.qty" matInput min="1" max="{{cpy.qty}}" where cpy represents an object that is constantly changing. Currently, I need to execute a certain operati ...

Adjusting the dimensions of the canvas leads to a loss of sharpness

When I click to change the size of the graph for a better view of my data in the PDF, the canvas element becomes blurry and fuzzy. Even though I am using $('canvas').css("width","811"); to resize the canvas, it still results in a blurry graph. I ...

What is preventing my function from retrieving user input from an ngForm?

I'm currently working on my angular component's class. I am attempting to gather user input from a form and create an array of words from that input. The "data" parameter in my submit function is the 'value' attribute of the ngForm. Fo ...

When hovering the mouse over, the text fails to appear

Is there something wrong with my overlay on this image? It darkens when I mouse over, but the text I want to display does not show up. Any ideas? http://jsfiddle.net/cryycw3n/ HTML <div class="square"> <div class="info"> <h2&g ...

Troubleshooting the issue of process.nextTick not being recognized in Calgolia places.js

After successfully implementing Algolia's places.js in my Angular 7 project using NPM, I encountered an issue. I have integrated a form where one of the fields should be an input. <form [formGroup]="myForm"> <pre style="color: white; b ...

What are some ways I can incorporate PrimeNG components into my Ionic 4 project?

Exploring the integration of PrimeNG components in an Ionic 4 application is my current project. The initial steps I took included creating a blank Ionic 4 app: ionic start myApp blank Afterwards, I proceeded to download PrimeNG into the project: npm ...

The Bootstrap 5 navigation bar remains fully expanded and does not collapse as intended

I'm having trouble getting the navbar to collapse on my landing page created using react and bootstrap. Here is the code for my header component: import React from 'react'; import logo from '../images/logonoBG.png'; export default ...

Can you please explain what shape-id denotes and provide guidance on locating it within a CSS file?

I have a question that may seem trivial to experienced web developers - what exactly is "shape-id"? For example, in the code <hr shape-id="2">. I'm currently attempting to change the color of the horizontal lines (hr) on my website, but I can& ...

In certain browsers, the link changes color to white

As I assist my brother in setting up a website for his business, we encountered an issue. In some browsers, hyperlinks appear as white and therefore invisible. Interestingly, the hyperlink is white in Firefox, but not when browsing in incognito mode, see t ...