css - 如何让iframe在主窗口水平滚动时改变位置

标签 css iframe scroll horizontal-scrolling

我的 UI 中的 iframe 元素有问题。当我调整屏幕大小时(使其变小)并开始使用水平滚动条滚动时,它不会滚动到 iframe,但 iframe 保持在相同的固定位置并且无法看到它。

Example

和 HTML:

<div id="top-element">Some div that has greater width than the inner div</div>
<div id="iframe-wrapper">
    <iframe src="http://www.apple.com/" scrolling="auto"></iframe>
</div>

最佳答案

您必须通过添加 left:50% 和 margin-left iframe 宽度的一半使其居中,例如:

div#iframe-wrapper {
    position: fixed;
    left: 50%;
    margin-left:-150px; /* this must be the half of the iframe's width */

 }

您可以通过添加 top:50% 和 margin-top:(减去 iframe 高度的一半)来垂直居中。关于定位,您不需要底部或“div#iframe-wrapper iframe”

关于css - 如何让iframe在主窗口水平滚动时改变位置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20581729/

相关文章:

css - 带有 Internet Explorer 的自定义元素符号上的工件

javascript - 浏览器仅应用来自第一个动态添加的样式元素的 css

javascript - 使用 iframe 呈现用户提供的 html 代码

iframe - 如何正确转义过滤后的内容变量?

html - CSS组合relative+fixed无跳转效果

jquery - 如何在页面加载前运行加载动画

javascript - Firefox 中的 NS_ERROR_FAILURE 在隐藏的 iframe 中设置 Canvas 字体

jquery - 仅当用户一直向上滚动时显示 div

jquery - 在自定义 div 下拉菜单中发生键盘导航时移动垂直滚动条

Javascript获取文档中的字符,包括css和javascript