I first read about negative margins as a design technique a couple of years ago, in a Site Point article by Jina Bolton entitled, “Breaking Out of the Box”
http://www.sitepoint.com/breaking-out-of-the-box/, wherein she described the use of negative margins in design to offset elements and “break the grid” to achieve a more attractive layout. I later read how negative margins could be used to actually overlap elements for design purposes.
Negative margins are not “magic numbers,” a term, it seems from the link that you posted, that has no real meaning, but is used derogatorily to mean “a hack.” After doing some research, I found that this is an ongoing controversy, with some designers advising to avoid them like the plague. But negative margins are a valid CSS technique according to the W3C.
[INDENT]1. Setting the record straight
We all use margins in our CSS, but when it comes to negative margins, our relationship somehow manages to take a turn for the worse. The use of negative margins in web design is so divided that while some of us absolutely love it, there are also those who simply think it’s the work of the devil.
A negative margin looks like this:
view sourceprint?
1 Content {margin-left:-100px;}
Negative margins are usually applied in small doses but as you’ll see later on, it’s capable of so much more. A few things to note about negative margins are:
•They are extremely valid CSS
I’m not kidding on this one. W3C even says that, “Negative values for margin properties are allowed…” ‘Nuff said. Check out the article 1 for more details.
•Negative margins are not a hack
This is especially true. It’s because of not understanding negative margins properly that it got its hackish image. It only becomes a hack if you use it to fix an error you made elsewhere.
•It goes with the flow
It does not break the flow of the page if applied to elements without floats. So if you use a negative margin to nudge an element upwards, all succeeding elements will be nudged as well.
•It is highly compatible
Negative margins are wholly supported across all modern browsers (and IE6 in most cases).
•It reacts differently when floats are applied
Negative margins are not your everyday CSS so they should be applied with care.
•Dreamweaver doesn’t understand it
Negative margins don’t show up in the Design View of DW. Why are you even checking your site in Design View anyway?
[/INDENT]
In my design, I used a negative top margin on the sidebar to position it above the header all the way to the top of the page, and overlapping the header (-185 px = 150 px header height + 35px top margin applied to the header div). This was deliberate, and not “picked out of the air.” I have not yet found any other way to accomplish this techique, which in my design allows for the header horizontal gray stripes to show over the top of the sidebar (which has a transparent gradient background image that repeats horizontally across it’s width).
This is also the reason I have had to assign a height to the sidebar (which you also called a “magic number”), as without a height there is no sidebar visible, as it collapses (as one might expect). Additionally, the page height is specified at 900px ( I do not understand why you said this caused you to scroll continually — in any of my browsers, I cannot scroll below the set height of the page (which happens to be the height of my monitor (1600px X 900px). For the purposes of testing the design, this 900px height was arbitrary, I admit, and I may set the page height taller if it needs to be. What is wrong with establishing a height for a Web page? Another controversy for which I’m sure there are plenty of desingers who prefer to have no end to the page length, and something I despise in a Website. Make a new page! For cryin’ out loud, what’s the big deal?
I think we are probably more or less really on the same page where the importance of design vs. the importance of “content” is concerned, but for me, if design is going to suffer, I’ll rethink content placement and styling first. I do agree that what is contained in the page (“content”) becomes integral to the design (and I think a good example of what I mean is in Jina Bolton’s article referenced above).
I would like to see some examples of some of your designs. Where can I find them?
I knew about comma separated lists to apply styles to multiple elements. I don’t understand why you added “html” in front of the “body.” What, will that do?
Thanks for the info on z-index. Not sure yet where it might apply, but I can see that it could be useful in accomplishing some design technique.