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

268
Visualizações
Stretch an iframe with width and height of parent

I've got a module in my Nextjs app that shows events that are currently being live-streamed. Within this module I've got an image preview with a play button that, when clicked, takes you to the live event.

The version with an image...

What I'd like to do, however, is have this preview be the Vimeo video for the event, so it shows a video preview. That's easy enough to do, I can get the embed code for the Vimeo video from the events API, but I'm having trouble getting it to stretch into the full width and height of this rectangle. This is how it's looking right now:

The version with an iFrame

Essentially, I can't figure out the correct styles to get it to stretch to this ratio, similarly to the image. I'm not concerned with what is being cut off or not, I just want to use the video as a background.

Here's what I've got so far (I'm using Nextjs and SASS modules):

The HTML in the component:

<div className={s.liveStream__player}>
  <Link href={`/events/${live.event_id}`} title="Play" className={s.liveStream__play}>
    <PlayButton />
  </Link>
  <iframe
    src={`https://player.vimeo.com/video/${vimeoId[1]}?background=1`}
    className={s.liveStream__preview}/>
</div>

And the SASS:

.liveStream {
  &__play {
    position: relative;
    z-index: 10;
  }

  &__player {
    display: flex;
    height: 100%;
    width: 100%;
    flex-grow: 1;
    align-items: center;
    justify-content: center;
    position: relative;
    overflow: hidden;
  }

  &__preview {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    pointer-events: none;
  }
}

Is there an easy way to accomplish this and get the iframe to stretch to the full width and height of the parent?

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

You have missed one property to stretch iframe (height):

    .liveStream {
      &__play {
        position: relative;
        z-index: 10;
      }
    
      &__player {
        display: flex;
        height: 100%;
        width: 100%;
        flex-grow: 1;
        align-items: center;
        justify-content: center;
        position: relative;
        overflow: hidden;

        // make sure wrapper has necessary sizes
        // min-height: 100vh;
        // just for example purposes:
        height: 300px;
        width: 300px;
      }
    
      &__preview {
        position: absolute;
        top: 0;
        left: 0;
        width: 100%;
        pointer-events: none;

        // add height prop to stretch iframe to parent height
        height: 100%;
      }
    }

Also make sure wrapper has necessary sizes.

You can check codes in Codepen.io example.

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