Tips for creating a flexible video layout using HTML

I've been trying to figure out how to make a video responsive in HTML with CSS, but no matter what I do, it just doesn't seem to work. Can someone please provide some guidance?

Here is the HTML code that I am using:

<div class="container">
   <video width="540px" height="320px" controls src="Videos/Video.mp4"></video>
</div>

And here is my CSS code:

.container {
  width: 100%;
}
video {
  height: auto !important;
  width: 100% !important;
}

Answer №1

To optimize the display of your videos, consider removing the width and height attributes from the video tag. Instead, add a max-width setting in the CSS rule:

<div class="video-container">
   <video controls src="Videos/Video.mp4"></video>
</div>

.video-container {
  width: 100%;
}
video {
  height: auto;
  width: 100%;
  max-width: 540px;
}

By doing this, the video will be restricted to a maximum width of 540px within the container. If the container is wider than 540px, the video will adjust accordingly while maintaining its original proportions. However, if the video file itself is larger than the specified maximum width, use the original size width as the value for max-width in the CSS to prevent loss of quality.

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

Python Parsing HTML content

The problem at hand involves the inability to navigate to the next page on an HTML page. Upon accessing an HTML page displaying search results, a line of numbers is available at the bottom to select the desired page i.e. "1 2 3 4 next" - clicking on "2" re ...

Monitor the element's height for any changes and update it accordingly on a separate element

Is there a way to accomplish the following: I currently have a navigation bar with the class of "navbar-fixed-top", and I've also added a style of min-height: 50px; Beneath the navigation bar, I have a content section with a class style of padding-t ...

Utilizing AJAX alongside a checkbox

I'm a beginner in the world of AJAX and JavaScript, but I have taken up the challenge of sending a value based on an HTML "" tag using Ajax to a Python handler. Below you will find my code, inspired by this site. The issue I am facing is understanding ...

Position the div elements at the center

I am facing an issue with aligning elements inside a div both vertically and horizontally. I have tried various CSS methods like margin auto, but none seem to work. If you could provide a solution and explain how it works, it would be greatly appreciated. ...

Removing a Row from an HTML Table with JavaScript

I am currently facing an issue with my JavaScript code that is intended to delete a row from an HTML table. Additionally, I have a JavaScript code snippet that generates a column dynamically at runtime with a delete anchor tag. var tbody = document.getEl ...

What is the best way to place a div absolutely in a flex box without affecting the positions of its neighboring elements?

I have an element with the #text inside a flex container and I want to position something absolutely beneath it: How can I ensure that it does not affect the positioning of its siblings in the flex layout? #container{ display: flex; align-items: cen ...

Trouble with Loading jQuery Files on Beaglebone Server

Working on a wireless robotics project that involves using node.js and jquery to create a webpage "controller". Currently, the code is set up to work with an internet connection because it downloads scripts from internet addresses. The goal is to make it ...

Exploring Pseudo Classes in Oracle ADF

Within my skin file (which is an extension of Skyros), I have defined a rule as: .arrow_box:after { /*insert some css rules here*/ } .arrow_box:before { /*insert some css rules here*/ } The goal is to generate an arrow on the top of the box simila ...

How can I prevent an image from scrolling on a webpage?

I am seeking a way to prevent an image from scrolling along with the rest of the page. I want the image to occupy a specific percentage of width, while allowing the browser to determine the appropriate height for display. The image's height should als ...

Aligning Description Item components horizontally in antdLearn how to easily horizontally align Description

Currently, I am utilizing the `antd` Description components. In this scenario, when there is no `title` for the items, the value should be aligned to the left. You can see an example of this alignment in the image below: https://i.sstatic.net/Ah70f.png I ...

How to automatically close a JavaScript popup once a form is submitted and refresh the parent page

I am facing an issue with a popup on my website. I have a separate page called math.ejs that pops up when a button is pressed on the index.ejs page. However, after clicking the submit Ok button in the math.ejs popup, I want it to close and display the calc ...

Issue with loading the main.css file

Getting Started Managing two domains can be a challenge, especially when trying to make them appear as one seamless website. In this case, I have ownership of and . Goal My goal is to merge the content of https://mauricevandorst.com/personal-page/index ...

Displaying the following item in the array when clicking a button in a modal

Hey there! I'm trying to display a new quiz question in a modal when the next button is clicked. I'm new to angular 2 so I might be missing some basic elements. I know that I can access the questions from the html because I have shown them in oth ...

Some of the CSS code in my file is not displaying properly on my ejs file

For some reason, only the CSS styles for my footer are rendering on my ejs file. The rest of my CSS doesn't render at all. I've tried defining the path of my static files to my views directory using the path method: app.use(express.static(path.jo ...

Issue with jQuery UI: Accordion not functioning properly

I have created a nested sortable accordion, but there seems to be an issue. Within the 'accordion2' id, the heights of each item are too small and a vertical scroll bar appears. The content of the item labeled '1' is being cut off, show ...

`The logo does not dim when the popup is displayed`

I'm currently experiencing an issue with pop-ups on my page - when they appear, they create a shade over all elements of the page except for my two logos and are displayed with a border around them. Here's what my page looks like before the popu ...

The appearance of the logout button may differ depending on the web browser being used

I have implemented a straightforward logout button using the following code: <li><a href="http://localhost:8666/web1/profile/mainpage/logout.php" onclick="return confirm('Are you sure to logout?');">Log Out</a>&l ...

The jQuery animate() method fails to execute animations

I'm currently working on a JavaScript animation project and I've run into some roadblocks. One particular issue I'm facing is with animating the <label>'s margin-top, as it's not behaving as expected. For example: $(' ...

Positioning JQuery sliders

I've been working on a jQuery slider for my header, but I'm encountering an issue where the previous image drops down to the next container instead of staying in place and transitioning smoothly. It seems like there might be an error in my HTML/C ...

I am experiencing issues with Google Fonts not functioning properly when I insert the bootstrap CDN

I have encountered an issue while working on my landing page. I am using Google fonts for the design and trying to integrate Bootstrap as well. However, whenever I add the Bootstrap link, all the font styles stop working. I have checked the order of the CS ...