Connecting Tech Pros Worldwide Help | Site Map
 
 
LinkBack Thread Tools Search this Thread
  #1  
Old April 12th, 2006, 05:45 AM
axlq
Guest
 
Posts: n/a
Default can this layout be done without tables?

Suppose I had to lay out a part of a page where I wanted to retain the
horizontal and vertical relationship of the elements. Yes, this is what
tables are for. I was curious if it can be done in CSS, in a way that
works across all browsers. For example:

+------------------------------------------------------+
| +--------------------------------------------+ |
| |+---------------------+ +------------------+| |
| || a block of stuff | | unknown but small|| |
| || | | width data table || |
| || | +------------------+| |
| |+---------------------+ +-------------+ | |
| | (empty space) | some small | | |
| |container is centered | block below | | |
| |horizontally regardless | the table | | |
| |of its width +-------------+ | |
| +--------------------------------------------+ |
|this container has the maximum available width |
+------------------------------------------------------+

Table layout consists of a simple 2-row, 3-cell table (with the left
cell rowspan=2), and the table is centered in the available width.

I tried to implement this using no tables, and couldn't achieve
anything that satisfied me. The lower right-hand block would always
appear in an odd place. And I ended up with a soup of divs.

I don't mind using tables for layout if I have to, but I'm always
curious about ways to avoid it if I can do so.

-A



  #2  
Old April 12th, 2006, 07:25 PM
Tony
Guest
 
Posts: n/a
Default Re: can this layout be done without tables?

axlq wrote:[color=blue]
> Suppose I had to lay out a part of a page where I wanted to retain the
> horizontal and vertical relationship of the elements. Yes, this is what
> tables are for. I was curious if it can be done in CSS, in a way that
> works across all browsers. For example:
>
> +------------------------------------------------------+
> | +--------------------------------------------+ |
> | |+---------------------+ +------------------+| |
> | || a block of stuff | | unknown but small|| |
> | || | | width data table || |
> | || | +------------------+| |
> | |+---------------------+ +-------------+ | |
> | | (empty space) | some small | | |
> | |container is centered | block below | | |
> | |horizontally regardless | the table | | |
> | |of its width +-------------+ | |
> | +--------------------------------------------+ |
> |this container has the maximum available width |
> +------------------------------------------------------+[/color]

This worked in IE and FF:

<div style="background-color:#ffffcc">

<div style="width:90%;margin:auto;border:solid blue 1px">

<div style="float:right;border: solid red 1px;padding: 5px;margin:
10px;">
<table style="background-color:#cccccc;border: solid green 1px">
<tr>
<td style="background-color: #ffffff">cell</td>
<td style="background-color: #ffffff">cell</td>
</tr>
<tr>
<td style="background-color: #ffffff">cell</td>
<td style="background-color: #ffffff">cell</td>
</tr>
</table>
</div>

<div style="border: solid red 1px;margin: 10px;">
The block of stuff goes here
The block of stuff goes here
The block of stuff goes here
The block of stuff goes here
</div>

<div style="clear:both"></div>

<div style="float:right; border: solid red 1px;margin: 10px;">
Small block D
</div>

<div style="clear:both"></div>

</div>

</div>
  #3  
Old April 13th, 2006, 01:58 AM
axlq
Guest
 
Posts: n/a
Default Re: can this layout be done without tables?

In article <123qgpiteqrrt1c@corp.supernews.com>,
Tony <tony23@dslextreme.WHATISTHIS.com> wrote:[color=blue]
>axlq wrote:[color=green]
>> Suppose I had to lay out a part of a page where I wanted to retain the
>> horizontal and vertical relationship of the elements. Yes, this is what
>> tables are for. I was curious if it can be done in CSS, in a way that
>> works across all browsers. For example:
>>
>> +------------------------------------------------------+
>> | +--------------------------------------------+ |
>> | |+---------------------+ +------------------+| |
>> | || a block of stuff | | unknown but small|| |
>> | || | | width data table || |
>> | || | +------------------+| |
>> | || | +-------------+ | |
>> | |+---------------------+ | some small | | |
>> | | (empty space) | block below | | |
>> | |container centered horiz. | the table | | |
>> | |regardless of width +-------------+ | |
>> | +--------------------------------------------+ |
>> |this container has the maximum available width |
>> +------------------------------------------------------+[/color]
>
>This worked in IE and FF:[/color]

Hmm, thanks. I guess my picture wasn't clear that the "some small
block" shouldn't necessarily start at the bottom border of the
left-hand "block of stuff" but rather immediately below the table.
So the clear=both prior to the small block shouldn't be there.
I fixed the picture in the quoted text above to correct this.

Also I wanted to avoid suggesting a width (like the 90% you used).
I needed the width to be the width of the content, centered in the
outer container. That is, the space between the outer container and
the next inner container can be zero, or even force the browser to
create a horizontal scroll bar. Is it possible to make a container
that shrinks to whatever width it contains, and then center it
within another container?
[color=blue]
><div style="background-color:#ffffcc">
>
> <div style="width:90%;margin:auto;border:solid blue 1px">
>
> <div style="float:right;border: solid red 1px;padding: 5px;margin:
>10px;">
> <table style="background-color:#cccccc;border: solid green 1px">
> <tr>
> <td style="background-color: #ffffff">cell</td>
> <td style="background-color: #ffffff">cell</td>
> </tr>
> <tr>
> <td style="background-color: #ffffff">cell</td>
> <td style="background-color: #ffffff">cell</td>
> </tr>
> </table>
> </div>
>
> <div style="border: solid red 1px;margin: 10px;">
> The block of stuff goes here
> The block of stuff goes here
> The block of stuff goes here
> The block of stuff goes here
> </div>
>
> <div style="clear:both"></div>
>
> <div style="float:right; border: solid red 1px;margin: 10px;">
> Small block D
> </div>
>
> <div style="clear:both"></div>
>
> </div>
>
></div>[/color]

I figured it would be something like that. It seems in this case, a
table for this part of the layout is simpler:

<div style="background: #ffffcc; text-align: center">

<table style="display: inline" border=0 cellpadding=0 cellspacing=0>
<tr>
<td rowspan=2>
block of stuff goes here
</td>
<td>
<table style="background-color:#cccccc;border: solid green 1px">
<tr>
<td style="background-color: #ffffff">cell</td>
<td style="background-color: #ffffff">cell</td>
</tr>
<tr>
<td style="background-color: #ffffff">cell</td>
<td style="background-color: #ffffff">cell</td>
</tr>
</table>
</td>
</tr>
<tr>
<td>
small block
</td>
</tr>
</table>
</div>

-A
  #4  
Old April 13th, 2006, 06:15 PM
Tony
Guest
 
Posts: n/a
Default Re: can this layout be done without tables?

axlq wrote:[color=blue]
> In article <123qgpiteqrrt1c@corp.supernews.com>,
> Tony <tony23@dslextreme.WHATISTHIS.com> wrote:
>[color=green]
>>axlq wrote:
>>[color=darkred]
>>>Suppose I had to lay out a part of a page where I wanted to retain the
>>>horizontal and vertical relationship of the elements. Yes, this is what
>>>tables are for. I was curious if it can be done in CSS, in a way that
>>>works across all browsers. For example:
>>>
>>> +------------------------------------------------------+
>>> | +--------------------------------------------+ |
>>> | |+---------------------+ +------------------+| |
>>> | || a block of stuff | | unknown but small|| |
>>> | || | | width data table || |
>>> | || | +------------------+| |
>>> | || | +-------------+ | |
>>> | |+---------------------+ | some small | | |
>>> | | (empty space) | block below | | |
>>> | |container centered horiz. | the table | | |
>>> | |regardless of width +-------------+ | |
>>> | +--------------------------------------------+ |
>>> |this container has the maximum available width |
>>> +------------------------------------------------------+[/color]
>>
>>This worked in IE and FF:[/color]
>
>
> Hmm, thanks. I guess my picture wasn't clear that the "some small
> block" shouldn't necessarily start at the bottom border of the
> left-hand "block of stuff" but rather immediately below the table.
> So the clear=both prior to the small block shouldn't be there.
> I fixed the picture in the quoted text above to correct this.[/color]

In that case, place the data table and the small block in the same DIV,
and float that DIV to the right
[color=blue]
> Also I wanted to avoid suggesting a width (like the 90% you used).
> I needed the width to be the width of the content, centered in the
> outer container.[/color]

How are you determining the width of the content? Is it an image?
Otherwise, the content will generally size to the container, wrapping as
necessary.
[color=blue]
> That is, the space between the outer container and
> the next inner container can be zero, or even force the browser to
> create a horizontal scroll bar. Is it possible to make a container
> that shrinks to whatever width it contains, and then center it
> within another container?[/color]

Although I can't recall offhand how I did it, I have done exactly that
before. (Offhand, I would say to place the content ("A Block of Stuff")
in a DIV floated left)

But that still begs the question - how will the content width be
determined, given that text will simply wrap to the container width.
What would force it to expand the container's width?
  #5  
Old April 14th, 2006, 05:45 PM
axlq
Guest
 
Posts: n/a
Default Re: can this layout be done without tables?

In article <123t16cddfp3df0@corp.supernews.com>,
Tony <tony23@dslextreme.WHATISTHIS.com> wrote:[color=blue][color=green]
>> Also I wanted to avoid suggesting a width (like the 90% you used).
>> I needed the width to be the width of the content, centered in the
>> outer container.[/color]
>
>How are you determining the width of the content? Is it an image?[/color]

Well, the left-hand block could be an image, but the right-hand
ones are a table with text (short rows of varying widths; they fit
within 200px for an 11px font, but I'd like to avoid specifying
pixel sizes), and the small block contains a short line of text that
won't wrap (say a single word).
[color=blue]
>Otherwise, the content will generally size to the container, wrapping as
>necessary.[/color]

No wrapping would happen in the instance I mentioned above.
[color=blue][color=green]
>> That is, the space between the outer container and
>> the next inner container can be zero, or even force the browser to
>> create a horizontal scroll bar. Is it possible to make a container
>> that shrinks to whatever width it contains, and then center it
>> within another container?[/color]
>
>Although I can't recall offhand how I did it, I have done exactly that
>before. (Offhand, I would say to place the content ("A Block of Stuff")
>in a DIV floated left)
>
>But that still begs the question - how will the content width be
>determined, given that text will simply wrap to the container width.
>What would force it to expand the container's width?[/color]

Well, an image sized in pixels and some blocks sized in ems would
determine a container width that can't easily be calculated or
predicted.

-A
 

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Popular Articles

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over 205,414 network members.