Angular causing alignment issues for items not centered

I'm having trouble centering the contents of a div with my code. The properties I am applying don't seem to work. Any idea why this is happening?

<div class='center'>
    <form (ngSubmit)="loginUser()" style="background: steelblue;" class='login-form'>
        <p>
            <mat-form-field>
                <input type="text" [(ngModel)]='email' matInput placeholder="Email" name='email'>
            </mat-form-field>
        </p>

        <p>
            <mat-form-field>
                <input type="password" [(ngModel)]='password' matInput placeholder="Password" name='password'>
            </mat-form-field>
        </p>
        <div class="button">
            <button type='submit' mat-raised-button>Login</button>
        </div>

    </form>
</div>

Here is the CSS I'm trying to apply:

.center {
    display: flex;
    background-color: #ff1124;
    justify-content: center;
}

And here is the additional CSS:

.login-form .button button {
    width: 100%;
    background: #27803f;
    color: white
}

Currently, my form appears like this: https://i.stack.imgur.com/r9YsJ.jpg

Answer №1

Give this a shot

.center {
    display: flex;
    background-color: 
    #ff1124;
    justify-content: center;
    align-items: center;
    height: 100vh;
}

.login-form .button button {
    width: 100%;
    background: #27803f;
    color: white;
}
<div class='center'>
    <form (ngSubmit)="loginUser()" style="background: steelblue;" class='login-form'>
        <p>
            <mat-form-field>
                <input type="text" [(ngModel)]='email' matInput placeholder="Email" name='email'>
            </mat-form-field>
        </p>

        <p>
            <mat-form-field>
                <input type="password" [(ngModel)]='password' matInput placeholder="Password" name='password'>
            </mat-form-field>
        </p>
        <div class="button">
            <button type='submit' mat-raised-button>Login</button>
        </div>

    </form>
</div>

Answer №2

Give this a shot:

<div class="custom-wrapper">
  <div class='middle'>
  ...
  </div>
</div>

Also, in your stylesheet :

.custom-wrapper {
  text-align:center;
  width: 100%;
}

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

How can I retrieve all values from an input number field that is created using *ngFor in Angular?

In my table, I have a list of cart products displayed with a quantity field. Users can increase or decrease the quantity using options provided. Currently, if I place an update button inside a loop, it creates separate buttons for each product. However, I ...

Transmit data to a modal popup in Angular 8

Here is the code snippet written in .ts file: openFormModal(id: number) { console.log(id); const modalRef = this.modalService.open(PartidoComponent); modalRef.componentInstance.id = id; //modalRef.componentInstance.id = id; modalRef.r ...

Converting canvas illustrations into HTML files

I am in the process of creating a drawing application that will be able to export into HTML/CSS/JavaScript. I plan to use this tutorial as a foundation for the drawing functionality. My goal is to take all the rectangles within the this.shapes = [] array a ...

Getting node siblings within an Angular Material nested tree: A comprehensive guide

Struggling to retrieve the list of sibling nodes for a specific Angular Material tree node within a nested tree structure. After exploring the Angular Material official documentation, particularly experimenting with the "Tree with nested nodes," I found t ...

The DIV element fails to encompass all of its content

There seems to be an issue with the only div element on my page. It's covering the middle of the page, but I managed to make it extend all the way down using CSS tweaks. However, there is a problem - the video inside the div is overflowing: Below is ...

Embrace the words enveloped within large quotation marks

I am seeking a way to format paragraphs with large quotation marks surrounding them. I have attempted several methods, but my line-height seems to be affected, as shown in the following image: Can anyone suggest a proper method for achieving this? (Addit ...

Navigate between links by using the Tab key, while excluding certain links from the sequence

On my webpage, I have a main menu, various links in the main content area, and a left menu. The challenge is to make the website accessible for people who are blind... When using the tab button to navigate between links, the order currently goes as follow ...

I am unable to locate the module '@schematics/angular/utility/config'

I attempted to execute the command below in order to add ngx-bootstrap to my project: ng add ngx-bootstrap Unfortunately, I encountered an error message. The full CLI output is displayed below: i Using package manager: npm √ Found compatible package ver ...

What is the best way to display two tables together using inline styling?

I attempted to display 2 tables inline by setting their display property to inline, but unfortunately, it did not work as expected. Is there a more straightforward way to achieve the desired inline display for these tables? table { display: inline; } ...

What is the best way to restrict user input to specific numbers only?

I have a text input field, how can I ensure that only numeric values from 1 to 31 are allowed? <input type="number" min="1" max="31"> ...

Tips for iterating through nested objects with a for loop

Struggling with validations in an Angular 5 application? If you have a form with name, email, gender, and address grouped under city, state, country using FormGroupname, you might find this code snippet helpful: export class RegistrationComponent implemen ...

Angular 7 is throwing an error because it is expecting the "path" argument to be a string, but it is receiving an object instead

Whenever I attempt to run tests on my Angular project by typing: ng test --browsers=PhantomJS I discovered that I needed to manually install phantomjs using the following command: npm install <a href="/cdn-cgi/l/email-protection" class="__cf_email__" ...

Is it possible to replace multiple li elements with multiple ul elements within a single ul for better organization?

In the world of HTML and CSS, there are endless possibilities for creating unique designs. Recently, I stumbled upon an interesting question that has been lingering in my mind without a clear answer. Typically, people use a single "ul" element to create a ...

How can I effortlessly retrieve the Current Route Path Name in Angular?

I needed to find out the current route's path name and discovered this simple solution. this.route.snapshot.firstChild.url[0].path Is there a more efficient method for achieving this? Appreciate any advice! ...

Encounter a 404 error message coming from nginx while running ng build

Hello, I'm new to angular and attempting to run my angular application within a docker container. After executing ng build or ng build -prod and setting it up to run in a docker using the following dockerfile: ### STAGE 1: Build ### FROM node:12.7-a ...

There seems to be an issue with the CSS header alignment as the logo is not properly positioned using a top margin of -20px

My goal is to create a header bar that includes an image, a title, and a menu car. I want the bar to be displayed after scrolling 50px down, and I also want the image to be positioned slightly above the wrapping div, showing a bit of it in the top 50px. Ri ...

Adjust the size of the sliding tool with images of varying dimensions

My mobile-first slider features three different types of images: tall, horizontally long, and square. I want the size of the slider to be determined by the horizontally long image and then scale and center the other images to fit its size. To achieve this, ...

The site is visually appealing in Firefox, but has a few issues on Chrome

I've encountered a common issue where my website displays perfectly in Firefox but looks terrible in Dreamweaver and Chrome. To fix it, I made live CSS edits in Firefox then copied them to Dreamweaver resulting in a mess. Here's how it should lo ...

The promise object is displayed instead of the actual data retrieved from the API call

I am currently working on fetching data from an API and showcasing the name of the returned data on the front end. This function successfully retrieves the data through an API call: async function retrieveData(url){ var _data; let response = await fetch( ...

Accessing different pages in Angular 2 based on user type

If I have four pages and two user types, how can we implement access control in Angular 2 so that one user can access all four pages while the other is restricted to only two pages? ...