LarrySteele
Programmer
Okay, we've all read that there are few evils as bad as using tables for page layout. Got it.
The page I'm currently working on is the classic "C." It's pretty straightforward until I get to the content div on the first page.
The first page includes a simple input form. The page background is white, and they want the input form to be wrapped in a lite gray box. They want a second box, lighter gray to the right that will contain instructions or whatever. The left side of box 2 will be 15px to the right of box 1 and will continue to page end.
Height of both boxes will be the same.
Width of box 1 will vary because there's a select box that's filled from a database - and this will end up driving the width of the first box. This prevents us from using fixed positioning.
Here's the conceptual layout:
I've checked through a few CSS books I have here and have queried the great Google machine for ideas and answers.
Generally speaking, most point towards using floats. I've used floats for the page header successfully, and figured floating would probably be the best path for this request. So tried playing with floats a bit - floating everything left. For the white space in the middle, I added floated a div that was 15px wide with a white background. Here are some of the problems I had - if text in the right box was too long to display on one line, rather than simply wrapping, it first moved the box below box one, then wrapped. When it was short enough not to wrap, it was not same height as box 1. I had situations where the second gray box placed its top left corner at the same position as the top left corner of the first box.
I played around with so many variations of floats that I really did lose track of which wrong effect went with which rendering attempt.
There's a very easy way to manage this - make a one row table with three columns. Easy to write, easy to understand, and easy to maintain.
=========================================================
I'm curious how others would handle a page layout like this. Do you "break the rules" and use a table to layout these elements? Do you go through a bunch of CSS gymnastics? Or, have my books and the great Google failed me and there's a straightforward method for doing this that I haven't found?
This question is more philosophical than technical. I know that generally speaking, tables should be used to display tabular data. I know that creating the classic "C" page layout is better left to CSS than tables. But CSS has some definite limitations and I think there ought to be some balance between CSS-purists who proclaim though-shalt-not and those of us in the field who are trying to get the job done effectively and efficiently.
The page I'm currently working on is the classic "C." It's pretty straightforward until I get to the content div on the first page.
The first page includes a simple input form. The page background is white, and they want the input form to be wrapped in a lite gray box. They want a second box, lighter gray to the right that will contain instructions or whatever. The left side of box 2 will be 15px to the right of box 1 and will continue to page end.
Height of both boxes will be the same.
Width of box 1 will vary because there's a select box that's filled from a database - and this will end up driving the width of the first box. This prevents us from using fixed positioning.
Here's the conceptual layout:
Code:
+----------------------+ +--------------------------------->>
| (background: eaeaea) | | (background: e4e4e4)
| | |
| label [form field] | w | Lorem ipsum dolor sit amet,
| | h | consectetur adipiscing elit.
| label [form field] | i | Nunc egestas.
| | t |
| label [form field] | e |
| | |
| label [form field] | s |
| | p |
| label [form field] | a |
| | c |
| submit | e |
| | |
+----------------------+ +--------------------------------->>
I've checked through a few CSS books I have here and have queried the great Google machine for ideas and answers.
Generally speaking, most point towards using floats. I've used floats for the page header successfully, and figured floating would probably be the best path for this request. So tried playing with floats a bit - floating everything left. For the white space in the middle, I added floated a div that was 15px wide with a white background. Here are some of the problems I had - if text in the right box was too long to display on one line, rather than simply wrapping, it first moved the box below box one, then wrapped. When it was short enough not to wrap, it was not same height as box 1. I had situations where the second gray box placed its top left corner at the same position as the top left corner of the first box.
I played around with so many variations of floats that I really did lose track of which wrong effect went with which rendering attempt.
There's a very easy way to manage this - make a one row table with three columns. Easy to write, easy to understand, and easy to maintain.
=========================================================
I'm curious how others would handle a page layout like this. Do you "break the rules" and use a table to layout these elements? Do you go through a bunch of CSS gymnastics? Or, have my books and the great Google failed me and there's a straightforward method for doing this that I haven't found?
This question is more philosophical than technical. I know that generally speaking, tables should be used to display tabular data. I know that creating the classic "C" page layout is better left to CSS than tables. But CSS has some definite limitations and I think there ought to be some balance between CSS-purists who proclaim though-shalt-not and those of us in the field who are trying to get the job done effectively and efficiently.