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

158
Vistas
img srcset and sizes not working in PHP/JavaScript

I am creating dynamic HTML from PHP. I wanted to resize images for mobile, but it doesn't seem to work. It picks up the larger image on my desktop with resolution 1440x900 as expected, but on my mobile the resolution shows up as 360x640 but it still picks up the larger image whereas I want it to pick the resized image. I am not an expert so any help would be appreciated.

<script language="javascript">
alert("Your screen resolution is: " + screen.width + "x" + screen.height);
</script>

        <?php
        print "<div class=\"row\">";
            print "<div class=\"img-P\">";
                print "<img srcset=\"images/resized/$img_resized 640w, images/$img 1024w\" 
                            sizes=\"(max-width: 640px) 640px, 1024px\" 
                            src=\"images/$img\"
                            loading=\"lazy\" />";
            print "</div>";
        print "</div>";
        ?>
about 4 years ago · Juan Pablo Isaza
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