the zen CSS was driving me up the wall with all the math, and i imagine it scares some newbies off. negative margins are difficult to grasp even for experienced CSS coders. i figured if i could eliminate the negative margins, i could get almost anyone to use Zen.

after thinking about it for a while, i've found that i can use absolute positioning to eliminate ALL the math. here's how:

#main is the parent element of #content, #navbar, #sidebar-left and #sidebar-right. #main has its position set to relative; this means absolutely positioned child elements will be positioned relative to the top/right/left/bottom of #main and not relative to edges of the browser. by using absolute positioning for #navbar and the sidebars i've found that i don't need to do any math at all. check out my code and tell me what you think. if it works for others (it works great for me on my site), i say we seriously consider replacing the current Zen layout CSS with this easier CSS.

#main
{
   position: relative;  /*absolutely positioned child elements will be positioned relative to parent and not to the browser*/
}

#navbar {
   height: 50px;
   position: absolute;
   top: 0px; /* place 0px from the top edge of #main */
   left: 0px; /* place 0px from the left edge of #main */
   margin: 0px;
}

#sidebar-left {
   width: 200px;
   position: absolute;
   top: 50px; /* set to height of navbar - 50px from the top edge of #main is right below the navbar*/
   left: 0px; /* place 0px from the left edge of #main */ 
   margin: 0px;
}

#sidebar-right {
   width: 200px;
   position: absolute;
   top: 50px; /* set to height of navbar - 50px from the top edge of #main is right below the navbar*/
   right: 0px; /* place 0px from the right edge of #main */
   margin: 0px;
}


#content, .no-sidebars #content {	
   margin-left: 0;
   margin-right: 0;
   margin-top: 50px /*set to height of navbar */
   padding: 0; 
}

.sidebar-left #content {
   margin-left: 200px; /* width of #sidebar-left */
}

.sidebar-right #content {
   margin-right: 200px; /* width of #sidebar-right */
}

.two-sidebars #content {
   margin-left: 200px; /* The width of #sidebar-left */
   margin-right: 200px; /* The width of #sidebar-right */
}

this is working great for me and it requires no math at all.

thoughts?

Comments

debonator’s picture

regarding the above: it's a good idea to specify the width of #content for in the CSS for all the scenarios (no sidebars, sidebar-left, sidebar-right).

pkiff’s picture

debonator,

I didn't see that you had created a new thread until now, but I posted a reply to a duplicate post in the other thread where you brought this up:
http://drupal.org/node/201428#comment-3173466

Also, some of these questions/suggestions are also answered in a thread from late 2009 on a similar topic:
Can anyone explain the negative margins in the zen template?
http://drupal.org/node/273383

In particular, I would point to the reply by dman, which fairly eloquently explains what the point of all the negative margins in zen is:
http://drupal.org/node/273383#comment-2221238

Phil.

johnalbin’s picture

Component: CSS/HTML Markup » layout.css
Status: Active » Closed (fixed)

I completely agree the math is scary.

Thank god Sass was invented. http://zengrids.com/