负利润,黑客与否?
我见过各种帖子,人们都说负边距是黑客行为。因此,我已经偏离使用它们,除非我可以合理地使用它们的特定情况,例如使用 margin:-9999px
将文本从屏幕上扔掉
问题,负边距是一种黑客攻击吗?正确使用负边距?我见过它们在 960 网格系统中与 .push
和 .pull
一起使用,在任何其他情况下它们都可以合理使用吗?!?!
I've come across various posts where people are stating that negative margins are hacks. Thus I've strayed away from using them with exception to particular cases when I can justifiably use them, like throwing text off the screen with margin:-9999px
Question, are negative margins a hack and when is it right to use negative margins? I've seen them used in the 960 Grid System with, .push
and .pull
, any other cases where they are justifiably usable?!?!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
根据 W3C 规范,允许使用负边距。我用它们让东西悬在容器上方。
Negative margins are allowed based on W3C specifications. I have used them to let things overhang their container.
我认为这不是黑客:它是定义的、逻辑的行为;所有浏览器都支持它;预计未来版本的浏览器将支持它(未来不支持是反对黑客攻击的最重要论据)。
此外,正如 @durilai 指出的,它们受到 W3C 的正式认可(尽管有限制)。
这篇Smashing 杂志文章支持该案。
I would argue it's not a hack: It's defined, logical behaviour; it's supported in all browsers; it can be expected to be supported in future versions of browsers (the absence of future support is the most important argument against hacks).
Also, as @durilai points out, they are officially sanctioned (although with limits) by the W3C.
This Smashing Magazine article supports the case.
我怀疑他们因为浏览器行为不一致而被标记为黑客。
只要有可能,我都会使用
position:relative
和负的顶部和左侧值将元素拉到新位置。这并不适用于所有情况,但我发现它在所有 Internet Explorer 风格中的行为更加一致。I suspect they've been labeled as a hack because of inconsistent browser behavior.
Whenever possible I use
position: relative
and negative top and left values to pull elements into new locations. This isn't possible for every case, but I find it behaves more consistently in all the Internet Explorer flavors.