Negative Margins, Hack or Not?

荒凉一梦 提交于 2019-12-05 10:05:07

问题


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?!?!


回答1:


Negative margins are allowed based on W3C specifications. I have used them to let things overhang their container.




回答2:


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.




回答3:


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.



来源:https://stackoverflow.com/questions/3534324/negative-margins-hack-or-not

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!