【发布时间】:2013-06-12 00:25:36
【问题描述】:
这段代码有效地将 iframe 居中,但在其左边缘而不是其中心。
<!DOCTYPE html>
<html lang="en" xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta charset="utf-8" />
<title>Videos</title>
<style>
div.center {
width: 200px;
display: block;
margin-left: auto;
margin-right: auto;
}
</style>
</head>
<body style="background: lightblue">
<div class="center">
<iframe src="http://www.youtube.com/embed/dgZ-K87NcwQ"></iframe>
<p />
<iframe src="http://www.dailymotion.com/embed/video/xoy7jd"></iframe>
</div>
</body>
</html>
我看过这些问题:
- How to center an iframe horizontally?
- how do I center the full page?
- How to horizontally center a <div> in another <div>?
- How to center an iframe horizontally?
不幸的是,没有一个对我有用。
如何真正将这些放在屏幕上?
【问题讨论】:
-
在 HTML 中,不要写
<p />。它不会做你认为它会做的事情。见this fiddle。您可以在 XHTML 中执行此操作,但强烈建议不要这样做。但不是在 HTML 中。此外,您不应该将段落用于垂直间距。 -
对,我应该改用
吗? -
没有。给 iframe
display:block然后你就可以在它们上面加边距了。