Angular - creating adaptive HTML container with CSS styling

I am trying to achieve a layout similar to the one shown in the image. A container can have multiple elements starting within it or no elements at all. The elements always have a fixed height, and the container's height is determined by the number of elements. If there are no elements, the height is the minimum; if there is more than one element, the height must be sufficient to cover that element (with each element having a height of 40px) plus half of the next element.

In the illustration:

  • Elements 1 and 2 start in container 1;
  • Elements 3 and 4 start in container 2;
  • Containers 3 and 4 do not have any elements starting within them (so they should have the minimum height).

<div class="all">
  <div class="conts" *ngFor="let cont of container;  let i = index">
    <div class="cont" [ngStyle]="{'height': cont.numberOfElements + 'px'}">
      C{{i}}
    </div>
  </div>
  <div class="test">
  <div class="els" *ngFor="let elm of el;  let i = index">
    <div class="el">
       El{{i}}
    </div>
  </div>
  </div>
</div>

    .all {
  width: 100%;
  height: 100%;
}

.test {
  position: absolute;
  top: 10px;
  left: 40px;  
}

.els {
  display: flex;
  width: 100%;
  justify-content: center;
}

.el {
  display: flex;
  align-items: center;
  justify-content: center;
  margin-right: 80px;
  height: 40px;
  width: 40px;
  border: 1px solid blue;

}

.const {
  display: flex;
  width: 100%;
  justify-content: center;
}

.cont {
  display: flex;
  align-items: center;
  justify-content: left;
  min-height: 40px;
  height: var(--height);
}

.conts:nth-child(odd) {
  background-color: green;
}
.conts:nth-child(even) {
  background-color: red;
}

  el = [
    {start: new Date('1/1/2020')}, 
    {start: new Date('1/1/2021')}, 
    {start: new Date('1/1/2022')}, 
    {start: new Date('1/1/2023')}
    ]
 
    container = [
    {start: new Date('1/1/2019'), end: new Date('1/5/2021'), numberOfElements: 40*1},
    {start: new Date('1/5/2021'), end: new Date('1/5/2023'), numberOfElements: 40*0},
    {start: new Date('1/5/2023'), end: new Date('1/6/2023'), numberOfElements: 40*2},
    {start: new Date('1/6/2023'), end: new Date('1/1/2024'), numberOfElements: 40*1}
    ]

https://i.stack.imgur.com/d1k6p.png

Answer №1

Utilizing the position: absolute successfully resolved the problem.

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

Refresh Angular Component upon query parameter modification

Within my application, there is a search form that can be accessed by adding query parameters to the URL. This will prefill the form with specific information. My goal is to clear this prefilled state when the search icon in the navigation is clicked. Whi ...

Reimbursement for utilizing SwitchMap in Rxjs within the Angular framework

I'm new to using switchMap for the first time and I am encountering an issue. The console is asking me to return a value, but whenever I try to do so, it doesn't seem to be working properly. @Effect() subData$ = this.actions$.pipe( ofType( ...

Using z-index to position a paragraph element behind other elements in a webpage

I am facing a challenge where I want to hide a paragraph within an element, and layer it behind another element. Despite my attempts with z-index, I have been unsuccessful in achieving this effect between the elements. Could someone shed some light on why ...

Should I convert to an image or utilize the canvas?

I'm debating whether it's more efficient to convert a canvas drawing into an image before inserting it into the DOM, or if it's better to simply add the canvas itself. My method involves utilizing canvas to generate the image. ...

The menuToggle feature works flawlessly on desktops after integrating my AngularJS module, but unfortunately, it is not functioning

I have successfully integrated autosuggestion using AngularJS material library into my web application. Everything seems to be working fine except for one issue. When I include ng-App="MyApp2", the menuToggle button stops functioning only on mobile devices ...

The canvas map has an unseen boundary on the right, causing all other div sections to be

When I set the width of my google map canvas to 80%, the map itself fills that percentage but leaves a wide space to the right of the canvas, taking up the remaining 20% of the screen. This creates an issue because my div cannot be placed in that space. ...

What could be causing my jQuery script to malfunction?

After scouring through numerous Stack Overflow questions and conducting countless Google searches, I am still stumped by the issue at hand. As a beginner in web development, all I want is for this simple page to function properly. Can someone please point ...

Switching over to a stored procedure

I have been using a query string for the jQuery Autocomplete plugin, but I think it would be better to switch to a stored procedure. However, when I tried to do so, it didn't work. Can anyone provide guidance on how to convert my code? Original ASHX ...

In iOS devices, the Ionic framework restricts the ability to open links in a new tab using the ng-href attribute

In my quest for mobile functionality, I'm aiming to implement a feature on devices where tapping will open 'codepen.io' (triggered by ng-click), and tap and hold will display a context menu with the option to 'Open In New Tab', red ...

What is the best way to enable `child_process.execFile` to utilize an existing running application?

I am currently developing an Electron app that is designed to launch another application, such as Photoshop, using child_process.execFile. However, I have encountered an issue where if Photoshop is already running when child_process.execFile is called, a n ...

Angular2: The comeback of accessing a getter after the service constructor has completed (using HTTP Get)

I have a requirement for my app where I need to utilize List.json to create a list, which forms the core of my application. To ensure this list is shared across all components, I have opted to establish a service. Within this service, I call my JSON file ...

Is there a bug or user error causing CSS float not to be applied in Chrome?

I've encountered an issue with Chrome's rendering in my web application that seems to be intermittent. When I switch the float property between "left" and "none", Chrome doesn't reposition the elements properly. Interestingly, Firefox and I ...

HTML comments generated from Freemarker's list notation

Currently, I have integrated Apache Freemarker into an HTML editor where users can create templates using code. For example, a user may write the following code for a list: <#list items as item>...</#list> While this is the correct way to gen ...

Accessing data from a reactive source within a component

Upon building a component, I encountered an issue with returning a property containing an observable. While I was able to successfully display the property in the template, I realized that its presence there was unnecessary: {{(selectedOrder$ | async).ord ...

text/x-handlebars always missing in action

I'm currently working on my first app and I'm facing an issue with displaying handlebars scripts in the browser. Below is the HTML code: <!doctype html> <html> <head> <title>Random Presents</title> ...

Utilizing Sequelize's multiple operators for fetching objects with an exclusion clause: A comprehensive guide

In my NodeJS/Express/Angular7 application with Sequelize 5 and MySQL, I have a table of images connected to a table of keywords through a join table in a bidirectional hasMany relationship. My goal is to retrieve all images that contain keyword IDs within ...

The Bootstrap collapsible feature is causing elements to shift to the adjacent column

I'm currently implementing bootstrap's collapsible feature to showcase a list of stores along with expandable details. However, the issue arises when I expand one of the collapsibles in the left column, causing certain items to shift into the ne ...

Angular 2: A Beginner's Guide to Creating Objects and Transforming Code from Angular to Angular 2

Currently, I am learning Angular 2 and facing an issue. I am unsure about how to create an object in my login function (Angular1). public logIn() { let phone = this.user.number.replace(/\s+/g, ''); let email = 'u&a ...

Dynamic divs to occupy the rest of the available vertical area

I have been experimenting with a new website layout and created a form setup. However, I am facing an issue with the fluidity of the layout. While the items are floating into position, there is a problem where if the item on the right is 400px bigger than ...

Progress bar arrows undergoing transformation in shape

I am currently developing an angular application where I have implemented a progress bar. The CSS code I have used is: CSS: .progressbar { height: 56px; background: lightgray; box-shadow: inset 0px -2px 5px rgba(0, 0, 0, 0.5); anim ...