How can I add a CSS filter to an HTML5 video without interfering with the controls?

Can CSS filters be applied solely to video content without affecting the media controls UI provided by the browser?

  video:first-child {
    filter: brightness(40%);
  }
<video controls></video> vs.
<video controls></video>

When applying a CSS filter to a video element, it appears that the same effect is also applied to the media controls UI. Is there a way to avoid this and only affect the video itself?

Answer №1

If you're looking for a creative solution, why not try customizing your play/pause buttons with some JavaScript? You can then style the video however you like. Here's an example of how you could do it:

(function (window, document, $, undefined) {
    'use strict';

    $(document).ready(function () {
        $('#play').on('click', function(){
            $('.my-video')[0].play();
        });
        $('#stop').on('click', function(){
            $('.my-video')[0].pause();
        });
    });


})(window, document, jQuery);
video {
    border: 10px solid green !important;
    opacity: 0.6;
    box-shadow: 12px 9px 13px rgba(255, 0, 255, 0.75);
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div>
<video width="320" height="240" class="my-video">
    <source src="https://www.w3schools.com/html/movie.mp4" type="video/mp4">
    <source src="https://www.w3schools.com/html/movie.ogg" type="video/ogg">
    Your browser does not support the video tag.
</video>
</div>
<button type="button" id="play">Play</button>
<button type="button" id="stop">Stop</button>

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

Is it possible to dynamically override inline styles?

My HTML code is as follows: <div title="remove css"style="position:relative;">Remove my style</div> After the page loads, I need to completely remove the position style attribute. Due to limitations, I cannot override the CSS. Is there a way ...

What is the most efficient way to cycle through HTML image elements and display a unique random image for each one?

I'm currently working on coding a simple game that involves guessing the Hearthstone card based on its flavor text. I plan to add a button later to progress in the game, but I haven't implemented that yet. To start, I created 4 image elements an ...

I attempted to apply vertical-align and color properties to the static_nav div, but they didn't have any effect. Could this be due to its placement within the header? What steps should I take to resolve this issue?

<!DOCTYPE HTML> <html lang ="en"> <meta charset = "utf-8" /> <head> <title>Sample Page</title> <link rel="stylesheet" type="text/css" href="Web_Design_01_Stylesheet.css" /> </head> <body> &l ...

Beginner Inquiry: Implementing an Overlay Div with Text on Top of an Animated Element

Looking to create a stacked div layout but facing some challenges due to being new at this. // Particle Animation !function(a){var b="object"==typeof self&&self.self===self&&self||"object"==typeof global&&global.global===glo ...

Submit button in the contact form fails to refresh upon being clicked

My website features a contact form with mandatory fields that users must fill out. If a user misses a field and is prompted to complete all fields, upon returning to fill everything out and clicking "send," nothing happens. The SEND button becomes unrespo ...

Using AJAX to upload an image and passing multiple parameters

I'm facing an issue when trying to upload an image along with other input text in a form and send it to ajax_php_file.php. Whenever I upload the image, all my input text fields appear empty. Any assistance would be greatly appreciated. Thank you very ...

Is it possible to use HTML alone in Bootstrap 5 to link a button to display a toast notification?

I'm working on a Bootstrap page that includes a button and a toast element sourced from the Bootstrap documentation. The documentation states that I need to initialize the toast in JavaScript during page load. My goal is to have the toast appear when ...

Is the content within the h3 tag invisible on Internet Explorer 8?

The text within the h3 tag displays correctly in Firefox and Chrome, but is not visible in IE8. I'm unsure of what the issue might be. Here is the HTML code: HTML: <div id="right"> <h3> profile <div id='upload' cla ...

Conceal table rows with JQuery in html

I need assistance in hiding a row in an HTML Table that contains a value of 0.00 in the third column. I've attempted using JQuery and CSS, but so far no success. Below is the code snippet: <%@ page language="java" contentType="text/html; charset= ...

Troubleshooting problems with smooth scrolling in jQuery

After following a tutorial on how to implement smooth scrolling using jQuery on my website, I encountered an issue with the animation not working correctly. I am seeking assistance from someone who can help me identify where my jQ code went wrong and how t ...

Mastering the art of horizontal alignment in forms

So, within my render function, the following code is used: render() { <div> <form id="one"> <TextField id="t1" ... /> <Button id="b1" /> </form> <div id="empty"><div ...

Having trouble implementing responsive image with fixed aspect ratio code

I've tried several tutorials online to make this image responsive with a fixed aspect ratio, but nothing seems to work. The image is set at 900x400px and I want it to remain fully visible on smaller screens as well. Here's the codepen link < ...

Unable to interpret data from the API

{ id: 8, customerName: "xyz", customerMobileNumber: "123456789", customerBillingAddress: "xyz address", customerShippingAddress: "xyz address", customerProductPurchasedDate: "2021-11-09T09:07:00.000Z", cust ...

Guide to populating a dropdown list using an array in TypeScript

I'm working on a project where I have a dropdown menu in my HTML file and an array of objects in my TypeScript file that I am fetching from an API. What is the best approach for populating the dropdown with the data from the array? ...

Adding a border to my image that extends to the edges of the page

.overlay{ position:absolute; top:0; left:0; height:100%; width:100%; background:url(hex-shape.png) no-repeat center; z-index:99999; } I have created an overlay background image that covers the entire page. I want the area surrounding the ove ...

What is the best method to extract individual data values from ul li tags using PHP?

As I navigate through a page filled with HTML codes, I stumble upon snippets like this: <ul class ='trainList'> <li> <div class="smallFont farelist no-discount "> <div class="train-no">ABC 701</div> ...

Invoke a C# method within an ASP.NET environment by clicking on an HTML hyperlink

I have a page called myEditPage.aspx that contains both inputs and TextAreas. I want to upload the data from these elements to a database, but to accomplish this, I need to create a link using <a href=".."> that will connect to a function in my myEdi ...

Running a PHP MySQL function with Onclick without using POST data

I am seeking to trigger a MySQL search using an ONCLICK event in PHP. Initially, I considered utilizing a JavaScript or jQuery function to parse the selected ID through JS. However, I am unsure of how to re-execute the PHP to conduct a new search on the d ...

Mastering the art of combining style with the perfect class name

I am looking to update all instances of <p class="p1"><span class="s1"> Sent with the appropriate style that was defined earlier in my iOS project. I am relatively new to iOS development and this is a dynamic HTML content that can render in v ...

When using the 'rtl' direction in Dojo Text, all special characters are aligned to the right

I'm having an issue with keeping the text of a button centered followed by an icon. The code works fine until I add special characters in front of the button text. In that case, the special characters are placed after the text followed by the icon. I ...