html - 为特定宽度的内容主体居中 iframe 内容

标签 html css iframe

另一个问题可能无法回答: 在我的网站上,我在 div 容器中有一个 iframe:

分区:

<div id='frame'>
    <iframe id='content' name='contentfield' ></iframe>
</div>

css 文件中有:

CSS:

div#frame{
position:absolute;
display:flex;
background-color:green;(just for my testing)
top:100px;
float:left;
width:calc(100vw - 200px);
height:calc(100vh - 100px);
}
iframe#content{
border:none;
width:100%;
height:100%;
}

这个 iframe 显示了我网站的不同方面,例如index.php(很多 index.php 的) 所以一个由 javascript 加载:

function start(id){active = id;
    document.getElementById('content').src='content/hallo/';
}

所以有:content/hallo/index.php。 index.php 是一个普通的 html 文件,但是 body 被设置为特定的 px 宽度:

<body style='width:1000px'>
    ...
</body>

现在:如果浏览器窗口大于 1200px(body 为 100px,另一个 div 为 200px,请参阅 div#frame)iframe 的内容具有 1000px 的宽度但向左浮动。我希望它居中,这样如果浏览器窗口的宽度为 1600px,则内容的 margin-left=margin-right 为 200px a.s.o.

编辑: 显示不希望的屏幕截图: darkgray is the menu, light gray the iframe and, as you guess right, the pic i a part of me

最佳答案

解决方案:您将设置以下属性

max-width:auto;

关于html - 为特定宽度的内容主体居中 iframe 内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47729931/

相关文章:

jquery - 我如何处理网页和移动浏览器上的滚动?

html - 谷歌地图 100% 高度不工作

javascript - JavaScript 变量中的简单 Iframe

html - 使子 div 大于固定位置父 div

html - 列表样式位置 : outside not working HTML CSS

jquery - 在带jQuery的youTube和Vimeo源之间切换

javascript - 如何更改 reddit 的嵌入评论 iframe 的最大宽度?

javascript - 是否有关于如何创建简单的外部 javascript 小部件的教程?

javascript - jQuery 在一个又一个的 child 中淡入淡出

html - 使用 ng-show AngularJS 传递元素