Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

252
Vistas
javascript math: what is the height of the image

What is the css height of the image if the width is for example: 3px?

original image height is 400px; original image width is 800px;

what I've tried is:

convert the 3px to a percentage of the original image width:

function perwVal(v){
return 100 * v / iow; //img orig width
}

function perhVal(v){
return   v / 100 * ioh; // img original height
}

var imgwidthPerc = perwVal(3);
var imgheightPerc = perhVal(imgwidthPerc);

// not correct the height is off

any help will be appreciated.

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

You get the ratio of the width vs. height:

const ratio = originalWidth / originalHeight;

and then to find the width for a different height:

const newWidth = newHeight * ratio;

In your example:

const originalHeight = 800;
const originalWidth = 400;
const ratio = originalWidth / originalHeight;
const newHeight = 3;
const newWidth = newHeight * ratio;
console.log(newWidth);

But note Sebastian's point that you may not need it, you may be able to use CSS's aspect-ratio.

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda