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

266
Views
Container scaling with proportional size (width/height)

Does anyone have any idea how I can get a proportional scaling, both in width and height? I have a DIV container with the following setting:

<style>
#container {
width: 100%;
height:calc(100vw * 1.72);
background:red;

}
</style>
       
<div id="container"></div> 

When I adjust the width of the browser window, the area scales. However, no scaling takes place when I adjust the height of the browser window.

Is there a simple CSS solution to this?

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

0

try aspect ratio

width:100%;
aspect-ratio:1;

Please keep in mind that aspect-ratio does not work with all the browsers. Visit Mozilla description about aspect ratio to see the supported browsers

about 4 years ago · Juan Pablo Isaza Report

0

You can proportionally scale an element by giving its child element a padding-top percentage value at the ratio you want. The example below has an element with a height that's 2x its parent's width.

More details on the technique here.

.container { 
    width: 20%; /* pick whatever width you want */
    background-color:red;
}
.container .outer {
    width: 100%;
    padding-top: 200%; /* defines aspect ratio */
    position: relative;
}
.container .outer .inner {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
}
<div class="container">
    <div class="outer">
        <div class="inner">Your content</div>
    </div>
</div>

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!