考虑下面的例子:(现场演示)
HTML:
<div>div</div>
<iframe></iframe>
CSS:
div, iframe {
width: 100px;
height: 50px;
margin: 0 auto;
background-color: #777;
}
结果:
为什么iframe不像div一样集中对齐?我怎么把它放在中间?
考虑下面的例子:(现场演示)
HTML:
<div>div</div>
<iframe></iframe>
CSS:
div, iframe {
width: 100px;
height: 50px;
margin: 0 auto;
background-color: #777;
}
结果:
为什么iframe不像div一样集中对齐?我怎么把它放在中间?
当前回答
你可以试试
<h3 style="text-align:center;"><iframe src=""></iframe></h3>
我希望它对你有用
link
其他回答
在我的情况下,解决方案是在iframe类添加:
display: block;
margin-right: auto;
margin-left: auto;
你可以把iframe放在<div>中
<div>
<iframe></iframe>
</div>
它可以工作,因为它现在在块元素中。
如果你不能访问iFrame类,然后添加下面的css包装div。
<div style="display: flex; justify-content: center;">
<iframe></iframe>
</div>
<iframe src="https://www.facebook.com/plugins/page.php?href=https%3A%2F%2Fwww.facebook.com%2FRishabh-Cars-Jodhpur-110479104559774&tabs=timeline&width=500&height=1200&small_header=false&adapt_container_width=true&hide_cover=false&show_facepile=true&appId" width="500" height="1200" style="border:none;overflow:hidden;display:block;margin:0 auto;"6" allowfullscreen="true" allow="自动播放;clipboard-write;加密介质;画中画;合伙分成应得的" > < / iframe >
使用它和嵌入facebook在iframe中心的HTML页面
你可以试试
<h3 style="text-align:center;"><iframe src=""></iframe></h3>
我希望它对你有用
link