没有属性"allowtransparency"

Bha*_*mar 36 html css w3c w3c-validation

我正在寻找一些替代方法:

<iframe transparency=true   ...
Run Code Online (Sandbox Code Playgroud)

当我进行W3C验证时,我收到错误:

Column 31: there is no attribute "allowtransparency"
Run Code Online (Sandbox Code Playgroud)

如果使用这个CSS,

.iframe-trans-fix{
   opacity: 0;
   filter:alpha(opacity=0);
}
Run Code Online (Sandbox Code Playgroud)

对于上面的代码片段,我得到一个空白的iframe.

jam*_*iss 33

虽然W3C的HTML规范确实没有定义它,但是有一个allowTransparency属性,所有现代浏览器(和Internet Explorer)都支持它.正如HTML5告诉我们的那样,购物车应该在马前.

假设您的主页上有这个HTML,index.html:

<html>
    <body>
        <iframe src="source.html" 
                allowTransparency="true" 
                style="background-color:lightgreen;" 
                width="400" height="200">
        </iframe>
    </body>
</html>
Run Code Online (Sandbox Code Playgroud)

你的source.html看起来像这样:

<html>
    <body>
        <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Proin gravida, magna
           id bibendum sollicitudin, tellus tortor consequat enim, et mollis mauris 
           augue et dui. </p>
    </body>
</html>
Run Code Online (Sandbox Code Playgroud)

当您在浏览器中打开主页面(index.html)时,您将在iframe中看到来自source.html的文本,但它将具有浅绿色背景.

(在Mac OS X上测试Safari,Firefox和Chrome,在Windows XP上测试Internet Explorer 8和Chrome)

编辑:关键是:源页面无法设置自己的背景.如果是,则忽略透明背景.

  • 这个属性可能没有你想象的那么广泛使用,你有没有看到它是否真的改变了除 IE 之外的浏览器的行为?据我所知,这是一个特定于 IE 的属性,其他浏览器默认允许 iframe 透明,而忽略此属性。 (2认同)

Yi *_*ang 13

我不确定你在这里要做什么,但这应该是你正在寻找的:

iframe {
    background-color: transparent;
}
Run Code Online (Sandbox Code Playgroud)

当然,这是假设您希望背景iframe是透明的.