1

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>
Hooman Bahreini
  • 14,480
  • 11
  • 70
  • 137
DumbDevGirl42069
  • 891
  • 5
  • 18
  • 47

1 Answers1

2

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.

Hooman Bahreini
  • 14,480
  • 11
  • 70
  • 137
  • This works great thank you for your detailed explanation. I would also like to add that this will only work if the iframe doesn't have a height=" " in the html as this overrides styles from the responsive.css stylesheet – DumbDevGirl42069 Mar 22 '18 at 02:31
  • 1
    Thanks Jessica,that's true. Though it is not a good practice to use inline css at the first place: see here https://speckyboy.com/good-bad-css-practices/ or here: https://stackoverflow.com/questions/2612483/whats-so-bad-about-in-line-css – Hooman Bahreini Mar 22 '18 at 02:39