11

I have the below image of a blank Macbook.

enter image description here

The image is 1034 × 543.

I want inset a youtube video inside of the "grey" area of the screen. I want it to appear as if the youtube video is playing on the laptop screen.

I also want the laptop image / youtube video to scale, so that when the web page is in a tablet or mobile view, the image and video shrink to match.

I am trying to use fitvid.js to accomplish this but am not having luck -- I can get the video to fit at one static size but I cannot get it to still fit perfectly on resize, it gets deformed.

Below is my current markup:

html:

<div class="col-sm-12">
  <div class="title">
    <h2>What's New</h2>
    <small>ASC Sneak Peak</small>
  </div>
  <div class="macbook-wrapper">
    <iframe width="715" height="402" src="//www.youtube.com/embed/**url**" frameborder="0" allowfullscreen></iframe>
  </div>
</div>

SASS:

.macbook-wrapper{
  background: url('../img/content/home/macbook.png') no-repeat;

  .fluid-width-video-wrapper {
    width: 97.5%;
    background: #000;
  }
}
4

1 回答 1

21

您可以使用填充和百分比灌输一些技巧,这样您就可以相应地缩放。基本上,设置一个纯粹以 % 为基础的容器,其绝对位置 iframe 会根据容器进行相应缩放。

HTML

<div>
  <iframe></iframe>
</div>

CSS

div {
    position: relative;
    padding-top: 25px;
    padding-bottom: 67.5%;
}
div iframe {
    background: url(http://i.stack.imgur.com/zZNgk.png) center center no-repeat;
    background-size: contain;
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
}

您只需要添加box-sizing: border-box;一些padding内容即可将 iframe 定位在屏幕内。看看http://jsfiddle.net/41sdho4w/

更进一步 - 这是一个带有容器的版本,以帮助控制max-widthmax-height不是依赖于主体/视口http://jsfiddle.net/4g9e3ywy/

于 2014-08-29T18:11:38.593 回答