I encountered an issue with a black outline appearing around a video, even after attempting various solutions. Initially, using clip-path: inset(10px 10px); seemed to solve the problem, but the outline reappeared after a few months. Solution is written in Angular!!!
<section id="video-wrapper">
<video
#maltaIntroVideo
id="video"
(ended)="onVideoEnded()"
muted
playsinline
(loadedmetadata)="onMetadataLoaded()"
autoplay>
<source
src="/assets/VisitMalta_Logo_Animated.mp4"
type="video/mp4" />
</video>
<div id="video-overlay" #videoOverlay></div>
</section>
#video-wrapper {
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
width: 100vw;
height: 100vh;
overflow: hidden;
position: relative;
}
#video {
width: 80%;
height: auto;
position: relative;
z-index: 1;
border: none;
clip-path: inset(10px 10px);
}
#video-overlay {
position: absolute;
border: 15px solid white;
z-index: 2;
}
I get references to the video and video overlay elements, and I set up an event listener for screen size changes to re-adjust the overlay size. This ensures the overlay always matches the video’s dimensions, hiding the black outline. The loadedmetadata event also triggers adjustOverlaySize to ensure proper initialization.
import {
AfterViewInit,
Component,
ElementRef,
EventEmitter,
Output,
ViewChild
} from '@angular/core';
@Component({
selector: 'app-video-visitmalta',
standalone: true,
templateUrl: './video-visitmalta.component.html',
styleUrls: ['./video-visitmalta.component.css']
})
export class VideoVisitmaltaComponent implements AfterViewInit {
@Output("videoEnded") videoEnded = new EventEmitter<void>();
@ViewChild('videoOverlay', { static: false }) videoOverlay: ElementRef<HTMLDivElement> | undefined;
@ViewChild('maltaIntroVideo', { static: false }) maltaIntroVideo:
| ElementRef<HTMLVideoElement>
| undefined;
onVideoEnded() {
this.videoEnded.emit();
}
ngAfterViewInit(): void {
if (this.maltaIntroVideo) {
this.maltaIntroVideo.nativeElement.muted = true;
this.maltaIntroVideo.nativeElement.play();
}
window.addEventListener('resize', this.adjustOverlaySize.bind(this));
}
onMetadataLoaded() {
this.adjustOverlaySize();
}
private adjustOverlaySize() {
if (this.maltaIntroVideo && this.videoOverlay) {
const videoElement = this.maltaIntroVideo.nativeElement;
const overlayElement = this.videoOverlay.nativeElement;
const videoRect = videoElement.getBoundingClientRect();
overlayElement.style.width = `${videoRect.width}px`;
overlayElement.style.height = `${videoRect.height}px`;
overlayElement.style.top = `${videoRect.top}px`;
overlayElement.style.left = `${videoRect.left}px`;
}
}
}
So i get the reference to the video and the video-overlay and i set an event lisner for when the screen size changes to trigger the adjustOverlaySize again wich gets the current height width and positioning of the video and i set the overlay with those values. Also i have (loadedmetadata)="onMetadataLoaded()" when the video initizalize fully in the begining to trigger the adjustOverlaySize. And the last step was to create enouch bigger white border wich hides the video black outlines. enter image description here