Html 如果在没有javascript的情况下没有返回任何内容,如何隐藏iframe

Html 如果在没有javascript的情况下没有返回任何内容,如何隐藏iframe,html,css,asp.net-mvc,iframe,Html,Css,Asp.net Mvc,Iframe,我试图创建一个具有特定大小的内容区域,但是如果api返回的结果为空,我不希望显示任何内容 这是html的代码: <div class="myclass"> <iframe frameborder="0" src="http://localhost:1000/example"></iframe> </div> css的行为是:iframe一直是隐藏的,尽管我在其中有内容。 如果iframe如下所示: .myclass { max-w

我试图创建一个具有特定大小的内容区域,但是如果api返回的结果为空,我不希望显示任何内容

这是html的代码:

<div class="myclass">
        <iframe frameborder="0" src="http://localhost:1000/example"></iframe>
</div>
css的行为是:iframe一直是隐藏的,尽管我在其中有内容。 如果iframe如下所示:

.myclass {
max-width: 1060px; 
max-height: 392px;

  & > iframe {
      min-height: 0;
      min-width: 0;
      max-width: 1060px;
      max-height: 392px;
    }

   & > iframe:empty {
    display: none;
 }
}
<div class="myclass">
        <iframe frameborder="0" src="http://localhost:1000/example">
        <!--notice white-space here-->
        </iframe>
</div>
iframe {
    display:none;
}


css不会将iframe视为空的。

我实际上是在没有javascript的情况下实现的

但是您需要创建一个代理来生成css

如果不可能出现以下情况,那么所有的赌注似乎都没有了。祝你好运

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <style>
        @import url('iframecheck.asp?url=http://www.example.com');
        iframe {
            width:1000px;
            height:400px;
        }
    </style>
</head>
<body>
<iframe src="http://www.example.com"></iframe>
</body>
</html>
这将自动覆盖其他
iframe
样式

如果需要,请不要忘记强制使用text/css内容类型标题

<%response.ContentType="text/css"%>


默认情况下隐藏它,如果内容不是空的,用javascript显示它怎么样?如果我错了,有人会纠正我,但iframe不总是返回一些东西,比如新文档吗?所以它从来都不是空的?