css - 根据iframe内容扩展div容器宽度

标签 css html iframe width

如何对齐 div 以扩展其宽度以匹配 iframe 内容的大小。

需要扩展父div以匹配iframe的内容。如果iframe生成的内容超出了父div的宽度,如何自动扩展父div的宽度???

CSS

#header {
    background-color:#FFA500;
}
#container {
    width:500px;
    position:absolute;
    left:200px;
    vertical-align:center;
}

#mainContainer {
    border:0px solid red;
    height:auto;
}

#menu {
    background-color:#FFD700;
    height:auto;
    width:100px;
    float:left;
}

#content {
    background-color:#EEEEEE;
    height:auto;
    width:400px;
    float:left;
}

#footer {
    background-color:#FFA500;
    text-align:center;
    clear:both;
}

.width-2 {
    width: 500px;
}

.iframeContainer {
    border:1px solid red;
    width: auto;
}
.iframeContainer .embed-container iframe {
     width: auto;   
     height:100%;
     border:1px solid royalblue;
}
.width-auto .embed-container iframe {
     width: auto;   
}

.expected {
     width: 400px;   
     background: green;
}



HTML

<div id="container" >

    <div id="header" >
        <h1 style="margin-bottom:0;"> Web Page</h1>
    </div>
    <div id="mainContainer">
        <div id="menu" >
        <b>Menu</b><br>
        HTML<br>
        CSS<br>
        JavaScript<br>
        HTML<br>
        CSS<br>
        HTML<br>
        CSS<br>
        JavaScript<br>
        HTML<br>
        CSS<br>
        HTML<br>
        CSS<br>
        JavaScript<br>
        HTML<br>
        CSS<br>
        HTML<br>
        CSS<br>
        JavaScript<br>
        HTML<br>
        CSS<br>
        HTML<br>
        CSS<br>
        JavaScript<br>
        HTML<br>
        CSS<br>
    </div>

    <div id="content">
        Content goes here
        <p>You might have seen floating content of web sites which is always visible on the page even if you scroll it. This is easy achieve thing by using just CSS. However there is also JavaScript alternative for this but the CSS one is smoother and faster as this doesn't includes any run time calculation. The below step by step process will guide to how to add a always visible div on web page.</p>
    </div>
    <div class="iframeContainer">
        <div class="embed-container">
            <iframe src="http://player.vimeo.com/video/30279492?title=0&amp;byline=0&amp;portrait=0" width="400" height="180" frameborder="0" webkitAllowFullScreen allowFullScreen></iframe>
        </div>
    </div>
</div>
<div style="clear:both;"></div>


<div id="footer">
    Copyright © W3Schools.com</div>

</div>

最佳答案

这取决于您与此 iframe 的关系。

关于css - 根据iframe内容扩展div容器宽度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23069116/

相关文章:

html - 页面加载时的 CSS 不透明度

html - 将用户重定向到他们自己的主页

c# - 将 iFrame 动态添加到页面?

php - 使用 iframe 在不同域的不同网站上显示相同数据的优缺点(以及可能的其他方法)

javascript - JS/JQUERY iframe.contents() 语法

javascript - 有什么方法可以通过 Javascript 或 CSS 更改浏览器打印设置

HTML/CSS : scroll bar appears below HTML elements

html - TD 宽度 - 使用 CSS 所需的最小值

html - CSS 定位 : Content that should be below the fold is appearing above the fold

javascript - 固定顶部导航 + 使用 Jquery 的粘性页脚