用CSS集中整个页面 [英] Centering entire page with CSS

查看:126
本文介绍了用CSS集中整个页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图仅使用CSS集中我的整个页面,这证明比我预期的更复杂。目前我的代码在IE中工作,但不是在Firefox中进行更改。您可以在此处查看该页面。下面是涉及的代码部分:

I am attempting to center my entire page using only CSS and it is proving more complicated than i first expected. Currently my code works in IE but not in Firefox which makes a change. The page can be seen here. Below is the code portion involved:

#wrap {
    width: 960px;
    margin: 0 auto;
    padding: 6px;
    background: #FFFFFF;
    }

我的HTML结构是:

<body>
<div id="wrap">
    Gubbins in here.
</div>
</body>

看起来在Firefox中,wrap div之后的所有内容都是在它外面创建的。这是问题是解决,如果我添加一个'float:left'到wrap div,但显然一些漂浮在左边而不是中心。

It seems that in Firefox everything following the wrap div is be created outside of it. This is problem is resolved if i add a 'float: left' to the wrap div but then obviously everything floats left rather than center.

任何帮助将非常感谢。

Any help would be greatly appreciated.

推荐答案

将您的标记更改为

<body>
<div id="wrap">
    Gubbins in here.
</div>
</body>

编辑:看看链接,你已经这样做了。你会想要添加overflow:auto; #wrap或在wrap div上的结束标记之前的末尾添加一个清除div。

Looking at the link, you've already done that. You'll want to either add overflow:auto; to #wrap or add a clearing div at the end just before the closing tag on the wrap div.

此外,在您的示例页面上,wrap div缺少关闭

Also, on your example page, the wrap div is missing its closing tag.

这篇关于用CSS集中整个页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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