【问题标题】:Can't resize in iframe [duplicate]无法在 iframe 中调整大小 [重复]
【发布时间】:2015-07-05 20:43:25
【问题描述】:

我希望能够使用 css 中的调整大小功能调整 div 的大小。在我的 .css 文件中,我有:

#test {
    border: 2px solid;
    padding: 20px;
    width: 300px;
    resize: both;
    overflow: auto;
}

我的 div 如下:

<div id="test">Let the user resize both the height and the width of this div element.</div>

在我将我的 html 放入 iframe 之前它工作正常,我无法调整 div 的大小。怎么了?

PS:我不想用 jquery

【问题讨论】:

    标签: html css


    【解决方案1】:

    iframe 作为新网站处理。要将 CSS 应用到 iframe - 只需在 iframe 中设置对样式表的引用即可。

    <iframe id="frame"></iframe>
    
    <script>
    document.getElementById('iframe').contentWindow.document.write("<html><head>" +
    "<link rel='stylesheet' href='style.css'>" + 
    "</head><body><div id='test'></div></body></html>");
    </script>
    

    这样,您的 iframe 将正确访问您的样式表

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-03-31
      • 1970-01-01
      • 2014-06-04
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多