The styles are not being rendered on the Angular application

I have successfully implemented a Modal service with working HTML/CSS (Check it out on StackBlitz)

div.cover {

  align-items: center;
  background-color: rgba(0, 0, 0, 0.4);
  bottom: 0;
  display: flex;
  justify-content: center;
  left: 0;
  position: fixed;
  right: 0;
  top: 0;
  z-index: 200;

}

div.modal {

  background-color: white;
  display: flex; 
  flex-direction: column;
  max-height: 60vh;
  max-width: 400px;
  width: 100%;

}

div.head {

  align-items: center;
  background-color: white;
  border-bottom: 1px solid gray;
  display: flex;
  flex-shrink: 0;
  height: 50px;
  justify-content: space-between;
  padding: 0 20px;

}

div.body {

  background-color: white;
  flex-grow: 1;
  overflow: auto;

}

div.view {
  padding: 20px 28px;
}

div.foot {

  align-items: center;
  background-color: white;
  border-top: 1px solid gray;
  display: flex;
  flex-shrink: 0;
  height: 50px;
  justify-content: flex-end;
  padding: 0 20px;

}

p {
  margin: 0; 
  padding: 0;
}
<p>
  Lorem ipsum dolor sit amet, consectetur adipiscing elit. Morbi porttitor aliquet orci sit amet fringilla. Duis a ligula consequat, ornare elit eu, tincidunt turpis.
</p>
<p>Nulla faucibus ultrices est eu laoreet. Suspendisse accumsan blandit ipsum ultricies congue. Nam eget leo a elit vestibulum tincidunt in elementum nunc. Nunc cursus lacus eu placerat auctor.
</p>
<div class="cover">
  <div class="modal">
    <div class="head">
      <div>Head</div>
      <div><a href="#">Close</a></div>
    </div>
    <div class="body">
      <div class="view">
<p>
  Lorem ipsum dolor sit amet, consectetur adipiscing elit. Morbi porttitor aliquet orci sit amet fringilla. Duis a ligula consequat, ornare elit eu, tincidunt turpis.
</p>
<p>
  Nulla faucibus ultrices est eu laoreet. Suspendisse accumsan blandit ipsum ultricies congue. Nam eget leo a elit vestibulum tincidunt in elementum nunc. Nunc cursus lacus eu placerat auctor.
</p>
      </div>
    </div>
    <div class="foot">
      Foot
    </div>
  </div>
</div>

Subsequently, I utilized a Modal.Service to open the content (Access it on StackBlitz)

Upon clicking "Open Modal", the modal displays as expected.

However, an issue arises when resizing the browser window height as the modal does not adjust accordingly.

Any thoughts on what may be causing this problem?

Answer №1

In order to achieve the desired behavior when the max-height parameter is reached, it is important to define more properties for the flex element. For instance, if you want the element to shrink and scroll vertically as content overflows while also adjusting its height accordingly, consider the following CSS:

div.modal {

  background-color: white;
  display: flex; 
  flex-direction: column;
  max-height: 60vh;
  max-width: 400px;
  width: 100%;

  flex-shrink: 1;
  overflow-y: auto;
}

Defining the flex-shrink property is crucial in achieving the desired outcome.

https://stackblitz.com/edit/modal-angular-flex-2-rysjej

Answer №2

There were a couple of errors in your code. Angular wraps your HTML around the component selector element. In this instance, your modal content was placed inside <content>, which does not have flex applied.

div.cover {
  flex-direction: column;
}

div.modal {
  flex-grow: 1;
}

div.modal > content {
  display: flex;
  flex-direction: column;
  height: 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

"Encountering a form submission error - requested resource not located

I am currently trying to submit a form to an MVC controller using AJAX, where the controller is expected to take a form collection. I came across this helpful resource on Stack Overflow regarding passing formcollection using ajax call to an action. However ...

CSS or jQuery: Which is Better for Hiding/Showing a Div Within Another Div?

Show only class-A at the top of the page while hiding all other classes (x,x,c). Hide only class-A while showing all other classes (x,x,c). Is it possible to achieve this? <div class="x"> <div class="y"> <div class="z"&g ...

Creating a triangular shape using a div element

Struggling to create a triangular div? I used the border trick to make it, but now there's a transparent line slicing through the triangle like a dividing line. I've attempted various solutions to make that line solid, but nothing seems to be wor ...

Locate Checkbox by its Attribute Name and Value

On my webpage, there are multiple groups of checkboxes. In one particular group, I have added a custom "documentcategory" attribute to each checkbox. My goal is to identify all the checkboxes on the page that have the "documentcategory" attribute with a va ...

Scanning barcode and Qrcode with Angular js HTML5 for seamless integration

Looking to scan Barcode and Qrcode on Android, iPhone, and iPad devices for a project that is built on AngularJS and HTML5 as a mobile website. The requirement is not to download any third-party native application on the device, ruling out the use of nati ...

The JavaScript code malfunctions when I introduce a new HTML tag

I am attempting to create a simple photo gallery using PhotoSwipe. However, I have encountered an issue where certain functions like Previous and Next buttons stop working when I add new HTML elements. Here is the original code: <div class="my-gallery ...

Testing Angular with Jasmine: The spy should have been called as expected

Seeking assistance for a persistent issue that has been troubling me. I am currently working on unit tests for a component I developed, and no matter what I try, I can't seem to resolve the recurring problem of an "Expected spy getTopRatedMedia to ha ...

How can I establish default values for 2 to 3 options in a Dropdownlist?

Is there a way to set two values as default in a dropdown list, and when the page is refreshed, the last two selected values are retained as defaults? Thanks in advance! Visit this link for more information ...

The speed at which Laravel loads local CSS and JS resources is notably sluggish

Experiencing slow loading times for local resources in my Laravel project has been a major issue. The files are unusually small and the cdn is much faster in comparison. Is there a way to resolve this problem? https://i.stack.imgur.com/y5gWF.jpg ...

Determine the amount of time that can be allocated based on the attributes contained within the object

I am faced with a JSON structure like the one below: var meetings = [ { id: '1', start_time: "2020-11-15T08:30:00+00:00", end_time: "2020-11-15T14:15:00+00:00" }, { id: '2', start_time: &quo ...

Disabling a jQuery function on an external page: Step-by-step guide

I have encountered a challenge while trying to load an anchor tag on an external page using a specific method: <a href="page.html#div> This method is meant to link me to another page's particular div. <div name="div"> stuff </> H ...

Ensuring Data Accuracy in Angular 2 Forms

Currently, I am working on form validation using Angular 2 and encountered an issue with the error message Cannot read property 'valid' of undefined. The HTML file I am working on contains a form structure like this: <form id="commentform" c ...

Effective URL structure with nested ui-view in AngularJS

It is common knowledge that Angular functions as a SPA (Single Page Application). I am seeking the most effective approach to display a main left-side menu selector page, where clicking on any menu item will load the content in the right-side view div. Th ...

Exploring Model Object Properties with ngFor in Angular

Currently, I am developing an Angular application with a Model object that consists of properties of various types. My goal is to loop through these properties in the component and generate form fields for each property. Unfortunately, the implementation i ...

Using Moneris with Google Pay in Angular

I'm currently working on implementing Google Pay with Moneris Gateway using the Google-Pay-button-Angular library. However, I'm unsure of how to connect Moneris with it. I followed a tutorial provided in this link but I'm unsure where to inp ...

What's the best way to integrate Bootstrap into my HTML document?

Hey there, I'm new to the coding world and just started learning. I could use some assistance with including Bootstrap v5.1 in my HTML code. The online course I'm taking is using an older version of Bootstrap, so I'm having trouble finding t ...

Error 404 occurs when attempting to retrieve a JSON file using Angular's HTTP

I'm having an issue with my service code. Here is the code snippet: import {Injectable} from '@angular/core'; import {Http, Headers, RequestOptions} from '@angular/http'; import 'rxjs/add/operator/map'; import {Client} f ...

create parameters for the angular properties of chemical functions

I have two functions that clear cancer and reproductive dropdowns individually. Now, I want to combine these functions into a parametrized function that takes a chemical input: clearDropdown(chemical) { switch (chemical) { case 'cancer& ...

I encounter issues with HTML input fields becoming unresponsive whenever I attempt to apply CSS filters in IE8 for stretching the background

When I wanted to stretch a background image on my website so that it always fills the available window area regardless of resolution, I initially used background-size:cover;. Unfortunately, Internet Explorer doesn't seem to support valid CSS, so I had ...

What is the process for adding the multiple attribute to a select dropdown in a form?

I implemented the selectric plugin for dropdowns on my website. I included the multiple attribute in the select tag, but it doesn't seem to be functioning properly based on what is shown on the index page of the selectric plugin located at: This is t ...