Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Horizontal scroll bar for iframe with content that has overflow-x: hidden

I am working on a landing page with width 760px and need to have an iframe with content (a flash demo) that is 980px wide. So I would need to have a horizontal scrollbar in order to view the entire content. However, no matter what I add as scrolling attributes (e.g. scrolling="auto/yes" etc), nothing happens - no horizontal scrollbar at all.

The page displayed in the iframe has the following command in the source code:

body {
    margin-left: 0px;
    margin-top: 0px;
    margin-right: 0px;
    margin-bottom: 0px;
    overflow-x: hidden;
}

As far as I understand it, this is the reason why there is no horizontal scrollbar in my iframe. Is there any workaround for that to get one?

like image 750
dtr Avatar asked Jun 14 '13 13:06

dtr


People also ask

What does the overflow-X mean in a scroll bar?

The overflow-x: scroll tells the web browser to clip the content if necessary. With this, the web browser displays scroll bars even if there is no clipped content. This means, if the content fits, you’ll observe a scroll bar that is not active.

How to use CSS overflow-X to scroll to see content?

With the horizontal scroll bars, you can scroll to see the content. All this is possible via a set of options that you can use with CSS overflow-x. This is the combination of overflow-x and its set of acceptable values.

What is the difference between a vertical and a horizontal scrollbar?

A vertical scrollbar counts as part of the width of the viewport, meaning you’ll have horizontal overflow. Horizontal overflow means you’re going to see a horizontal scrollbar on the page.

Should I use overflow-X or X visible when iframe content?

You should use overflow-x: visible. If your content is hosted elsewhere you will not be able to change due to cross domain issues. Imagine if you own a website and someone else wants to iFrame your website and make changes to it ( if you could change the overflow, you could literally change any styling and that would be a huge security leak ).


2 Answers

You should wrap the iframe in a containing div, applying the fixed-width to the container.

-

HTML

<div class="container">
    <iframe></iframe>
</div>

-

CSS

.container {
    width: 980px;
    height: auto;
    overflow: scroll;
    -webkit-overflow-scrolling: touch;
}
like image 146
blend Avatar answered Oct 15 '22 17:10

blend


Try changing the iFrames (body/child) overflow with javascript.

Something like:

window.onload=function(){
 document.getElementById(one).setStyles({ 'overflow': 'auto' });
};

maybe this, not sure which will get the body of the iframes contant:

window.onload=function(){
    var frame = document.getElementById('one'),
    frameDoc = frame.contentDocument || frame.contentWindow.document;
    frameDoc.setStyles({ 'overflow': 'auto' });
};
like image 32
Sergio Avatar answered Oct 15 '22 17:10

Sergio