Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

448
Views
How to make a variable css height for a div in Angular CLI V12

I'm fairly new to developing in Angular and I'd like some help with finding the best way to create a variable CSS height in Angular CLI V12. To simplify my question by a lot I'll present my problem as follows. I've got three boxes as seen below.

Picture of boxes:

enter image description here

These three boxes were made by three components. The code of which is below.

app.component.html:

<app-top></app-top>
<app-center></app-center>
<app-bottom></app-bottom>

top component:

.box {
    width: 500px;
    height: 100px;
    padding: 10px;
    border: 5px solid black;
    margin: 0;
}
<div class="box">top box</div>

center component:

.box {
    width: 500px;
    height: 100px;
    padding: 10px;
    border: 5px solid green;
    margin: 0;
}
<div class="box">center box</div>

bottom component:

.box {
    width: 500px;
    height: 100px;
    padding: 10px;
    border: 5px solid yellow;
    margin: 0;
}
<div class="box">bottom box</div>

What I want to do here is change the height of the center box dynamically through a variable in the typescript portion of my Angular project. I don't think what I'm trying to do here is all that complicated but all the sources I find online for this are somewhat outdated and a bit confusing to follow if you are new to the development scene. What would be the best way to go about doing this? Thank you.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

You can just use ngStyles to add style to html tags. For eg:

<div class="box" [ngStyle]="{'height': myCustomHeight}">center box</div>

Here "myCustomHeight" will be the variable whose value you can change accordingly in typescript.

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!