Troubleshooting: CSS Border Radius Not Applying to HTML5 Video Element in Chrome

Is there a way to achieve rounded corners with transparency on an HTML5 video in Google Chrome, similar to the border-radius property? It seems like border-radius doesn't work for the HTML video tag in Chrome, although it does in IE10 and Firefox.

I came across an answer that suggested a solution (https://stackoverflow.com/a/16470150/1115367), but it ended up filling the rounded corners with color instead of making them transparent.

Are there any techniques or methods to make border radius work on an HTML5 video in Google Chrome without compromising video performance? I'm open to using javascript/jQuery if needed.

Answer №1

As stated in another response:

There are known issues in WebKit related to clipping content along with border-radius, such as this one or the specific problem addressed in this thread focusing on the video element.

If you add a border-radius to an enclosing element that also includes a -webkit-mask-image, it is achievable in Chrome. Check out this demonstration that applies a mask to a transparent png and clips the corners of the video:

Live Demo (transparent background): http://jsfiddle.net/pe3QS/24/

Update: By modifying the HTML/CSS to use one wrapping element only, the solution now functions across IE9+, Firefox, and Chrome.


CSS Code:

div.outer {
    float: left;
    height: 240px;
}
div.outer video {
    width: 320px;
    height: 100%;
    -webkit-mask-image: url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAIAAACQd1PeAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAA5JREFUeNpiYGBgAAgwAAAEAAGbA+oJAAAAAElFTkSuQmCC);
    border-radius: 32px 0 32px 0;
}

HTML Code:

<div class="outer">
    <video src="http://www.w3schools.com/html/movie.ogg" type="video/ogg" controls></video>
</div>

Answer №2

To overcome this issue, consider utilizing a canvas element. While it may involve more code, this method provides greater flexibility and control.

You can style the Canvas element with CSS:

#canvas {
    background:#000;
    border-radius:20px 0 0 20px; /* applying styles */
}

Next, manually create and load the video (alternatively, you can load the video using HTML and hide the original video element):

Check out live example here

var video = document.createElement('video'),
    url;

/// configuring video instance    
video.preload = 'auto';
video.addEventListener('canplaythrough', start, false);

/// determining compatible video format and providing online link
if (video.canPlayType('video/ogg').length > 0 ) {
    url = 'http://www.w3schools.com/html/movie.ogg';
} else {
    url = 'http://www.w3schools.com/html/movie.mp4';
}

/// initiating video loading process
video.src = url;

/// starting the loop
function start(e) {

    /// obtaining canvas and context
    var canvas = document.getElementById('canvas'),
        ctx = canvas.getContext('2d'),
        w = canvas.width,
        h = canvas.height,
        toggle = false;

    /// playing video and looping through frames
    video.play();
    loop();
    
    function loop() {
        
        /// reducing FPS to improve performance
        toggle = !toggle;
        if (toggle === false) {
            requestAnimationFrame(loop);
            return;
        }
        
        /// drawing video frame onto canvas
        ctx.drawImage(video, 0, 0, w, h);
        requestAnimationFrame(loop);
    }
}

This is a basic example and it's essential to properly handle the canPlayType results for various formats like webm as well. Keep in mind that this method may not be compatible with Safari browsers due to their lack of support for drawImage with video elements as source.

Answer №3

Experience our innovative video player with rounded corners and a captivating drop shadow using this simple code:

border-radius: 22px;
overflow: hidden;
-webkit-transform: translateZ(0);
box-shadow: 0 19px 51px 0 rgba(0,0,0,0.16), 0 14px 19px 0 rgba(0,0,0,0.07);

The secret sauce lies in -webkit-transform: translateZ(0). By utilizing this line of code, the browser is instructed to utilize GPU rendering instead of CPU, enabling seamless display of visually rich styles like this.

Tested successfully on Safari 11, Chrome 65, Firefox 59, Edge Win 10, & IE 11

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Issue [ERR_MODULE_NOT_FOUND]: The module 'buildapp' could not be located within buildserver.js

I am currently working on a node project using typescript. The project's structure is organized in the following way: --src |-- server.ts |-- app.ts --build |-- server.js |-- app.js In server.ts: import { app } from &q ...

What is the process for selectively applying Mantine styles.css solely to React component(s) residing within a legacy web page?

As we transition our old web application from Bootstrap 4.x to a React based framework, our approach involves gradually integrating React components into each page until the entire page is operated by a top-level React app. We have chosen Mantine as our c ...

I am attempting to transmit an Error Object through an Axios POST request, but the server is receiving an empty Object

Hey everyone, I'm currently working on creating a Logging Microservice specifically for capturing frontend errors. The goal is to log all errors in a specific format like the example below: catch(err){ sendToLogs({message: 'Could not read input ...

Trying to access the main container without also triggering the animations for its children isn't possible

Despite my extensive search efforts, I have not been able to find a solution to this seemingly common issue. As a vendor, I am limited in my ability to alter the client's HTML and use ULs. My objective is to create a hover effect where only the conten ...

Utilizing angularjs ng-repeat directive to present JSON data in an HTML table

I've been struggling to showcase the JSON data in my HTML table using AngularJS ng-repeat directive. Here's the code snippet: <thead> <tr> <th ng-repeat="(header, value) in gridheader">{{value}}</th> </tr> </ ...

Modifying the URL on the fly in Gatsby and React

Is there a method available to dynamically update the URL in the browser without causing a page reload? I have a set of paginated pages where clicking on a different page updates the content without refreshing the entire page, while also scrolling to the ...

Integrate functionality to track elapsed hours in stopwatch timer

Struggling to incorporate hours into my JS Stopwatch timer, the math for calculating the hours section is proving difficult. This is what I have so far, but I suspect the issue lies within the h variable. function formatTime(time) { var h = m = s = ...

Searching for a document using the $eq operator in MongoDB within the context of Next.js - what is

In my Next.js code, I am fetching a document from MongoDB using a unique slug. Here is the code snippet: export async function getStaticProps(context) { const postSlug = context.params.postPage; const { db } = await connectToDatabase(); const posts ...

Retrieving Data from all Rows in jQuery DataTables

Is there a way to copy all rows in jQuery DataTables into a JavaScript array by clicking the header checkbox? https://i.sstatic.net/57dTB.png I need to locate where jQuery DataTables store the HTML for the remaining page of rows so that I can manipulate ...

What sets apart jQuery's `click`, `bind`, `live`, `delegate`, `trigger`, and `on` functions, and how can they be utilized differently in coding

I have gone through the documentation for each function provided on the official jQuery website, but I couldn't find any comparison listings for the following functions: $().click(fn) $().bind('click',fn) $().live('click',fn) $().d ...

How can one properly transition an Angular 1 provider to Angular 2?

While there is ample documentation and examples available on how to convert Angular 1 services and factories to Angular 2, the process of converting an ng1 provider to its equivalent in ng2 seems to be a bit more scarce. Here's an example of a provid ...

Manipulate a custom member field in a Safecracker form with jQuery, Ajax, and Expression Engine

Currently, I am using jQuery in combination with Expression Engine to send an ajax form. This process involves the Safe Cracker module, which is well-documented on the following page: My form is designed for logged in members to vote. I want to restrict t ...

Guide on showcasing SQL information in HTML using AJAX and JQuery for a dynamic table display

I have some data stored in a SQL file and I'm looking to present it as a table in HTML using AJAX JQuery. Although the data is correctly retrieved when inspected, I am struggling with displaying it on my HTML page. This concept is new to me and I&apos ...

Guide on modifying HTML attribute with TFHpple in the Swift programming language

I have received an HTML string and I want to modify the elements inside them, specifically the img tags, so that they have a style of width = 100% and height set to auto. This way, when I embed these images into a web view, they can easily adjust to fit th ...

Calculate the number of rows in a table that contain identical values

I have a puzzling issue that has been on my mind. I currently have an SQL statement that selects specific rows from my database and displays them in an HTML table, which is functioning properly. However, I now need to determine how many rows have the same ...

What could be the reason for the malfunctioning of the "subscribe" button?

Whenever the subscribe button is clicked, it should send an email to the "subscriptions" section of the database. Unfortunately, when I click the button, nothing seems to happen. My understanding of this is very limited and I can't seem to troubleshoo ...

retrieve the parent or preceding element depending on the child or adjacent class

Consider three different types of products in HTML, where you want to target the product-block element only if it has a child or sibling with an input element that has the class mySelector. Type A contains the 'mySelector' element within. Type B ...

Updating the value of a localStorage key after each successful AJAX call in JavaScript

I'm currently facing a challenge with my local storage key value. The issue is that it doesn't update the value when the AJAX call successfully returns data. It only retains the old stored data, requiring me to manually refresh the page by pressi ...

interactive vuetify navigation trail elements

Currently working on a vuetify project and I'm facing an issue with implementing breadcrumbs. The problem arises when clicking on a breadcrumb, as it deletes the ones that come after it in the list. I've tried some code snippets but could only ma ...

Unexpected and lengthy Styling rules generated from Gulp Sass compilation

Whenever my gulp sass task runs, it successfully creates the combined file. However, there are a few peculiar rules that stand out. These rules are incredibly long, about 1.5 million characters, and result in a 1.1mb file each time. This is clearly not acc ...