PHP 悬浮居中iframe显示html内容
可以使用以下PHP代码实现悬浮居中iframe显示HTML内容:
<?php
$html_content = "<h1>Hello World!</h1>"; //替换为要显示的HTML内容
?>
<div style="position: fixed; top: 50%; left: 50%; transform: translate(-50%, -50%); z-index: 9999;">
  <iframe srcdoc="<?php echo $html_content; ?>" width="500" height="500" frameborder="0"></iframe>
</div>
解释:
- 首先定义要显示的HTML内容,这里使用了一个简单的标题作为示例。
 - 然后使用一个div元素包裹iframe,设置其position为fixed,即固定在页面上,top和left为50%,即居中显示,使用transform属性将其向左上方移动自身宽高的一半,以使其完全居中。最后设置z-index为9999,以确保其在页面上最上层。
 - 在iframe中使用了srcdoc属性,将其设置为要显示的HTML内容。同时设置其宽度和高度为500px,并去掉了边框。
 
注意:这种方式会将HTML内容嵌入到iframe中,并在浏览器中显示。如果HTML内容中包含外部资源(如图片、样式表、脚本等),则可能无法正常显示。
原文地址: https://www.cveoy.top/t/topic/EV3 著作权归作者所有。请勿转载和采集!