In your use case, I don't think you can only use css.
Usually we add a mailbox or pillar box around the video clips to maintain the height and width in a certain ratio for the presentation. But in this case, the black borders will be as simple as a css background.
To maintain responsiveness, you should set the height to about zero (like yours) and use a hacker robe to maintain the aspect ratio of the video (in this case, the video is 16: 9; 9/16 * 100 = 56.25%). This number will be either your top or bottom padding value. Since padding is measured as a percentage, this scales the indentation with respect to the width, maintaining the correct ratio, no matter what width you occupy to fit the video.
In your case, this video actually has a mailbox in real video, which you can see from the source of the video tag in the iframe. I'm not sure why you have padding-top:30 , but that makes the black borders even bigger. You need to hack the situation even more, though because of the built-in mailbox. I put together a jsfiddle demo here , which contains a few comments, but uses JS to achieve what you are looking for.
The code concept is as follows:
- You want the outer container to crop the bottom and top of the video. Assuming you want the video to respond and crop, you always need the actual video to be larger than the external container that masks it.
- The video should be moved depending on how wide the video is and the thickness of the top border.
- You need to slightly reduce the height of the outer container to compensate for the negative top margin, but still hide the bottom of the video.
Personally, I donβt like doing expensive DOM operations when resizing, which is probably the reason why you asked exclusively for css, but FWIW, you have a demo.
Ideally, the best option would be to overwrite the video without a mailbox, so all you need is a gasket.
source share