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

275
Vistas
In JS can I use an if-statement for substituting a css media query?

I want the iFrame to adjust its height to that of its src document ONLY when the viewport-width is equal or less than 800px.

Can I somehow implement this into a CSS media query?

Or do I need to apply an if-statement to the script?

I only know a little html and css, so as a non-programmer I already did a lot of research and try, nothing worked 'til now. A little help would be much appreciated.

the iframe code:

<iframe name="iframe" class="iframe-content" id="iframe" frameborder="0" src="suchness.html"></iframe>

the script for adjusting the iframe height to its content

<script>
    
let iframe = document.querySelector("#iframe")
         
iframe.addEventListener
('load', function() 
{iframe.style.height = iframe.contentDocument.body.scrollHeight + 'px';}
);  

</script>
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

You can do media-queries in both CSS and JS. In this example it is only really possible in JS, as you are styling the iframe with a dynamic value generated in JS.

const breakpoint = window.matchMedia("(max-width: 800px)");
if (breakpoint.matches) {
  // code to be executed
}
@media only screen and (max-width: 800px) {
  .element {
    color: red;
  }
}

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