iframe居中

杀意已决 2014-03-20 11:15:53
页面上有一个iframe

目前是全屏的时候水平居中

我想让它在窗口不是全屏的时候仍然在当前窗口居中
...全文
560 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
  • 打赏
  • 举报
回复
框架页面内水平垂直居中
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="textml; charset=utf-8" />
<title>无标题文档</title>
<style type="text/css">
.box{ position:absolute;}
</style>
<script>
window.onload=function()
{
	var oBox=document.getElementById('box');
	adjustResize();
	window.onresize=window.onscroll=adjustResize;
	function adjustResize()
	{
		var iWidth=document.documentElement.clientWidth;
		var iHegiht=Math.max(document.documentElement.clientHeight,document.body.clientHeight);
		oBox.style.left=(iWidth-oBox.offsetWidth)/2+'px';
		oBox.style.top=(iHegiht-oBox.offsetHeight)/2+'px';
	}
}
</script>
</head>

<body>
<div class="box" id="box">
	<iframe width="800" height="400" frameborder="0" scrolling="no" src="http://www.baidu.com"></iframe>
</div>
</body>
<html>
varbobo 2014-03-20
  • 打赏
  • 举报
回复
position:absolute;left:50%;margin-left:-iframe宽度/2 比如iframe宽100px,设置margin-left:-50

61,125

社区成员

发帖
与我相关
我的任务
社区描述
层叠样式表(英文全称:Cascading Style Sheets)是一种用来表现HTML(标准通用标记语言的一个应用)或XML(标准通用标记语言的一个子集)等文件样式的计算机语言。
社区管理员
  • HTML(CSS)社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧