1

Suppose I have very simple markup. I want iframe to take 100% of screen height but setting 100vh still adding scrollbar.

* {
  box-sizing: border-box;
}

body {
  margin: 0;
}

iframe {
  width: 100%;
  height: 100vh;
}
<iframe scr="https://en.wikipedia.org/wiki/Main_Page"></iframe>

But I see vertical scrollbar. Why is it showing and how to get rid of it?

Vadim Ovchinnikov
  • 13,327
  • 5
  • 62
  • 90

5 Answers5

6

You can simply fix this issue , Just add a float:left or display:block to the iframe

* {
  box-sizing: border-box;
}

body {
  margin: 0;
}

iframe {
  width: 100%;
  height: 100vh;
  padding:0;
  display:block;
}
<iframe scr="https://en.wikipedia.org/wiki/Main_Page"></iframe>
Jishnu V S
  • 8,164
  • 7
  • 27
  • 57
2

iframe has default display: inline so changing display property to something like display: block fixes this issue.

Also if iframe is flex item (child of flex-container, adding display: flex for body in current case will make iframe a flex-item) it will also help because it will be implicitly blockified.

Vadim Ovchinnikov
  • 13,327
  • 5
  • 62
  • 90
1

Assuming you want it to be full screen:

  1. Add display:block;
  2. Add the 'allowfullscreen' attribute.

Change to:

<iframe scr="https://en.wikipedia.org/wiki/Main_Page" allowfullscreen></iframe>
Jishnu V S
  • 8,164
  • 7
  • 27
  • 57
Leah
  • 336
  • 4
  • 14
0

Please check this.

* {
  box-sizing: border-box;
}

body {
  margin: 0;
}

iframe {
  width: 100%;
}
<iframe scr="https://en.wikipedia.org/wiki/Main_Page"></iframe>
chander shekhar
  • 425
  • 2
  • 10
-1

You cannot control the height of a cross domain content. If you try to upload an outsource html page into your html page, you cannot control the content size, only if you have access to the source content or server. Then you can add some JS and you'll not have extra scrolling.

https://github.com/davidjbradshaw/iframe-resizer

DanielaB67
  • 446
  • 6
  • 14