考虑下面的例子:(现场演示)
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一样集中对齐?我怎么把它放在中间?
当前回答
添加显示:块;到你的iframe css。
Div, iframe { 宽度:100 px; 高度:50 px; 保证金:0自动; background - color: # 777; } iframe { 显示:块; 边框样式:没有; } < div > div < / div > < iframe的src = "数据:iframe " > < / iframe >
其他回答
将iframe居中的最佳方法和更简单的方法是:
<p align="center"><iframe src="http://www.google.com/" width=500 height="500"></iframe></p>
其中宽度和高度将是你的HTML页面中的iframe的大小。
添加显示:块;到你的iframe css。
Div, iframe { 宽度:100 px; 高度:50 px; 保证金:0自动; background - color: # 777; } iframe { 显示:块; 边框样式:没有; } < div > div < / div > < iframe的src = "数据:iframe " > < / iframe >
你可以把iframe放在<div>中
<div>
<iframe></iframe>
</div>
它可以工作,因为它现在在块元素中。
如果你不能访问iFrame类,然后添加下面的css包装div。
<div style="display: flex; justify-content: center;">
<iframe></iframe>
</div>
你可以试试
<h3 style="text-align:center;"><iframe src=""></iframe></h3>
我希望它对你有用
link