Adapt the size of HTML video tags based on the width of the screen and level of

Within the site (developed with React, utilizing Typescript and Tailwind), there exists a component that allows users to watch videos (constructed using the HTML Video tag). Additionally, beneath the video, there are various dropdowns and buttons. However, our focus will be on the HTML Video component.

The layout of this page can be illustrated schematically as follows:

FirstPageContent.tsx

<div className="container m-auto flex h-full max-w-[600px] flex-col">
    <div className="flex">
      <VideoComponent />
    </div>

    <div className="flex">
      <DropdownComponents />
    </div>

    <div className="flex">
      <Buttons/>
    </div>
</div>

VideoComponent.tsx

  <div className="relative h-full w-full">
    <video
      ref={videoRef}
      className="w-full"
    />
  </div>

Currently, I am adjusting the size of the HTML Video by applying padding on the left and right. However, I am aware that this method may not be universally applicable. See sample code below:

main.css

@media screen and (max-width:812px) {
  .container{ padding-right:90px; padding-left:90px;}
}
@media screen and (max-width:750px) {
  .container{ padding-right:75px; padding-left:75px;}
}
@media screen and (max-width:700px) {
  .container{ padding-right:60px; padding-left:60px;}
}
@media screen and (max-width:650px) {
  .container{ padding-right:45px; padding-left:45px;}
}
@media screen and (max-width:600px) {
  .container{ padding-right:30px; padding-left:30px;}
}

I have only provided a snippet of the code; it's clear that there are many more conditions involved. Hence, my query is: Is it possible to dynamically adjust the size of the HTML Video based on screen dimensions and zoom levels, akin to YouTube's approach?

Answer №1

If you use different units like % or vw instead of px, the size of the video element will adjust based on the screen size.

video {
    width:80vw;
}

Alternatively, you could dynamically change the size of the video element based on the screen width and height using JavaScript, but this may not be the most effective approach.

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

Calculating the annual total in angular 4 - a step-by-step guide

I have successfully calculated the sum of costs between each other, but now I am facing a challenge in summing up the total budget for the entire year. I have attempted to achieve this, but unfortunately, I am encountering an issue as it is showing me &apo ...

Is there a way to implement infinite scrolling in my MUI DataGrid component?

Hey there! I have a custom component that needs to have infinite scrolling added to it. I tried looking into MUI DataGrid for solutions, but didn't have much luck implementing anything successfully. Currently, I'm fetching data using GraphQL and ...

Switching the color scheme between mobile and desktop devices to make the background look

As a newcomer to threejs, I have just begun learning and developing with this technology. I am aware that certain features may be different on mobile browsers compared to desktop ones due to limitations. However, I have encountered an issue that I cannot s ...

Creating an optical illusion using nested left borders in HTML and CSS for a captivating and repeating visual impact

I am looking to achieve a nested border-left effect on HTML lists where the left border moves in one step with each nested level: https://i.sstatic.net/QDS3d.png What I want is something similar to this with minimal gap between the listed term and bullet ...

What is the best way to ensure the menu background aligns perfectly with the header in HTML/CSS?

Issue: Menu background doesn't align with header. (visible in the image provided below) VIEW IMAGE Any suggestions on how to resolve this alignment problem? CSS CODE : .header { margin:0px auto; max-width: 960px; } #header { height:30 ...

Exploring the process of implementing a dynamic background image feature in Vue

Looking to create a dynamic navbar and change its background image. I attempted the following: Here is my attempt: <b-navbar toggleable="lg" v-bind:style="headerStyle"> this.headerStyle = { backgroundImage: &a ...

Modify the Markdown blockquote HTML format in Jekyll

Currently, I am diving into the world of Jekyll and I am working with a basic file that includes YAML frontmatter like this: --- layout: 'post' --- > Test Quote One accomplishment I'm proud of is successfully linking my CSS stylesheet t ...

Lazy loading a costly Material-UI modal in React

My issue involves an expensive Material-UI modal component that takes about 1 second to render. I attempted to lazy load it using Suspense and React.lazy, but unfortunately, it did not work as expected. It seems that lazy loading only works for imports. T ...

Challenges with Internal Styling on Wordpress Sites

Okay. I've been dealing with some internal style issues on my Wordpress website. After dedicating hours to trying to change styles for various elements, I realized that the main html file contained a bunch of internal style sheets that were overridin ...

Understanding how to leverage styles.module.scss for implementing personalized styling within react-big-calendar

I'm currently working with the react-big-calendar library in order to develop a customized calendar. However, I've encountered an issue where the SCSS styling is not being applied correctly. export const JobnsCalendar = () => ( <Calendar ...

What are the differences between TypeScript's 'Dictionary' type accessors for objects and objects with predefined members?

Currently, I am delving into TypeScript by following an online tutorial. While my programming background primarily consists of 'structurally' typed languages like C and ActionScript 3, TypeScript presents some new concepts for me to grasp. One p ...

The 'ReactType' type is not generic within material-ui@next

After installing material ui@next, I encountered an error in the node modules. ERROR in [at-loader] ./node_modules/material-ui/Avatar/Avatar.d.ts:8:15 11:31:52 web.1 | TS2315: Type 'ReactType' is not generic. 11:31:52 web.1 | ERROR in ...

Tips for embedding Apache Superset visualizations into an Angular 7 app: Overcoming hurdles with authentication and headers

I am currently working with Apache Superset to create charts. I am looking to embed these charts in my Angular 7 application using an iframe. One major problem I encountered is an authentication failure with the following error message: Refused to display ...

Error: Unable to locate module: cannot find './node_modules/@material-ui/core/IconButton'

Encountering an error in the browser: Error: Failed to compile ./src/components/layout/search/Searchbar.js Module not found: Can't resolve './node_modules/@material-ui/core/IconButton' in 'C:\Users\Ja\Desktop\ ...

Label positioning for checkboxes

Is there a way to display the checkbox label before the actual checkbox without using the "for" attribute in the label tag? I need to maintain the specific combination of the checkbox and label elements and cannot use nested labels or place other HTML elem ...

Tips for resolving the issue of "Text stays in original position while image changes in the background when hovering over the text."

I'm currently working on a website and I have a question regarding how to make text stay in position while hovering over it (inside a span), and at the same time, display an image in the background that allows the text to overlay it. HTML: <ht ...

CSS: Only one out of three <div>'s has the styles applied in JSFiddle

When working on my project, I encountered an issue while trying to add CSS styles to three <div> structures with unique IDs. Strangely, making small changes to unrelated CSS caused elements to go from being stylized to losing their style. If you com ...

Styling CSS for disabled nested elements

In a project I am currently working on, I've noticed that disabled items do not appear disabled enough. My initial plan was to easily address this issue with some CSS. Typically, adjusting the opacity is my go-to solution to achieve the desired effec ...

Issues with locating the fonts: React-slick paired with nextjs

Incorporating react-slick into a NextJs project has been quite seamless, however, I'm encountering issues with importing the necessary fonts from the CSS files. To address this snag, I've attempted the following steps: npm install slick-carouse ...

Jest in combination with Next/Dynamic is causing an error that is not supported

While working on testing for my component, I encountered an error involving the use of: ... const Rating = dynamic(import('components/Rating')); ... In addition, I am utilizing jest-next-dynamic: beforeAll(async () => { await preloadAll() ...