设置overflow:auto到所有元素除了html坏习惯? [英] Is setting overflow: auto to all elements except html bad practice?

查看:293
本文介绍了设置overflow:auto到所有元素除了html坏习惯?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当开始一个新的设计时,我总是开始我的样式表,推翻浏览器的所有元素的默认填充和边距:

When it comes to starting a new design I always start my style sheet with overruling the browser's default padding and margin on all elements:

* { margin: 0; padding: 0; }

阅读 j08691的回答一个边际崩溃问题我意识到 overflow:auto 修复了比我知道的。我想知道是否对 html 中的所有元素添加 overflow:auto 以松开滚动条)。所以:

After reading j08691's answer on a margin collapse problem I realized overflow: auto fixed more than I knew of. I was wondering if it would useful to add overflow: auto on all elements inside the html (you don't want to loose the scroll-bar there). So:

html * { overflow: auto; }

我试图将这条规则添加到我们的网站之一,恐怕它可能打破更多的异国元素(我现在不使用,但可能更晚)和... Internet Explorer。

I tried adding this rule to one of our sites, and at first glance this works well, but I'm afraid it might break the more exotic elements (that I'm not using now, but might later) and ... Internet Explorer.

具有默认 overflow:auto 的经验?这是坏事吗?我应该选择一个较温和的版本,并在 div 元素上定义默认 overflow:auto b $ b

Do any of you have experience with a default overflow: auto? Is it a bad thing to do? Should I opt for a milder version and defining a default overflow: auto only on div elements?

推荐答案

是的,我认为这是坏的做法。您应该只在不知道内容是否可以破坏元素的大小时才使用它。

Yeah, I do think it's bad practice. You should only use it when you don't know whether the content can break the size of an element.

这篇关于设置overflow:auto到所有元素除了html坏习惯?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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