Removing black borders on a vimeo iframe embed usi

2020-03-18 01:31发布

I am trying to find a way to hide the black strips across the top and bottom of a vimeo video. I thought there might be a way to cover them up with CSS.

I basically wanted to achieve what this person wanted to achieve with an image in the link below except I want to do it with an embedded video whilst keeping it repsonsive.

Removing black borders 4:3 on youtube thumbnails

Many thanks.

HTML

<section class="d5-d13 c5-c13 b5-b13 a5-a13 video">

   <div class='embed-container'>
      <iframe src='http://player.vimeo.com/video/69252713' frameborder='0'
      webkitAllowFullScreen mozallowfullscreen allowFullScreen></iframe>
   </div>

</section>

CSS

.embed-container { 
position: relative; 
padding-bottom: 56.25%; 
padding-top: 30px; 
height: 0; 
overflow: hidden; 
max-width: 100%; 
height: auto; 
}

.embed-container iframe, .embed-container object, .embed-container embed { 
position: absolute; 
top: 0; 
left: 0; 
width: 100%; 
height: 100%;
}

8条回答
女痞
2楼-- · 2020-03-18 01:38

Simply put frameborder="0" as one of your attributes.

查看更多
男人必须洒脱
3楼-- · 2020-03-18 01:47

I just solved this -

The video container was built with a video-captions-container DIV which was a black transparent bar.

查看更多
三岁会撩人
4楼-- · 2020-03-18 01:51

For your use case, I don't think you'll be able to use just css.

Usually we add letterboxing or pillar boxing around video iframes to keep the height and width at a certain ratio for presentation. But in that case, the black borders would just be as simple as a css background.

To keep things responsive, you would set the height to something like zero (like you have) and use the padding hack to keep the aspect ratio of the video (in this case a 16:9 video; 9/16 * 100 = 56.25%). That number would be either your padding-top or padding bottom value. Since the padding is measured with percent, this scales the padding in relation to the width keeping the correct ratio no matter what width you size the video to.

In your case, this video actually has the letterboxing in the actual video which you can see from the source of the video tag within the iframe. I'm not sure why you have the padding-top:30 but that makes the black borders even bigger. You'll need to hack your situation even more though because of the built in letterboxing. I put together a jsfiddle demo here which includes a few comments but it uses JS to achieve what you're looking for.

The concept for the code is as follows:

  • You want the outer container to crop off the bottom and top of the video. Assuming you wanted the video to be responsive, and be cropped, you need to always have the actual video be larger than the outer container which masks it.
  • The video should be moved up in relation to how wide the video is vs the thickness of the top border
  • You'll want to shrink the height of the outer container a bit to compensate for the negative top margin yet still hide the bottom portion of the video

Personally I don't like doing expensive DOM operations on resize which maybe is the reason you asked for solely css but FWIW, you have the demo.

Ideally your best option would be to get the video re-recorded without the letterboxing so all you would need is the padding hack.

查看更多
爷、活的狠高调
5楼-- · 2020-03-18 01:52

Cut the 1px off all edges with CSS:

.embed-container { 
    position: relative; 
    padding-bottom: 43%;        /* Aspect ratio of the video */
    height: 0; 
    overflow: hidden; 
    max-width: 100%;
} 

.embed-container iframe, 
.embed-container object, 
.embed-container embed { 
    position: absolute; 
    top: -1px; 
    left: -1px;
    width: calc(100% + 2px); 
    height: calc(100% + 2px);
}
查看更多
放我归山
6楼-- · 2020-03-18 01:52

I had this same issue and the problem was simple to solve. My videos were embedded in Wordpress pages and posts using oEmbed. Wordpress was wrapping my embedded videos in <p> tags, the <p> tags had some margin which was causing black borders on the top and bottom of my videos. I used the following bit of jQuery to remove the <p> tags from my embedded videos:

$('.embed-container iframe').unwrap();
查看更多
我欲成王,谁敢阻挡
7楼-- · 2020-03-18 01:56

HTML:

<div class="js-video [vimeo, widescreen]">
  [video html goes here]
</div>

CSS:

.js-video {
  height: 0;
  padding-top: 25px;
  padding-bottom: 67.5%;
  margin-bottom: 10px;
  position: relative;
  overflow: hidden;
}

.js-video.widescreen {
  padding-bottom: 57.25%;
}

.js-video.vimeo {
  padding-top: 0;
}

.js-video embed, .js-video iframe, .js-video object, .js-video video {
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  position: absolute;
}

You will find more details here

查看更多
登录 后发表回答