iFrames Messing Up Your Mobile Experience?

One thing about embedding content from Google Maps, YouTube, Vimeo, Wistia, Flickr and other sources is they have all switched to iFrames (didn’t iFrames die out in the 90’s?). I wish someone could tell me why they are going away from the future instead of embracing it; but for now we have to deal with it.

3 reasons this sucks…

  1. iFrames need the size specified in exact pixels in the iFrame tag itself, which breaks mobile layouts.
  2. iFrames can’t be universally fixed with CSS because each embedded object needs a different CSS entry. (IE: YouTube needs a 30px top padding, Google Maps needs 8px, etc.)
  3. iFrames are serious lame… since IE:6 lame.

Here are some ways you can fix these issues…

First lets create a div for all iFrames:

div class="mobilefix"

Now we’ll create few CSS entries to repair 90% of the damage:

.mobilefix {
    position: relative;
    height: 0;
    overflow: hidden;
.mobilefix iframe {
    width: 100%;
    height: 100%;
    position: absolute;
    left: 0;

This will fix everything but your individual viewports for each service. From here on out we will be adding only padding rules. So now we need to make rules for each service…

Google Maps

Create your secondary class:

div class="mobilefix gmaps"

Now create the CSS – Padding rules for Google Maps are as follows…

Look at the Height and Width in the iFrame code. Divide the Height by the Width and turn that into a percentage. Example:

iframe src="http://somewhe.re" height="800" width="1000"

In this example the equation looks like this: 800 ÷ 1000 = 0.8 (80%)
Now your padding looks like this:

.mobilefix.gmaps {
padding:0 0 80% 0;


Create your secondary class:

div class="mobilefix youtube16x9"
div class="mobilefix youtube4x3"

Now create the CSS – Padding rules for YouTube are as follows…

If a video is 16×9 then the padding looks like this:

.mobilefix.youtube16x9 {
padding:35px 0 56.25% 0;

If a video is 4×3 then the padding looks like this:

.mobilefix.youtube4x3 {
padding:35px 0 75% 0;

Etc… etc…

Like I said, every service will require different settings so tinker with Vimeo and others until they are right for your site. Good luck and if you find something that works better please Tweet me up.

5 thoughts on “iFrames Messing Up Your Mobile Experience?”

  1. Amoxicilina Quick Shipping Cheap Viagra 25 50 Mg Zenegra 100 [url=http://genericcial.com ]online pharmacy[/url] Best Price Net For Tadalis Sx 100 50 Mg No Rx Elocon Need Online Overseas Pharmacy Allergic Reactions To Zithromax

  2. Всем известно что одежда всегда подчеркивала индивидуальность человека. Каждый человека уникален. Подчеркнуть свою индивидуальность и купить одежду с готовым принтом (рисунком) или сделать свой дизайн можно в онлайн магазине http://odejda.shopicheck.net/

  3. Erfahrungen Cialis Ohne Rezept Buy Priligy In Uk Prezzo Kamagra Thailandia [url=http://tadalaf20mg.com ]viagra cialis[/url] Ezonline Pharmacy

  4. Viagra Vorzeitiger Samenerguss Cialis Andorra Sin Receta [url=http://howtogetvia.com]online pharmacy[/url] Amitriptyline No Rx Needed Cialis Achat En Ligne Canada

  5. Viagra Cialis Ecc Viagra Aus Deutschland Online Pyridium Without Perscription [url=http://howtogetvia.com]buy viagra online[/url] Buy Seroquel Without Prescription Achat Propecia Generique France Acyclovir 400 No Prescription Online

  6. Non Prescription Zyvox 600 Levitra Dosage Instructions [url=http://buyvarden.com]fastest levitra home delivery[/url] Fluoxetine 20 Mg No Prescription Cialis En 24 Horas

  7. achat viagra
    acheter cialis en france
    achat cialis generique
    [url=http://www.pharmacie-burthier.com/acheter-propecia.php]acheter propecia[/url]
    kamagra oral jelly 100mg
    viagra soft

  8. Worldwide Drugstore Worldwide Levaquin Price [url=http://viaonlineusa.com]viagra[/url] Puedo Tomar Viagra Siendo Hipertenso Meloxicam Ordering Viagra Online Canada

  9. Viagra Billig De Potenzmittel Viagra Original [url=http://bestviaonline.com]viagra[/url] Venta De Kamagra Online 40 Mg Levitra Pills On Line For Sale Viagra Tarif En Pharmacie

  10. Acheter Cialis En Suisse Il Prezzo Di Kamagra Cialis O Levitra Yahoo [url=http://ordercheapvia.com]viagra[/url] Propecia Effets Indesirables buy now tab isotretinoin isotret mastercard cod