10

I have an iframe.

I need a cross-browser solution to ensure that only the vertical scrollbar is visible, regardless of the width of the iframe's contents.

My solution already has a dependency on jQuery, so if this is not possible with only CSS I am open to jQuery solutions.

How can I do this?

Knu
  • 14,806
  • 5
  • 56
  • 89
smartcaveman
  • 41,281
  • 29
  • 127
  • 212

4 Answers4

11

You can adjust scrollbars of an iframe or any element with following css code:

iframe{ width:500px; height: 500px; overflow-x: hidden; overflow-y: scroll }
HasanG
  • 12,734
  • 29
  • 100
  • 154
6

In order to show only the vertical scrollbar in an iframe, you specify the width of the iframe to be greater than the page's width inside the iframe.

<iframe src="#" width="--" height="250">
  <p>Your browser does not support iframes.</p>
</iframe>

Or try this:

<style>
    #scroll-box {
        background:#e6e6e6;
        width:150px;
        height: 150px;
        padding:15px;
        overflow-y: scroll
    }
</style>

<iframe id="scroll-box">
    <h3>Lorem ipsum dolor sit amet</h3>     
    <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit...</p>
</iframe>   
HasanG
  • 12,734
  • 29
  • 100
  • 154
mgreen
  • 69
  • 1
  • 1
    Great solution to override the scrolling attribute and prevent horizontal bar. It does however show a greyed out scrollbar when the content fits. – Stuart Dobson Sep 05 '12 at 00:05
2

Nesting...

Put the <div> on the page that is loading within the <iframe> and you can control the scrolls.

<iframe  scrolling="no" height="400" width="600" >
<div id="addcontent" style='width:600px;overflow-y:scroll;overflow-x:hidden;height:400px;position:relative;top:0px;left:0px;'>
</div>
</iframe>
Gary Hayes
  • 1,728
  • 1
  • 15
  • 23
1

this works for me (even on safari too):

<iframe src="http://url/file.html" frameborder="0" style="overflow-y:scroll !important; overflow-x:hidden !important; overflow:hidden;height:100%;width:100%;" scrolling="yes"></iframe>

Or you can do this too:

CSS

iframe {
    overflow-y:scroll !important;
    overflow-x:hidden !important;
    overflow:hidden;
    height:100%; /* optional */
    width:100%; /* optional */
    border:none; /* optional */
}

HTML

<iframe src="http://url/file.html" scrolling="yes"></iframe>

*src (http://url/file.html), needs to point to a valid URL and HTML file.

K-G
  • 2,799
  • 4
  • 26
  • 42