Media Queries are working but the reverse to how they should - html

I have been trying for a while now to build a website that fixes in landscape mode on all devices smaller than a tablet however this has been a real headache. I have no idea what I am doing, or what I am doing wrong.
I think my media query is all wrong. I need the website to be in portrait mode to begin with but when viewed on a mobile device it fixes in landscape mode. After much tinkering, I have got it almost working but it is round the wrong way! on desktop it is in landscape mode and then on a mobile device it is in portrait mode! Its mocking me!lol
Here is a livelink of my attempt at getting this code to work. Could somebody please tell me why this code is not working? If you resize the browser you will see for yourself what is wrong.
Below is my code.
CSS
body, html {
margin: 0; padding: 0; height: 100%; overflow: hidden;
}
#content {
position:absolute;
left: 0;
right: 0;
bottom: 0;
top: 0px;
top: -15px;
min-height: 100%;
min-width: 100%;
}
html, body {
height: 100%;
min-height: 100%;
}
#media screen and (min-aspect-ratio: 2/1) {
body {
transform: rotate(90deg);
transform-origin: 50% 50%;
}
}
HTML
<div id="content">
<iframe src="//fast.wistia.net/embed/iframe/qnca9gdlv5?videoFoam=true" allowtransparency="true" frameborder="0" scrolling="no" class="wistia_embed" name="wistia_embed" allowfullscreen mozallowfullscreen webkitallowfullscreen oallowfullscreen msallowfullscreen width="640" height="388"></iframe><script src="//fast.wistia.net/assets/external/E-v1.js"> </script>
</div>
UPDATE
I have now corrected the rotation on a smaller resized desktop browser size however on mobile device there is still no rotation.

#media (max-width: 600px)
body {
transform: rotate(90deg);
transform-origin: 50% 50%;
}
Above css is changing the height and width of the body
ex: normally
-----40px-----
|
|
|
100px
|
|
|
is rotated by 90 deg and becomes
-----100px-----
|
|
|
40px
|
|
|
This css must be helpful
#media (max-width: 600px)
iframe {
transform: rotate(90deg);
/* transform-origin: 50% 50%; */
width: 100vw!important;
height: 100vh!important;
}

Related

How to manipulate the iframe css based on device size

I'm building this site and I'm having trouble manipulating the iframe based on size of the device. Basically, what I want is if the use is on a tablet the video is one size but for example if the user is on a mobile device like a cell phone it is other size recommended it be smaller that the tablet or desktop window size. if any of that makes since.
I've tried using div's but I may have implemented then wrong but from all I researched I doubt it. I also made an iframe in the CSS just for that device size and had a default iframe for all devices.
#media only screen and (max-device-width:480px){
/* styles for mobile browsers smaller than 480px; (iPhone) */
.center{
width: 300px;
height: 100px;
position: fixed;
left: 48.5%;
top: 44%;
transform: translate(-50%,-50%);
}
iframe {
border:none;
overflow:hidden;
width: 500px;
height: 250px;
frameborder="0";
allowTransparency="true";
allowFullScreen="true";
}
}
iframe {
border:none;
overflow:hidden;
width: 1000px;
height: 500px;
frameborder="0";
allowTransparency="true";
allowFullScreen="true";
}
<!DOCTYPE html>
<html lang="en">
<p align="center">
<!--stackoverflow trying to get the videos to shrink when using mobile devices. need to be done for "ipad" and cell phones from my knowledge computers are fine. -->
<iframe src="https://www.facebook.com/plugins/video.php?href=https%3A%2F%2Fwww.facebook.com%2Fwhereisslice%2Fvideos%2F1034464440067039%2F&show_text=0&width=560">
</iframe>
</p>
<p align="center">
<iframe src="https://www.facebook.com/plugins/video.php?href=https%3A%2F%2Fwww.facebook.com%2FTimeOutForMeInc%2Fvideos%2F526931557744638%2F&show_text=0&width=267" >
</iframe>
</p>
</body>
</html>
Try this:
.embed-container {
position: relative;
width: 100%;
height: 0;
padding-bottom: 56.27198%;
background-size: cover;
background-repeat: no-repeat;
background-position: center center;
}
.embed-container iframe {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%
}
<div class='embed-container'><iframe src="https://www.facebook.com/plugins/video.php?href=https%3A%2F%2Fwww.facebook.com%2Fwhereisslice%2Fvideos%2F1034464440067039%2F&show_text=0&width=560"></iframe></div>
more detail

How to fit iframe content with landscape orientation within device screen

I have a webpage that I have set to have a landscape orientation on mobile devices within which I have placed an iframe. My problem is I cant get the iframe to fit within the mobile device screen while in landscape orientation (full width and height matching the device screen). How may I be able to achieve this?
I am using CSS:
<style>
body, html {
margin: 0;
padding: 0;
height: 100%;
overflow: hidden;
}
#content {
position:absolute;
left: 0;
right: 0;
bottom: 0;
top: 0
}
#content iframe{
width:100%;
height:100%;
border:none;
}
#media screen and (orientation:portrait) {
body {
-webkit-transform: rotate(-90deg);
-webkit-transform-origin: 50% 50%;
transform: rotate(-90deg);
transform-origin: 50% 50%;
}
}
</style>
And HTML:
<div id="content">
<iframe src="localhost/iframeTest/index.php"
allowtransparency="true" frameborder="0" scrolling="no"
class="wistia_embed" name="wistia_embed" allowfullscreen
mozallowfullscreen webkitallowfullscreen oallowfullscreen
msallowfullscreen width="100%" height="100%"></iframe>
</div>
As I stated in my comment the problem is, that the size is calculated before you rotate it. To fix this you can use vh, vw sizes and just just vw for height and vh for width. Then you can rotate and translate it back into viewport.
body {
display: block;
width: 100vh;
height: 100vw;
transform: translateY(100vh) rotate(-90deg);
transform-origin: top left;
}
Check this codepen to see it working: https://codepen.io/pixelarbeit/pen/rpLbNe

Can anyone tell me why this isn't responsive?

working on a site and this animation isn't responsive. I've changed the width to 100% and added css. Can anyone help me out? here's the site link..
armani.globerunnerstaging.com
Here's my html and css
<div class="video-container">
<iframesrc="https://content.understand.com/hair-loss-dallas.player?PresentationID=4e9e3cad-0f79-49c0-a204-8193a6a4264b&CatalogID=3fcc6564-3065-4b92-a116-8a692f3572d5" width="100%" height="557" frameborder="0" scrolling="no">
</iframe>
</div>
.video-container {
position: relative;
padding-bottom: 65.25%;
padding-top: 30px;
height: 0;
overflow: auto;
-webkit-overflow-scrolling:touch;
border: solid black 1px;
}
.video-container iframe {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
}
First thing, an iFrame can't have a percentage unit for the width attribute :
width="100%" height="557" frameborder="0"
It should be pixels. For example:
width="701" or width="701px"
But your main problem is that player displaying within your iFrame has a container with a fixed width of 701px.
div#container
{
background: #FFF;
margin: 0 auto;
padding: 0;
width: 701px;
height: 557px;
}
This means even if your iFrame has a smaller width than 701px, its content won't shrink below that limit.
Unless you can edit the CSS of the page inside the iFrame, there is no way to change this behaviour.
UPDATE:
Maybe if you try playing around with CSS Scale transform you could make it work for mobile.
.video-container iframe{
-ms-transform-origin: 0 0; /* IE 9 */
-webkit-transform-origin: 0 0; /* Chrome, Safari, Opera */
transform-origin: 0 0;
-ms-transform: scale(0.75); /* IE 9 */
-webkit-transform: scale(0.75); /* Safari */
transform: scale(0.75);
}
Make sure you correct the iframe property width:"100%" first.
Here is an example : http://codepen.io/Rubecula/pen/CtKdH

Force iframe YouTube video to center fit and full cover the screen in the background using HTML5 CSS3

How do you force HTML5 iframe YouTube video to center fit, cover the full-screen window background using CSS3 HTML eventually Java?
As for example "paypal.it" home page background or "unity3d.com/5" top video, has as iframe youtube video.
The iframe covers the full screen (zooming) and covers all the width and height when re-size the window.
It re-size maintaining the 100% min-width zooming the height or the 100% min-height zooming the width.
How is this effect achieve using iframe HTML5 and CSS3?
Code Example HTML5
<div class="video" style="opacity: 1;">
<iframe src="http://www.youtube.com/embed/AddHereVideoId?autoplay=1&html5=1" frameborder="0" style="height: 720px;">
</iframe>
</div>
Code CSS3 HTML eventually Java help would be appreciated.
Full-size YouTube video, all aspect ratios, CSS only
TL:DR - working fiddle
As an update/improvement to #Hinrich's answer, I have created a CSS-only scaler that works for ALL aspect ratios - even the extremes. Rather than over-compensating the width to fit most screen sizes, the iframe is set using vw and vh and offset using the CSS transform property (which offsets relative to the element, not the parent).
Most browsers (IE9+ and all evergreen browsers AFAIK) support the vw and vh units, as well as transforms, so this should work for pretty much all browsers with no JavaScript required.
.video-background {
position: relative;
overflow: hidden;
width: 100vw;
height: 100vh;
}
.video-background iframe {
position: absolute;
top: 50%;
left: 50%;
width: 100vw;
height: 100vh;
transform: translate(-50%, -50%);
}
#media (min-aspect-ratio: 16/9) {
.video-background iframe {
/* height = 100 * (9 / 16) = 56.25 */
height: 56.25vw;
}
}
#media (max-aspect-ratio: 16/9) {
.video-background iframe {
/* width = 100 / (9 / 16) = 177.777777 */
width: 177.78vh;
}
}
<div class="video-background">
<iframe src="https://www.youtube.com/embed/biWk-QLWY7U?controls=0&showinfo=0&rel=0&autoplay=1&loop=1&mute=1" frameborder="0" allowfullscreen></iframe>
</div>
With CSS variables
For those using CSS variables, you can also do this (fiddle), which lets you arbitrarily reuse the sizes for multiple classnames:
:root {
--video-width: 100vw;
--video-height: 100vh;
}
#media (min-aspect-ratio: 16/9) {
:root {
--video-height: 56.25vw;
}
}
#media (max-aspect-ratio: 16/9) {
:root {
--video-width: 177.78vh;
}
}
.video-background {
position: relative;
overflow: hidden;
width: 100vw;
height: 100vh;
}
.video-background iframe {
position: absolute;
top: 50%;
left: 50%;
width: var(--video-width);
height: var(--video-height);
transform: translate(-50%, -50%);
}
For a real full screen solution, this can be achieved like this:
HTML
<div class="video-background">
<div class="video-foreground">
<iframe src="https://www.youtube.com/embed/I4agXcHLySs?controls=0&showinfo=0&rel=0&autoplay=1&loop=1&mute=1" frameborder="0" allowfullscreen></iframe>
</div>
</div>
CSS
* { box-sizing: border-box; }
.video-background {
background: #000;
position: fixed;
top: 0; right: 0; bottom: 0; left: 0;
z-index: -99;
}
.video-foreground,
.video-background iframe {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
pointer-events: none;
}
#media (min-aspect-ratio: 16/9) {
.video-foreground { height: 300%; top: -100%; }
}
#media (max-aspect-ratio: 16/9) {
.video-foreground { width: 300%; left: -100%; }
}
#media all and (max-width: 600px) {
.vid-info { width: 50%; padding: .5rem; }
.vid-info h1 { margin-bottom: .2rem; }
}
#media all and (max-width: 500px) {
.vid-info .acronym { display: none; }
}
It is not perfect, e.g. it does not work well with extreme aspect ratios of the container, but is doing a great job in most situations. Here is a working example:
https://codepen.io/hnrchrdl/pen/YzPwjBV
Edit: Check Oliver's answer, he seems to have an improved version of this solution.
I think this is what you're trying to achieve:
.video-wrapper {position: relative; padding-bottom: 56.25%; /* 16:9 */ padding-top: 25px;}
.video-wrapper iframe {position: absolute; top: 0; left: 0; width: 100%; height: 100%;}
<div class="video-wrapper">
<iframe src="http://www.youtube.com/embed/AddHereVideoId?autoplay=1&html5=1" frameborder="0" allowfullscreen></iframe>
</div>
This will give you a video that fills the container that it is in and will automatically scale the height too.
I originally found this solution here: https://css-tricks.com/NetMag/FluidWidthVideo/Article-FluidWidthVideo.php

Trying to get a large centered background image to work in mobile browser without being distorted

So i used the method in this article: http://css-tricks.com/perfect-full-page-background-image/
here's the code i have:
css:
#bg {
height: auto;
left: 0;
min-height: 100%;
min-width: 1024px;
position: fixed;
top: 0;
z-index: -1;
width: 100%;
}
#media only screen
and (max-width : 1024px) {
#bg {
left: 50%;
margin-left: -512px;
}
html:
<img id="bg" src="breakfast.jpg">
this works for the most part except the height/width ratio in the mobile browser is messed up.
Edit you're media query like this:
#media only screen and (max-width : 1024px) {
#bg {
left: 50%;
margin-left: -512px;
min-height: 1px;
height: auto;
}
}
Going to answer my own question. In order for the background image to fill the page in mobile browser while maintaining the correct aspect ratio one must add a media query with a re-sized image for portrait / landscape mode.
Figured out the fix:
Needed to add
html {
height: 100%;
}