2017-12-16 6 views
0

나는 아주 간단한 질문이있다. iframe의 종횡비가 반응하는지 확인하려면 어떻게해야합니까?iFrame의 화면 비율이 어떻게 반응하는지 확인하려면 어떻게합니까?

iframe은 YouTube 동영상이며 브라우저 창의 크기에 관계없이 iframe의 종횡비를 16 : 9로 유지하려고합니다. 유튜브 iframe을 자동으로 화면 비율을 유지하지 않기 때문에, 나는 비디오의 화면 비율을 유지하는 방법이 필요하고, 폭이 90vw을 할

@media screen and (max-width: 600px) { 
    iframe, body { 
    max-width: 90vw; 
    height: auto; 
    } 
} 

iframe { 
    border: 0; 
    width: 600px; 
    height: 338px; 
} 

:

여기에 모바일 장치에 대한 내 현재 코드입니다. 이 현재 코드의 문제점은 원하지 않는 레터 박스를 남기고 너비 만 적용한다는 것입니다.

답변

1

정말로 이것을 얻기 위해 미디어 쿼리가 필요하지 않지만 원하는 경우 미디어 쿼리에서 이동할 수 있습니다. 그럼, 어떻게 성취되고 있습니까?

때문에, 우리는 우리가 aspect ratio of 16:9폭이 90vw이 때문에 높이도 50.85vw를 초과하지 않아야 초과하지 않아야을 필요로 알고있다. 그리고 귀하의 절대 치수 한계에 따라 max-height and max-width을 설정합니다. 600px 및 338px입니다. 이제 iframe dimensions to the 100% of the container을 설정하면 해당 크기가 상속됩니다. :)

.tv-wrapper { 
 
    max-width:600px; 
 
    max-height:338px; 
 
    width:90vw; 
 
    height:50.85vw; 
 
    margin:0 auto; 
 
} 
 
iframe { 
 
    width:100%; 
 
    height:100%; 
 
}
<div class="container"> 
 
     <div class="tv-wrapper"> 
 
      <iframe class="sproutvideo-player" src="//videos.sproutvideo.com/embed/489adcb51e1debcdc0/e0d9daac7a1a9b30? 
 
bigPlayButton=false&amp;showControls=false" frameborder="0" allowfullscreen="allowfullscreen"></iframe> 
 
      </div> 
 
    </div>

+0

매우 직관적이고 빠른 답변을 보내 주셔서 감사합니다. 작동 코드 [here] (https://thimbleprojects.org/henryweeblyowner/365305/)를 볼 수 있습니다. – Henry7720

+0

@ Henry7720 문제 없음 :) 좋아 보인다. –

0

컨테이너에 iframe을 래핑하십시오.

.media-container { 
    position: relative; 
    padding-bottom: 56.25%; // = 16:9 
} 

.media-container iframe { 
    position: absolute; 
    top: 0; 
    left:0; 
    right: 0; 
    bottom: 0; 
    width: 100%; 
    height: 100%; 
} 
+0

기다립니다, 나는 가로 세로 비율을 유지하기 위해 다른 방법이, w3schools.com에 패딩 종횡비 방법을 보았다? – Henry7720

+0

아니요 - 패딩 방법은 가로 세로 비율로 이동하는 방법입니다. 또한 [bootstraps embed class] (https://getbootstrap.com/docs/4.0/utilities/embed/#aspect-ratios)가이를 사용하고 있습니다. – l4ci

관련 문제