Modifying the alignment of Angular elements within the router-module to complement an established CSS grid

I'm facing an issue with my angular reactive-form project. I have successfully set up everything except routing. After defining all the routes in the app.module.ts file, things started getting messy. In my basic form, I had a responsive CSS grid with two columns that nicely accommodated the form before adding a there. It seems like the router outlet automatically becomes an item within the grid, causing my component to create an additional grid row and messing up the entire layout.

How can I resolve this problem?

Below is my template code:

<div class="container">
  <div class="wrapper">
    <app-form-slider></app-form-slider>
    <router-outlet></router-outlet>
  </div>
</div>

This is my app.module configuration:

const routes: Routes = [
  {path: '', redirectTo: '/form', pathMatch: 'full'},
  {path: 'form', component: FormComponent},
  {path: 'logined-user', component: FormLoginedUserComponent}
];

@NgModule({
  declarations: [
    AppComponent,
    FormComponent,
    FormLoginedUserComponent,
    FormSliderComponent
  ],
  imports: [
    BrowserModule,
    ReactiveFormsModule,
    IMaskModule,
    RouterModule.forRoot(routes)
  ],
  providers: [],
  bootstrap: [AppComponent]
})
export class AppModule { }

And here is the SCSS template used for styling:

.container {
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: row;
    justify-content: center;
    align-items: center;

}

.wrapper {
    margin-right: auto;
    margin-left: auto;
    display: grid;
    height: 100vh;
    width: 95vw;


    @media (min-width: 700px) {
        display: grid;
        grid-template-columns: 160px 2fr;
        width: 1000px;
        height: 95vh;
    }
}

app-form {
    background-color: #fff;
    grid-column: 1 / 3;
    @media screen and (min-width: 700px){
        grid-column: 2/3;
        border-top-right-radius: 10px;
        border-bottom-right-radius: 10px;
    }
    &-slider {
        grid-column: 1 / 3;
        background-color: #48a5ea;
        @media screen and (min-width: 700px){
            grid-column: 1/2;
            height: 100%;
            border-top-left-radius: 10px;
            border-bottom-left-radius: 10px;
        }
        height: 20vh;

    }
}

Answer №1

When wrapping it, you have the ability to dictate the amount of space allocated for it

<div class="container">
  <div class="wrapper">
    <div class="col-5">
       <app-form-slider></app-form-slider>
    </div>
    <div class="col-7">
       <router-outlet></router-outlet>
    </div>
  </div>
</div>

In this case, I'm demonstrating with bootstrap as an example but the concept is clear. The app-form-slider occupies 5 columns while anything routed through router-outlet must fit within the remaining 7 columns.

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

Ways to modify a link tag based on a specific browser width

Looking for a solution to optimize the drop-down sign in box code that gets appended to a hamburger menu when the mobile width media query is called. Can we refactor this to switch the drop-down sign in box to just an anchor tag (<a href="signin">< ...

The most recent update of Blink does not support the complex selector :nth-child(2):nth-last-child(2){}

There is an unusual issue: after a recent update, the selector .groups .group:nth-child(2):nth-last-child(2){} suddenly stopped working. However, it still works perfectly in Webkit and Gecko browsers. Any thoughts on how to resolve this? Snippet of HTML ...

The name 'Math' is not found

Currently diving into Angular7 with the tour-of-heroes application as my guide. I've been working on the InMemoryDataService class and encountered an issue when trying to generate an ID - I keep receiving the error "[ts] Cannot find name 'Math&ap ...

Tips for incorporating a theme into your CSS code using BEM naming conventions

Currently, I am using the BEM CSS naming convention for a project I am currently working on. So far, everything is going smoothly. However, I am faced with the challenge of implementing multiple themes (each with slightly different designs) on the same HTM ...

What could be causing this jQuery to malfunction?

Having trouble with the functionality of hasclass and this.addclass. if ($('.sidebar-menu-container li').hasClass('current-menu-item')) { $(this).addClass('expanded'); } Check out this CodePen for reference. ...

Ways to transition between divs using clickable buttons

I have a coding challenge where I need to implement two panels. The lower panel consists of three buttons and upon clicking each button, different data should load in the upper panel. For example, when button 1 is clicked, divs 1.1, 1.2, and 1.3 should sl ...

Leverage the power of Angular 2 in conjunction with the .NET

Recently, I've been contemplating transitioning to Angular 8 for new projects instead of sticking with Knockout.js in combination with ASP.NET WebApi2 for SPA development. However, I'm curious - is it possible to use Angular 8 with traditional A ...

Unable to locate the identifier 'BrowserWindow'

In the providers folder of electron.service.ts, I have the following code: import { Injectable } from '@angular/core'; // If you import a module but never use any of the imported values other than as TypeScript types, // the resulting javascrip ...

I would like to embed the HTML page within the specified div element

When attempting to load a HTML page inside the div, I encountered the following issue: <a href="#1" title="" class="base-banner" page="www.google.com for example"> <img src="images" alt=""></a> <div id="landingpage"> </div> ...

I require help with my digital greeting card

Apologies for any language errors in advance. I'm almost done with my first "online-card" project, but I've hit a frustrating issue. I can't seem to remove the gap between the footer and the tab-content (the Hungarian version is fine). I&apo ...

After importing RxJS, the error "toPromise is not a function" is encountered

I am trying to utilize the Promise operator Firstly, I imported rxjs: import 'rxjs/add/operator/toPromise'; then in my component, I implemented it ngOnInit() { this.EJnames= this.dataservice.getResults(); this.generalinfosservice.get ...

Eliminate a specific choice from a drop-down menu in an Angular application

I am implementing a feature where clicking on a button adds more select drop downs. I want to ensure that the selected options in these new dropdowns do not duplicate any already chosen options. Below is the code snippet used for the select drop down: < ...

Adjust the $scope variable depending on the size of the screen

Currently, I have a sidebar that collapses based on the value in $scope, specifically when $scope.open is set to true. However, I've noticed that if the menu is left open and viewed on mobile devices or small windows, it can look quite messy. To addre ...

What is the best way to integrate JSON:API with Angular and RxJs?

Currently, I have a Laravel API that adheres to the json:api spec and functions smoothly with Postman for making requests on related resources. However, I am facing challenges in understanding how to utilize this API with my Angular front-end. To kickstar ...

Determining the button's width relative to its parent's size using a

I'm trying to make my button take up 90% of the width of the screen. After testing my HTML code, I noticed that the button is only occupying around 10% of the screen. However, when I specify the width using pixels, it adjusts correctly. What could b ...

Using TypeScript and HTML to toggle a switch and retrieve its value

I am currently trying to utilize a toggle switch to determine which methods need to be activated. My expectation is that I can obtain a Boolean value indicating whether the switch is turned on or off. However, I am unsure of how to retrieve this informatio ...

Error occurring with the gulp task runner

Encountering an error while using the task runner for my "gulp" file. My project involves Angular 2 and Asp.net Core. The "typings" folder is set up with a "typings.json" file that contains the following: { "resolution": "main", "tree": { "src": ...

Upon opening index.html in the browser, the jQuery code fails to execute, as no errors are displayed in the console

I am struggling to make a simple toggleClass() function work in jQuery and I can't seem to figure out why. This is just a beginner exercise for me with jQuery. The code works perfectly when I test it as a snippet or manually in the console, but when I ...

CSS border not displaying correctly on high-resolution screens

When resizing the browser window, I noticed that the border of certain elements, such as this deposit button, gets clipped depending on the width. It seems that when I adjust the width pixel by pixel, the border appears and disappears with each movement. C ...

Is there a way to incorporate CSS into a JPG file on the server end?

I have some JPGs that need to undergo CSS operations on the server side, such as cropping and rounding corners. Once processed, I want to serve these edited JPGs to clients. The clients themselves are unable to interpret CSS, they can only display JPGs. I ...