Layout Calculation

Hi I’m reading a book on layouts. An it tells you what to add and subtract so that everything fits okay. However i find one bit confusing.

The book reads:

"Body width= 600 pixels

Left and right columns, both: margin = 5 pixels x 2, border = 2 pixels x 2, padding = 5 pixels x 2, a total of 24 additional pixels in each column, plus the 90-pixel content width, for a total of 114 pixels,

The middle column also has 24 pixels in the margins, border, and padding.

If the two columns and 24 added pixels in the middle are subtracted from the 600-pixel body width, it leaves 348 pixels for the content of the column, or 58 percent. "

I thought it would be 114 + 24 = 138
600 - 138.

I don’t know how their getting 348 pixels

1 Like

Get a new book! :smile:
Don’t set you body to any fixed width in pixels, ever!

1 Like

You just forgot to count both the columns - 114 + 114 = 228, 228 + 24 = 252, which leaves 348 pixels in the centre.

1 Like

But this confusion could arise even if you were working in percent. :smile:

I can understand how this could be confusing. The “margin = 5 pixels x 2” refers to 5 pixels margin on each side of one column, not 5 pixels per column. But I can see how that could be easily misread.

However, as @SamA74 says, that kind of pixel-precise layout is very out-dated, and unsuited to the current scenario where there are so many different devices or difffering sizes, from phones to wide-screen, HD monitors.

1 Like

Should I try convert all the widths into percentage and the pixels into ems?

I wasn’t concerned about the calculations, more about what book the OP is “learning” from.
The other thread has an example of a more up to date, fluid solution.

Not necessarily, for main containers, changing width to max-width can be better to limit width. For smaller containers like sidebars px (or em) widths can actually be better than % because % can get too thin or too wide on varying screens.

If it is anything to do with text, yes, you will handle text only zooming better. For image based elements pixels can be better.

1 Like

If you’re unfamiliar with the approach, I’d recommend reading a book or a couple of articles on responsive design. For example:

http://www.sitepoint.com/web-foundations/what-is-responsive-web-design/

http://www.sitepoint.com/responsive-web-design/

3 Likes

To add to what @technobear lists, I’d also suggest that anyone working with layouts read Ethan Marcotte’s seminal work on the subject of RWD - http://alistapart.com/article/responsive-web-design - get your head around that (not a difficult task), and you’ll be well ahead of many of your peers.

5 Likes

You might find it easier to use the ‘border-box’ model rather than the standard box model as padding and borders are included within your specified width and makes calculations easier although you do still have to ensure you have room for your content.

These days I always use the border-box model by default on all my projects. It makes life so much easier.:slight_smile:

3 Likes

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.