Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

269
Visualizações
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 Respostas
Responde à pergunta

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 Relatório

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda