使用body元素作为页面包装器 [英] Using the body element as a page wrapper

查看:175
本文介绍了使用body元素作为页面包装器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

昨天我和同事们讨论了使用body元素作为包装来避免div.page-margins或div.wrapper作为body元素的直接第一个子元素。



我喜欢使用body作为页面包装,并在其上应用各种样式,如宽度,边距,位置等。
通过快速搜索,我发现了这两篇博文[ 1 2 ],这证实了我。

我的同事不喜欢这个想法,因为曾经有过一些问题(IE7 +页面缩放),它们用于在body中使用div.wrapper。



所以我的问题是:是否有任何针对使用body元素的代码特定参数作为一个普通的容器元素?



附录:因为我们正在为我们的前端团队定义最佳实践,所以我们想要摆脱一些习惯 - 只是使用div.wrapper是因为有人习惯了这种习惯:)

由其他人提供的颜色推理,唯一的另一种情况是我可以想到它在哪里是必要的目前的包装是强制页脚粘到文档的末尾(当文档很短时,视口的底部)。除了这些情况,我想不出为什么要求包装的原因。我知道我已经使用了一个包装,只要我能记得,所以你的同事很可能会像我一样 - 从避免在老年人浏览器中出现错误时必须使用包装的那些日子来看,这是一个老习惯。



我认为最好有一个包装。这样,如果规格要求稍后发生变化以要求全窗口背景颜色或固定页脚,则您不必稍后添加包装并处理大量样式。毕竟,你只能说21个额外​​的字节......

 < body>< div id =body > ...< / DIV>< /体> 


Yesterday I had a discussion with my colleagues about using the body element as a wrapper to avoid something like div.page-margins or div.wrapper as a direct first child of the body element.

I like to use the body as a page wrapper and apply all sorts of styles like width, margin, positions etc. on it. With a quick search I found these two blog posts [1, 2] which confirm me.

My colleagues don't like the idea because there once were some problems (IE7 + page zoom) and they are used to use a div.wrapper inside body.

So my question is: Are there any code specific arguments against using the body element as a normal container element?

Addendum: Because we are defining best practices for our frontend team we want to get rid of some habits- and just using a div.wrapper because someone is used to this is one of those habbits :)

解决方案

In addition to the background-color reasoning provided by the others, the only other case I can think of where it is necessary to have the wrapper these days is to enforce a footer to "stick" to the end of the document (bottom of viewport when document is short). Aside from these cases, I can't think of a reason why the wrapper is required. I do know I've used a wrapper for as long as I can remember, so chances are your colleagues are like me - it's an old habit from the days when wrappers were necessary to avoid rendering bugs in aged browsers.

I would say it is still best practice to have a wrapper. This way if spec requirements change later on to require a full-window background color or fixed footer, you don't have to add the wrapper later and deal with moving the styles around a lot. After all, you're only talking about 21 extra bytes...

<body><div id="body">...</div></body>

这篇关于使用body元素作为页面包装器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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