如何水平居中 iframe? [英] How to center an iframe horizontally?

查看:112
本文介绍了如何水平居中 iframe?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

考虑以下示例:(现场演示)

HTML:

div

<iframe></iframe>

CSS:

div, iframe {宽度:100px;高度:50px;边距:0 自动;背景色:#777;}

结果:

为什么 iframe 不像 div 那样居中对齐?我怎样才能集中对齐它?

解决方案

display:block; 添加到您的 iframe css.

div, iframe {宽度:100px;高度:50px;边距:0 自动;背景色:#777;}iframe {显示:块;边框样式:无;}

div

<iframe src="data:,iframe"></iframe>

Consider the following example: (live demo)

HTML:

<div>div</div>
<iframe></iframe>

CSS:

div, iframe {
    width: 100px;
    height: 50px;
    margin: 0 auto;
    background-color: #777;
}

Result:

Why the iframe is not centrally aligned like the div? How could I centrally align it?

解决方案

Add display:block; to your iframe css.

div, iframe {
    width: 100px;
    height: 50px;
    margin: 0 auto;
    background-color: #777;
}

iframe {
    display: block;
    border-style:none;
}

<div>div</div>
<iframe src="data:,iframe"></iframe>

这篇关于如何水平居中 iframe?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆