I seem to have the opposite problem of everyone else with iframes and scrolling. I need the iframe (contains a youtube video) to NOT prevent scrolling of the main document. If I hover my mouse over it, the page won't scroll with the scroll wheel, and according to the latest chrome canary simulation of touch devices, I can't put my finger on the frame and scroll the main document either. Any way to stop this? My CSS is below:
.GalleryVideoWrapper {
position: relative;
padding-bottom: 56.25%; /* 16:9 */
padding-top: 25px;
height: 0;
width:95%;
margin:auto;
display:block;
}
.GalleryVideoWrapper iframe {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
}
The question is unclear, so I went into some detail below on various ways to achieve this effect and how it works.
If you don't need to interact with the iframe, the quick and dirty solution is to use pointer-events: none;. This will put the iframe on the page, and not allow it to scroll. However, it also does not allow you to click on it. This obviously won't work for a YouTube video, but it is important to know this is an option.
If you need to interact with the iframe, either to play a video or click a link, all you need to do is make sure the iframe is large enough to display the full contents. I'm unsure what specific problem OP was encountering as we don't have their HTML, but if you scroll and the iframe is not also trying to scroll, it will not prevent the parent from scrolling.
Basically, if you have your cursor over an iframe and you scroll, the iframe will receive the event first. If it does not need to scroll (either it can't or it has already reached the bottom of the iframe) the event will be propagated to the parent.
Finally, if you have an iframe that you need to be scrollable, but you want to scroll the parent while the cursor is on the iframe, you are out of luck. There is no way to inform the iframe that sometimes the user wants to scroll the whole page. This is simply how iframes work. You can either remove the cursor from the iframe to scroll, or scroll to the bottom of the iframe and continue down the page.
Using a YouTube video and the CSS in the question, I've included a demo for you to see. I also included two identical iframes that are scrollable and applied pointer-events: none; to one to demonstrate how it works.
.tall {
height: 1500px;
}
.GalleryVideoWrapper {
position: relative;
padding-bottom: 56.25%;
/* 16:9 */
padding-top: 25px;
height: 0;
width: 95%;
margin: auto;
display: block;
}
.GalleryVideoWrapper iframe {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
}
.scrolling-iframe {
margin-top: 35px;
display: inline-block;
height: 500px;
}
.no-scroll {
pointer-events: none;
}
<div class="tall">
<div class="GalleryVideoWrapper">
<iframe width="560" height="315" src="https://www.youtube.com/embed/hzB53YL78rE?rel=0" frameborder="0" allow="autoplay; encrypted-media" allowfullscreen></iframe>
</div>
<iframe class="scrolling-iframe" src="https://www.wikipedia.org/" frameborder="1"></iframe>
<iframe class="scrolling-iframe no-scroll" src="https://www.wikipedia.org/" frameborder="1"></iframe>
</div>
There used to be a scrolling attribute, but it is deprecated in html5. try this:
iframe {
overflow: hidden;
}
Don't forget to set your width and height somewhere!
If you wanted to try the iframe scrolling attribute, you could like this:
<iframe src="blah.html" width="200" height="200" scrolling="no"></iframe>
See working example here:
http://jsfiddle.net/4dt4zhwt/1/
I had horizontal-scrolling disabled like so:
html, body {
overflow-x: hidden
}
On a page with an iframe, if I tried to scroll the page vertically by touching and moving the iframe on Safari for iPad or iPhone, I couldn't.
This fixed it for me:
* {
-webkit-overflow-scrolling: touch
}
I don't know if you have found a way around this, but I had the same problem where all iframes (twitter, facebook and youtube) in my site was preventing the page itself from scrolling. After a lot of debugging and coffee, I found it, in my case at least, It was down to an overflow-x: hidden hidden I had set on a form element 4/5 parents up. Removing the overflow property fixed the issue for me, Hope it works for you!
I had an iframe in full width (with a Vimeo video inside) and it prevents the page scrolling.
Here is how I solved this issue :
<div class="video">
<iframe src="path-to-video"></iframe>
</div>
.video iframe {
pointer-events: none;
}
More info on this css property : https://developer.mozilla.org/en-US/docs/Web/CSS/pointer-events
Related
I have an iframe that embeds a pdf from a folder into the website. I want that iframe to cover the full page. I did width: 100%, and that covered the page for width, but if I do height: 100%, it doesn't even cover half of the page. How can I cover the full page with an iframe. One last thing, I have checked other answers and those don't help me, I have also tried to use embed and object tags but those don't work either.
The line of code:
<iframe src="/static/HowToPay.pdf" width="100%" height="1000px"></iframe>
use this CSS that set the height and cover the full page
body {
height: 100%;
margin: 0;
padding: 0;
overflow: hidden;
}
iframe {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
border: none;
}
<iframe src="/static/HowToPay.pdf" width="100%"></iframe>
We have property vh for get available window height.
<iframe src="/static/HowToPay.pdf" width="100%" height="1000vh"></iframe>
Did you try using vh and vw units within a style attribute?
<iframe src="/static/HowToPay.pdf" style="width: 100vw; height:100vh;"></iframe>
You can check the preview by running the snippet
Pervious answers offer ссs solution but I want to suggest Fullscreen API. Maybe will be usefull
https://developer.mozilla.org/en-US/docs/Web/API/Fullscreen_API
Easy way to use it is react-full-screen: https://www.npmjs.com/package/react-full-screen
function App() {
const handle = useFullScreenHandle();
return (
<div>
<button onClick={handle.enter}>
Enter fullscreen
</button>
<FullScreen handle={handle}>
Any fullscreen content here
</FullScreen>
</div>
);
}
UPDATE:
The idea behind my attempts so far has been focused on adjusting the iframe container and fixing it based on the intrinsic ratio of the Iframe so that it would then as it responds to change in proportion the contents would also change proportionally. This does not seem to work as some elements of the iframe remain fixed. I would really like to have a responsive Strava Iframe but for some reason cannot figure out to achieve this. I have made a Codepen Collection with current attempts thus far.
I have recently added a shortcode for embedding Strava iframes into my Hugo site (academic theme). On the desktop, devices the iframes render properly and appear to be responsive in browsers, yet on mobile devices, this isn't the case. The issue at hand can be seen on this webpage and my GitHub repo. I would be very grateful for any help in resolving this.
I have been trying multiple tried CSS tweaks and variation recommended on the Hugo forum and on other online sources.
Current Shortcode:
{{ if and (.Get "id") (.Get "hash") }}
<div class="responsive-object">
<iframe height='405' width='590' frameborder="0" allowtransparency='true' scrolling='no' src="https://www.strava.com/activities/{{ .Get "id" }}/embed/{{ .Get "hash" }}"></iframe>
</div>
{{ end }}
Current CSS:
.responsive-object iframe {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
}
.responsive-object {
position: relative;
padding-bottom: 67.5%;
height: 0;
margin: 10px 0;
overflow: hidden;
}```
Despite trying to make the iframe container responsive, the same result occurs where it seems responsive on desktop browsers yet not on mobile devices. I am unsure of how to proceed from this point, or if I am missing something.
Do you add <meta name="viewport" content="width=device-width, initial-scale=1.0">
To your <Head> ?
If yes imma gonna edit my post with the solution :)
EDIT
The best article I've found thus far on creating responsive iframes is How To Make Responsive Iframes - It's Easy!.
There are three salient points:
Set no attributes in the iframe opening tag, specifically not width and height
Put a div container around the iframe, and use CSS height: 0; and then padding-bottom: nn%; to give the container a height expressed as the height:width ratio as a percentage.
Style the div inline with -webkit-overflow-scrolling: touch and overflow: auto which are necessary to handle scrolling on mobile devices and are unstable in CSS.
This code works for me:
// HTML (in an embed block, not a code block)
<div class="iframe-container iframe-container-for-wxh-500x350" style="-webkit-overflow-scrolling: touch; overflow: auto;">
<iframe src="http://www.targetWebsiteURL.com"> <p style="font-size: 110%;"><em><strong>IFRAME: </strong> There is iframe content being displayed here but your browser version does not support iframes.</em> Please update your browser to its most recent version and try again.</p> </iframe>
</div>
// CSS
.iframe-container { position: relative; margin: 5px; height: 0; overflow: hidden; }
.iframe-container-for-wxh-500x350 {
padding: 25px 25px 70% 25px; /* padding-bottom = h/w as a % */
}
.iframe-container iframe {
position: absolute;
top: 0;
left: 0;
margin: 0;
padding: 0;
width: 100%;
height: 100%;
border: 1px inset #7a8b8b;
/* put following styles (necessary for overflow and
scrolling handling) in div container around iframe
because not stable in CSS
-webkit-overflow-scrolling: touch;
overflow: auto; */
} Use a separate class to style the padding-bottom so that, if you have more than one iframe and they are of differing wxh ratios, all you have to do is code a class for each and set padding-bottom to the different percentages.
I have a website grid that I am working on that shows new announcements and blog posts. I have one large column (col-sm-8 that spans 2/3 of the page) that I wish to have an introductory video (explaining/showcasing work) fitting.
I cannot seem to get a video to play nicely as the background for this (trying with YouTube embeds and a couple tutorials around the internet) I have created an image to explain this better below:
Any help, or just a shove in the right direction would be super appreciated!
Thanks
updated image for better scale:
You won't be able to get a youtube video, or any video to display nicely inside that region, so I suggest you resize the room you have allocated for the video to a better size for the video
Here is a responsive youtube embed code. The width and height were given by youtube. You need to come up with the rest of how you want your page to be.
/* Flexible iFrame */
.flexible-container {
position: relative;
padding-bottom: 56.25%;
padding-top: 30px;
height: 0;
overflow: hidden;
}
.flexible-container iframe,
.flexible-container object,
.flexible-container embed {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
}
<!-- Responsive iFrame -->
<div class="flexible-container">
<iframe width="560" height="315" src="https://www.youtube.com/embed/FSvNhxKJJyU" frameborder="0" allowfullscreen></iframe>
</div>
I set up a iframe like below
<iframe src="http://www.bbc.com/" frameborder="0" width="100%"></iframe>
CSS
iframe { overflow:hidden;
min-height:600px}
2 horizontal scrolling bars appear, 1 is at the iframe and the other is at the browser.
I want to get rid of the bar at iframe, I try
<iframe src="yahoo.com" scrolling="no" frameborder="0" width="100%"></iframe>
Then the scrolling bar at the iframe disappeared, and the problem is I cannot see anything at the bottom of BBC website!
I could increase min-height to greater number to cover entire length of BBC's page, but sometimes the page is very short and I'll get a huge white space at the bottom! So that increase the min-height is not a good practice.
How can I remove the scrolling bar at the iframe and use the browser's scrolling bar to navigate the page up and down?
Thank you!
There are different ways of doing this. There's jQuery solutions too. This will help you get started:
DEMO: http://jsbin.com/voqubo/1
CSS
body,html {padding:0;margin:0;height:100%;}
html {overflow-y:auto}
.embed-container {
position: relative;
height: 100%;
max-width: 100%;
}
.embed-container iframe,
.embed-container object,
.embed-container embed {
position: absolute;
top: 0;
left: 0;
bottom: 0;
width: 100%;
height: 100%;
}
HTML
<div class='embed-container'><iframe src='http://www.bbc.com/' style='border:0'></iframe></div>
<iframe
src="http://maroof.sa/Business/GetStamp?bid=203783"
style=" width: auto; height: 250px; overflow-y:hidden; "
frameborder="0"
seamless='seamless'
scrollable="no">
</iframe>
I'm currently trying to have an iframe fit the size of my screen, and any other user using it at different resolutions, except no matter what I try I'll either end up with the iframe being too small or the height being too large causing a double scroll bar. (The iframe and the page itself having scroll bars).
My objective is having the iframe fit only 85% width of the page (which works!), 100px from the top of the screen (also works), and then for the bottom to fit the edge of the bottom of my browser (that's where I'm stuck...)
HTML
<div id="maindiv" class="maindiv">
<iframe id="theiframe" class="iframeautowidth" seamless src="http://whateverdomain.com></iframe>
</div>
CSS:
.maindiv {
width: 85%;
top: 100px;
}
.iframeautowidth {
left: 0px;
top: 0px;
bottom: 0px;
width: 85%;
height: 100%;
border: 0
overflow: hidden;
display: block;
margin: 0;
float: left;
}
If it counts for anything, I have the latest jquery running on my page if it'll help. Thanks in advance!
Use the onload() event of your iframe and the onresize() event of the window to resize the iframe to the required size.
This Microsoft Support article explains it well.
FYI, in javascript screen.width & screen.height will give you the screen resolution.
If you had Fx4, a simple height: -moz-calc(100%-100px) would work a wonder. A pity this feature is introduced and supported so late in CSS3.
If the 100px top is for tabs navigating the iframe, there may be a workaround. Just fill up your iframe to 100% height and then put those tabs inside the iframes as another iframe with a fixed size. Or just resort to frameset.
Whether this works for you or not depends on your exact design, but hope that helps.