473,406 Members | 2,343 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

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
Apr 12 '06 #1
4 1281
axlq wrote:
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 |
+------------------------------------------------------+


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>
Apr 12 '06 #2
In article <12*************@corp.supernews.com>,
Tony <to****@dslextreme.WHATISTHIS.com> wrote:
axlq wrote:
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 |
+------------------------------------------------------+
This worked in IE and FF:


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?
<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>


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
Apr 13 '06 #3
axlq wrote:
In article <12*************@corp.supernews.com>,
Tony <to****@dslextreme.WHATISTHIS.com> wrote:
axlq wrote:
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 |
+------------------------------------------------------+
This worked in IE and FF:

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.


In that case, place the data table and the small block in the same DIV,
and float that DIV to the right
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.
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.
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?


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?
Apr 13 '06 #4
In article <12*************@corp.supernews.com>,
Tony <to****@dslextreme.WHATISTHIS.com> wrote:
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.
How are you determining the width of the content? Is it an image?


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).
Otherwise, the content will generally size to the container, wrapping as
necessary.


No wrapping would happen in the instance I mentioned above.
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?


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?


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
Apr 14 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

82
by: Peter Diedrich | last post by:
The site design is pretty simple: ============================================ | Head | ============================================ | | ...
4
by: Teknowbabble | last post by:
Hi All... Ive done several simple web pages, no biggy! Is there any way to layout a Table with lets say 3 columns and have the contents of those columns not have to fit the rigid row column...
39
by: Zak McGregor | last post by:
Hi all Are there any good solutions to aligning form field names and input boxes without resorting to tables? I am struggling to do this nicely at the moment. Thanks Ciao Zak
47
by: Neal | last post by:
Patrick Griffiths weighs in on the CSS vs table layout debate in his blog entry "Tables my ass" - http://www.htmldog.com/ptg/archives/000049.php . A quite good article.
5
by: Meinolf Sander | last post by:
Do you have experiences using HTML beautifiers (like 1st Page Editor) with nested table structures (like in <http://www.nexanto.de/m+e.html>)? Does the layout change significantly with non-text...
20
by: Tammy | last post by:
What would be a good alternative to using frames? I need something that will section my webpage into two halves and can change both frames on a single click. Thanks in Advance, Tammy
8
by: T. Bjarne | last post by:
I'm writing a form with a grid layout (similar to the ones in phpMyAdmin). The form will contain X number of columns and Y rows - all cells containg INPUT elements. As long as the data isn't...
15
by: Tamblyne | last post by:
This problem has got to have a simple solution and I can't be the first person who has ever handled it. Perhaps Google is no help because I'm not using the right terms? (I did find one post...
5
by: Ed Sproull [MSFT] | last post by:
First I'm pretty new to ASP.NET and I'm having a simple problem. I have small website with a header, sidebar and the the content. I want my content to appear beside my sidebar which seems to be a...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.