Make an Iframe responsive in height - html

I have a type of "store-locator" on https://www.carcarenederland.nl/detailer-zoeker/detailer-zoeker/
Due to demand, I want to put this in an iFrame so other websites can display this form on their page. Giving them the possibility to easily add my "store-locator" to their website.
At the moment I have:
<iframe name="De Detailer-Zoeker" src="https://www.carcarenederland.nl/detailer-zoeker/detailer-zoeker/" scrolling="no" style="width:100%;height:734px;border:none;overflow:hidden;"></iframe>
Which works, as long as the screen doesn't get to small.
However, the form is responsive, and if the screen becomes very small, the row with addresses goes underneath the big map. Making the complete form a lot higher then on normal view. (normally it would be 734px high, in responsive design it is 1388px high)
This would mean that I need an iFrame that stretches just as the content stretches. (if that is at all possible)
If that is not possible, would it be possible to put something like this in the style? (it doesn't work if I use it in my example, but maybe I'm doing it wrong?)
Style="#media (max-width:675px){iframe{height:1388px}}"
The goal of this piece of CSS would be to change the height of the iFrame when the width goes below 675px.
Another solution is welcome, as long as it works :). Because I'm displaying the code on my website, so other can just copy-paste it, it would be beneficial if the code is kept reasonably simple.
It seems 1 person has removed their comment, even though the solution was pretty good. Essentially, this was the code that I ended up with thanks to him:
<style>#iframe {width:100%;height:740px;border:none;overflow:hidden;}
#media (max-width:675px){#iframe{height:1588px;}}
</style>
<iframe src="https://www.carcarenederland.nl/detailer-zoeker/detailer-zoeker/
"frameborder="0" id="iframe" name="De Detailer-Zoeker"></iframe>
The only problem is that this only responds to the size of the browser-screen, and not the container in which the iFrame is placed. This means that the iFrame will behave differently on a website with sidebars, then one without sidebars.

You have a couple ways of dealing with this issue.
1. Breakpoints
Add a breakpoint the moment the list of address goes underneath the map. You can use CSS Media Queries to acheive this.
#media (max-width: 675px) {
iframe {
height: 1388px;
}
}
2. Javascript
Use Javascript to read the width of the screen and then change the height of the iframe accordingly.
Adjust width height of iframe to fit with content in it
Make iframe automatically adjust height according to the contents without using scrollbar?
However the Javascript method has drawbacks.

It works fine when you define all CSS in an external style sheet.
iframe {
width: 100%;
height: 734px;
border: none;
overflow: hidden;
}
#media (max-width:675px) {
iframe {
height: 1388px
}
}
<iframe name="De Detailer-Zoeker" src="https://www.carcarenederland.nl/detailer-zoeker/detailer-zoeker/" scrolling="no"></iframe>

code for responsive iframe
<style type="text/css">
iframe {
width:100%;
height:734px;
border:none;
overflow:hidden;
}
#media screen and (max-width:1166px) {
iframe {
width:100%;
height:734px;
}
}
#media screen and (max-width:1024px) {
iframe {
width:100%;
height:734px;
}
}
#media screen and (max-width:980px) {
iframe {
width:100%;
height:734px;
}
}
#media screen and (max-width:767px) {
iframe {
width:100%;
height:1388px;
}
}
#media screen and (max-width:599px) {
iframe {
width:100%;
height:1388px;
}
}
#media screen and (max-width:479px) {
iframe {
width:100%;
height:1388px;
}
}
#media screen and (max-width:374px) {
iframe {
width:100%;
height:1388px;
}
}
</style>
<iframe name="De Detailer-Zoeker" src="https://www.carcarenederland.nl/detailer-zoeker/detailer-zoeker/" scrolling="no"></iframe>

You are almost there, you just need to adjust your media query a bit.
You say you want other websites to include your iframe without having to edit their CSS file. You can do that as followed:
Tell the client to place the following CSS in their <head> section.
<style>
#media screen and (max-width:675px){
#iframe{
min-height:1388px;
overflow-y: scroll !important;
}
}
</style>
Then, tell them to put the iframe between the <body> tags where they want to display the iframe.
<iframe id="iframe" name="De Detailer-Zoeker" src="https://www.carcarenederland.nl/detailer-zoeker/detailer-zoeker/" scrolling="no" style="width:100%;height:734px;border:none;overflow:hidden;"></iframe>
Look at this working fiddle:
Hope this helped!

Related

pdf in iframe only first page on iphone/ipad

I am trying to display the content of a pdf with an iframe. Everything is working fine on a normal computer. However on mobile devices of apple (IPhone/IPad) only the first page of the pdf is getting displayed.
Here is my code where I already added some scrolling styles because I thought it was a problem related to the scrolling, but If I make the iframe very small it is possible to scroll! However the problem is still the same...only the first page is visible.
<div class="scroll-wrapper">
<iframe height="260" width="280" src="info.pdf"> </iframe>
</div>
.scroll-wrapper {
overflow-y:scroll;
-webkit-overflow-scrolling:touch;
width: 400px;
height: 300px;
}
Maybe you should try using viewport.
Or using responsive breakpoints
#media screen and (max-width:512px) {
size:
}
#media screen and (max-width:512px) {
.scroll-wrapper{
overflow-y:scroll;
-webkit-overflow-scrolling:touch;
width: 400px;enter code here
height: 300px;
}
}
try this
iframe {
width: 100% !important;
}

How can I change the height of an iframe for different screen sizes?

I have a form that is an iframe.
The code is below with a # for what the iframe is.
On desktop I need the frame to be 292px in height to match the design.
On tablet it needs to have height="180"
On mobile height="292"
I have tried making the height 100% and changing the size of the holding the iframe but the iframe is too short and cuts off the bottom of the form
Can I do adjust the height of an iframe for different viewports?
<iframe src="#" width="100%" height="292" type="text/html" frameborder="0" allowTransparency="true" style="border: 0"></iframe>
Create a file called responsive.css and add it to your styles. It's good practice to add this file after other css files as you want these rules to take priority over your other css rules.
This would be the content of your responsive.css
/* Style for Extra Large Screen */
#media (max-width:1199px) {
iframe {
height: 292px;
}
}
/* Style for Large Screen */
#media (max-width:991px) {
iframe {
height: 292px;
}
}
/* Style for Medium Screen */
#media (max-width:767px) {
iframe {
height: 180px;
}
}
/* Style for Small Screen */
#media (max-width:575px) {
iframe {
height: /* whatever height you want for mobile */
}
}
Depending on your screen size, the correct section of responsive.css will be used in your website. For example, if you are on mobile, then #media (max-width:575px) will be selected. Just put your required height in here.

How to override CSS according to screen width

Below i have written some css to ensure my "sections" use up the whole screen when navigated to, however when the browser window is made smaller or accessed on mobile the content is lost as it does not fit.
I have made a media query to counter the first bit of css but I'm not sure what to set it as to counter it.
#media screen and (max-width: 550px){
section.full {height: auto;}
section.contactfull {height: auto; margin-top:0%;}
}
section.full {height: 100vh;}
section.contactfull {
height: 70vh;
margin-top: 10%;
}
I think you will have to leave things flow down. No matter what device people use, you can restrict only one of the 2 dimensions, but not both of them.
Just adjust things horizontally and let them flow vertically.
If you want the section to take up the whole screen, you can use the following:
section {
display: fixed;
width:100%;
height:100%;
}
I think the reason vh is failing you is because at a smaller resolution, the horizontal scroll bar shows up on your page, and vh doesn't take it into account.

Responsive twitter height

I'm attempting to make the twitter embed widget responsive, to do this I need to make the height a percentage. As it stands I am using the default twitter embed from here
That says I can set the height in advanced customization, however that is only for pixels.
Here is my code;
HTML:
<div id="body-twitterFeed">
<a class="twitter-timeline" href="https://twitter.com/ARavinMadMonkey" data-widget-id="347000705833398272" height="700" data-chrome="noscrollbar transparent" border-color="#DBDBDB">Tweets by #ARavinMadMonkey</a>
<script>!function(d,s,id){var js,fjs=d.getElementsByTagName(s)[0],p=/^http:/.test(d.location)?'http':'https';if(!d.getElementById(id)){js=d.createElement(s);js.id=id;js.src=p+"://platform.twitter.com/widgets.js";fjs.parentNode.insertBefore(js,fjs);}}(document,"script","twitter-wjs");</script>
</div>
CSS:
#body-twitterFeed{
height: 80%;
padding: 5px 10px 5px 10px;
overflow: hide;
}
I attempted to use overflow:hide; to hide anything outside of the body-twitterFeed div, but it just simply doesn't work.
If anyone could help me work out a way to make the height of the twitter feed responsive, it would help a lot!
Thanks in advance.
PS. I am not using bootstrap or anything.
You need to set the height of the class .twitterTimeline.
Theoretically this should be easy: just set it as a proportion of the window height (e.g., 40vh). Trouble is that mobile Safari has trouble rendering vh properly.
Instead, I think you need to use media queries to set the height, as in the following example:
#media screen and (max-height: 30rem) {
.twitter-timeline {
height: 15rem;
}
}
#media screen and (min-height: 30rem) {
.twitter-timeline {
height: 30rem;
}
}
If you want to see more about media queries and what all they can do, try reading this.

Why does vertically centering a web page cut off on small monitors and mobile devices?

Right now I have a website which has an overall height set at 750px. I have it vertically centered using the position absolute and negative margin method. It works great apart from one problem.
If I try use it on a lower-res monitor or mobile device it cuts the top of the page.
Here is my code
HTML
<body>
<div class="content">
CONTENT IS HERE
</div>
</body>
CSS
.content {
position:absolute;
top:50%;
height:750px;
margin-top:-375px; /* Half of 750px */
}
I tried using overflow:scroll; on the body tag but I understand that it doesn't work, I didn't expect it to. I am totally stumped! Is there any suggestion?
You can overwrite it with a mediaquery on small screens:
.content {
position:absolute;
top:50%;
height:750px;
margin-top:-375px;
}
#media only screen and (max-height: 750px){
.content {
top:0;
margin-top:0;
}
}
Actually, this is a graceful degradation method, but if you're designing for mobile you probably want to approach in a progressive enhancement way. In that case, it becomes:
.content {
height:750px;
}
#media only screen and (min-height: 751px){
.content {
position:absolute;
top:50%;
margin-top:-375px;
}
}
Speaking about compatibility, the only keyword after #media prevent older browsers from rendering the rules contained.
To reach (almost) full compatibility, you can use this very useful plugin: respond.js
As far as scrolling goes,
overflow:auto;
is probably what you want as that will cause the scroll bars to appear.
This overall problem you are having is why sizing is almost always done relatively. Either relative with percentages, or relative with javascript to determine the clients viewable area.
Also note that,
.class {
does not match the definition you have class="content". This is a logical error and should be replaced with
.content {
Try something like
margin-top:-25%;
So that it will be the same at any browser window height
And the same for the height, use a combination of percentages, not pixels.