Ways to ensure the height of an element is consistent across various device modes

Testing out the angular-youtube-embed plugin with Chrome Dev tools' device mode, I wanted to see how the YouTube element would appear.

Here's my code:

<div class="fixed-header my-video">
    <div style="padding:0px;">
        <youtube-video  video-url='vm.videoUrl' player-vars="{controls : 0}" 
           player-width="'100%'" player-height="'180px;'"></youtube-video> 
    </div>
</div>

My CSS:

.my-video
{
  height:180px;
  width:100%;
  position:absolute;
  background:grey;
  color:white;
  text-align:center;
  padding:0px;
}

and

.fixed-header{
 margin-top:43px;
}

When testing on an iPhone5 in device mode, everything looks good. But on an iPhone6, the video appears smaller even though the height is set to 180px. Setting it to around 31% of the viewport height (around 207px) seems to work better for iPhone6.

I tried using '31vh' for the height in my CSS and passed it to the angular-youtube-embed component as well. However, the element's height ended up being 150px instead of 31% of the viewport height.

So, my question is, how can I make the height of the angular-youtube-embed element dynamically adjust to 31% of the viewport size?

Answer №1

implement media query for responsive design

@media (max-width: 1200px) {
  .video-container {
    height:360px;
    width:100%;
  }
}

@media (max-width: 600px) {
  .video-container {
    height:180px;
    width:100%;
  }
}

Answer №2

A big shoutout to all the amazing individuals who offered their assistance.

After much trial and error, I finally managed to achieve success by implementing the following code:

 vm.height = (0.5625 * $window.innerWidth);

This simple solution effectively maintains the aspect ratio of 16:9 while keeping the width at 100%.

Answer №3

Consider utilizing height as a percentage instead of in pixels. Using percentages allows the component to adjust based on the relative size of the window, offering more flexibility compared to specific pixel dimensions.

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

Protractor struggles with locating elements within separate div elements on a single webpage

I'm currently developing a test script using Protractor for the specified web page. https://i.stack.imgur.com/CrMzG.jpg My goal was to target each field using their unique locator. Below is the test script I have created. describe('Protractor ...

Using a nested loop in Javascript to fetch JSON data

My goal is to display Categories and their corresponding subcategories in a specific order. However, my current method of using loops within loops is not producing the desired outcome: Category(Mobile) Category(Laptop) Subcategory(Iphone4) Subcategory(Iph ...

Having trouble loading a CSS file in CodeIgniter?

I've added a link to my header.php and despite trying various solutions from stackoverflow, it still isn't working for me. Can someone please help? Thank you in advance :) Here's my folder structure: Main Folder: ci_attl - application ...

The issue of Vue.js template errors within inline code

I am experimenting with using inline-template in combination with vue.js 2.0. This usage is within the context of Laravel blade 5.4: <users inline-template> <tbody> @foreach($users as $user) <tr> ...

Secure an input field for exclusive attention. React

How can I lock the focus of my input field? I attempted using the following code: onBlur={this.click()} However, it was not successful. What is the correct way to accomplish this? ...

Update Jquery Dialog's Button After Making an Ajax Request

I am facing an issue with my dialog window that contains some confirmation elements following a form submission: $('#newUserDialog').dialog({ autoOpen: false, width: 600, modal: true, resizable: false, cl ...

Using Angular 1.4 - How to utilize a single controller with $routeProvider

How can I use the same controller on both full and mobile views using $routeProvider? The code below does not work as expected. What am I missing? Alternatively, is it possible to have the same controller but with different templateUrl based on the user a ...

Having trouble getting ng-click to function properly in TypeScript

I've been struggling to execute a function within a click function on my HTML page. I have added all the TypeScript definition files from NuGet, but something seems to be going wrong as my Click Function is not functioning properly. Strangely, there a ...

How to dynamically add table rows and cells with JavaScript using a single selection input

I am working on a project that involves a selection input with around 5 options. Additionally, there is an empty table that follows this format: <table> <tr> <td>X (for deletion)</td> <td>Option name</td> ...

Testing AngularJS 1.5 controller state changes using unit testing with UI-Router

My AngularJS 1.5 application utilizes the UI-Router for state management, but I'm encountering difficulties with unit testing state changes within the controller. Here is the snippet of logic in my controller: CostingsController = ($scope, $http, $s ...

Using Node.js, we can create a program that makes repetitive calls to the same API in a

My task involves making recursive API calls using request promise. After receiving the results from the API, I need to write them into an excel file. Below is a sample response from the API: { "totalRecords": 9524, "size": 20, "currentPage": 1, "totalPage ...

Error in Node.js (NPM Error)

Recently, I purchased a VPS running Ubuntu 14.4 and successfully installed Node.js 1.4. However, when attempting to run my script (node tradebot.js), I encountered the following error message! :-/ module.js:327 throw err; ^ Error: Cannot find ...

Adding external JavaScript files that rely on jQuery to a ReactJS project

As a beginner in web development, I have a question regarding importing external JavaScript files in ReactJS. I currently have the following imports: import $ from 'jquery'; window.jQuery = $; window.$ = $; global.jQuery = $; import './asse ...

Express.js Passport.js throws an error when req.user is not defined

The middleware function below is unable to access req.user or determine if the user is logged in after they log in. I have confirmed that passport.serializeUser is successful after logging in and that req is defined when accessed from the middleware funct ...

No matter how many times I modified the code in the ReactDOM.render() method within my index.js file, the end result remained unchanged

When I ran npx create-react-app my-app, and then proceeded to cd my-app and npm start, a browser opened on localhost:3000. While looking at the index.js file, I noticed that the ReactDOM.render() method included the following code: ReactDOM.render( <Rea ...

Explore the differences between user input and JavaScript

There seems to be an issue with the second output result. var compareNumber = 3; // Code will be tested with: 3, 8, 42 var userNumber = '3'; // Code will be tested with: '3' 8, 'Hi' /* Enter your answer here*/ if (userNum ...

Manipulating events through adjusting values of a JQuery-UI range-slider

My range-slider's values are being set with the code: $('...').slider( 'values', [ 0, 10000 ] );. However, I am facing an issue where this line triggers the change( event, ui ) event twice. Is there a way to ensure it only triggers ...

shifting the length of o to the right by zero with the

While exploring the polyfill function for Array.includes, I stumbled upon the following lines of code: // 2. Let len be ? ToLength(? Get(O, "length")). var len = o.length >>> 0; // 4. Let n be ? ToInteger(fromIndex). // (If fromIndex is undef ...

How can scope binding be reversed in AngularJS when implementing transclusion?

Utilizing transclude in directives proves to be extremely beneficial when you want the scope of your controller to be linked to the HTML being passed in. But how can you achieve the opposite? (accessing the directive's scope from the controller) Her ...

The different types of property 'cacheLocation' do not match

I have been working on updating an old React app from JavaScript to Typescript gradually. I started by migrating the configuration file, but encountered an error when renaming it to .TS. Here is the error message: /Users/xx/yy/lulo/src/adalConfig.ts (13, ...