473,796 Members | 2,462 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

table alike lay out (two columns dynamic width)

I was wondering if there is a good way to avoid a table but achieve
the following similar behaviour:

Two divs of equal height and undefined width next to each other with a
total width of 100%.
The width of the first (left) div should be the width needed to
contain its content on one line. The other div should take the rest of
the available width. Which content that comes into the first div is
not know in advance.
This can be achieved by using a table with two cells but is there a
good alternative to obtain this with divs or list markup (and the
right css obviously)?
Jun 27 '08 #1
6 2703
In article
<69************ *************** *******@8g2000h se.googlegroups .com>,
Roderik <em******@gmail .comwrote:
I was wondering if there is a good way to avoid a table but achieve
the following similar behaviour:

Two divs of equal height and undefined width next to each other with a
total width of 100%.
The width of the first (left) div should be the width needed to
contain its content on one line. The other div should take the rest of
the available width. Which content that comes into the first div is
not know in advance.
This can be achieved by using a table with two cells but is there a
good alternative to obtain this with divs or list markup (and the
right css obviously)?
No, it is not possible in the terms you state for the simple reason that
a div is 100% wide by default. You can explore the fanciest CSS you like
for shrink to width facilities (and there are a few) but you will always
end up coming across this barrier. You need to specify a width. And you
do not know it beforehand. So that rules out HTML/CSS without scripting
help to get the width somehow. That is about width. Height is probably
even more of a problem.

The magic of tables is that all this stuff is built into the technology.
Don't give it up for less than the weightiest reasons.

--
dorayme
Jun 27 '08 #2
On 2008-06-13, dorayme <do************ @optusnet.com.a uwrote:
In article
<69*********** *************** ********@8g2000 hse.googlegroup s.com>,
Roderik <em******@gmail .comwrote:
>I was wondering if there is a good way to avoid a table but achieve
the following similar behaviour:

Two divs of equal height and undefined width next to each other with a
total width of 100%.
The width of the first (left) div should be the width needed to
contain its content on one line. The other div should take the rest of
the available width. Which content that comes into the first div is
not know in advance.
This can be achieved by using a table with two cells but is there a
good alternative to obtain this with divs or list markup (and the
right css obviously)?

No, it is not possible in the terms you state for the simple reason that
a div is 100% wide by default. You can explore the fanciest CSS you like
for shrink to width facilities (and there are a few) but you will always
end up coming across this barrier. You need to specify a width. And you
do not know it beforehand. So that rules out HTML/CSS without scripting
help to get the width somehow. That is about width. Height is probably
even more of a problem.
There is a way to do it using a feature of block formatting contexts,
which is that they may become narrower due to floats in the way.

The spec says they should either become narrower or drop down. In
practice in FirefoxOperaSaf ariKonqueror, and maybe in IE who knows, they
become narrower.

The basic rule here is that *floats don't cross BFC boundaries*. By
making .right a BFC, it has to get out of the way of float .left
somehow.

But it's still a normal-flow block, so it still helps itself to as much
width as it can, which is why it extends all the way to the right.

Try this:

<style type="text/css">
div
{
border: 2px solid black;
margin: 0 2px;
}
.left { float: left }
.right { overflow: hidden }
</style>

...

<div class="left">
Shrinks to fit
</div>
<div class="right">
Takes up whatever's left
</div>
Jun 27 '08 #3
In article <sl************ *********@bowse r.marioworld>,
Ben C <sp******@spam. eggswrote:
On 2008-06-13, dorayme <do************ @optusnet.com.a uwrote:
In article
<69************ *************** *******@8g2000h se.googlegroups .com>,
Roderik <em******@gmail .comwrote:
I was wondering if there is a good way to avoid a table but achieve
the following similar behaviour:

Two divs of equal height and undefined width next to each other with a
total width of 100%.
The width of the first (left) div should be the width needed to
contain its content on one line. The other div should take the rest of
the available width. Which content that comes into the first div is
not know in advance....
No, it is not possible in the terms you state for the simple reason that
a div is 100% wide by default
....
Height is probably even more of a problem.

There is a way to do it using a feature of block formatting contexts,
which is that they may become narrower due to floats in the way.

The spec says they should either become narrower or drop down. In
practice in FirefoxOperaSaf ariKonqueror, and maybe in IE who knows, they
become narrower.

The basic rule here is that *floats don't cross BFC boundaries*. By
making .right a BFC, it has to get out of the way of float .left
somehow.

But it's still a normal-flow block, so it still helps itself to as much
width as it can, which is why it extends all the way to the right.

Try this:

<style type="text/css">
div
{
border: 2px solid black;
margin: 0 2px;
}
.left { float: left }
.right { overflow: hidden }
</style>

...

<div class="left">
Shrinks to fit
</div>
<div class="right">
Takes up whatever's left
</div>
I slap my forehead. I was not relating what I did know about BFC to the
situation so it was good of you to catch this.

This has given me an idea for columning where one need not specify
widths, taking care only not to bang on with long sentences in the left
column but I won't stop to go on about this.

OP's height problem is still to be solved.

--
dorayme
Jun 27 '08 #4
On 2008-06-13, dorayme <do************ @optusnet.com.a uwrote:
In article <sl************ *********@bowse r.marioworld>,
Ben C <sp******@spam. eggswrote:
>On 2008-06-13, dorayme <do************ @optusnet.com.a uwrote:
In article
<69*********** *************** ********@8g2000 hse.googlegroup s.com>,
Roderik <em******@gmail .comwrote:

I was wondering if there is a good way to avoid a table but achieve
the following similar behaviour:

Two divs of equal height and undefined width next to each other with a
total width of 100%.
[...]
I slap my forehead. I was not relating what I did know about BFC to the
situation so it was good of you to catch this.

This has given me an idea for columning where one need not specify
widths, taking care only not to bang on with long sentences in the left
column but I won't stop to go on about this.
You'd need to put <brafter each sentence or put each one in its own
block.
OP's height problem is still to be solved.
He presumably wants them both the height of the one that needs the most
height. Use a table or one of those border/background tricks depending
on whether they really need to be the same height or just to look like
they are.
Jun 27 '08 #5
In article <sl************ *********@bowse r.marioworld>,
Ben C <sp******@spam. eggswrote:
On 2008-06-13, dorayme <do************ @optusnet.com.a uwrote:
In article <sl************ *********@bowse r.marioworld>,
Ben C <sp******@spam. eggswrote:
On 2008-06-13, dorayme <do************ @optusnet.com.a uwrote:
In article
<69************ *************** *******@8g2000h se.googlegroups .com>,
Roderik <em******@gmail .comwrote:

I was wondering if there is a good way to avoid a table but achieve
the following similar behaviour:

Two divs of equal height and undefined width next to each other with a
total width of 100%.
[...]
I slap my forehead. I was not relating what I did know about BFC to the
situation so it was good of you to catch this.
There is one downside that OP might consider if he uses the
overflow:hidden on the right div: if he has images there, or generally,
if there is any content that cannot wrap like long urls, they will be
cut off. If that is remotely likely, he can use overflow: auto instead.
Or perhaps just use auto to be safe.

There is another too that may be of interest. With either hidden or
auto, if the material on the left is not pretty short, the right will be
squeezed to be easily unusuable, see what happens in Safari or FF when
the left is given more than very few words.

In other words, one can manage to get solution to OP's problem if the
case is tightly constricted.
OP's height problem is still to be solved.

He presumably wants them both the height of the one that needs the most
height. Use a table or one of those border/background tricks depending
on whether they really need to be the same height or just to look like
they are.
To give the appearance of equal heights, OP can wrap the two divs in a
bordered element and give the right div (judging by his post, obviously
the candidate for highest) a left border. That would mimic a one row two
cell table.

More interesting to assume that OP is not wanting a table because
material is not tabular.

But nevertheless, with a table, there is a small problem that he might
want to avoid: the sort of shrink to fit he might want might need a
nowrap in the td, otherwise even a short string of words in the left
cell would wrap too soon for his taste. With two divs side by side as we
are discussing, this allows the left to be as long as the sentence up to
the width of the body element. The right will be squeezed and will be
unusable under some circumstances. But in a table, the table always
seems to go for good sense and makes the right readable without undue
tricks.

Here is a URL that might help understand what I am saying:

<http://dorayme.890m.co m/alt/sideBySide.html >

--
dorayme
Jun 27 '08 #6
On 2008-06-14, dorayme <do************ @optusnet.com.a uwrote:
In article <sl************ *********@bowse r.marioworld>,
Ben C <sp******@spam. eggswrote:
>On 2008-06-13, dorayme <do************ @optusnet.com.a uwrote:
In article <sl************ *********@bowse r.marioworld>,
Ben C <sp******@spam. eggswrote:

On 2008-06-13, dorayme <do************ @optusnet.com.a uwrote:
In article
<69*********** *************** ********@8g2000 hse.googlegroup s.com>,
Roderik <em******@gmail .comwrote:

I was wondering if there is a good way to avoid a table but achieve
the following similar behaviour:

Two divs of equal height and undefined width next to each other with a
total width of 100%.
[...]
I slap my forehead. I was not relating what I did know about BFC to the
situation so it was good of you to catch this.

There is one downside that OP might consider if he uses the
overflow:hidden on the right div: if he has images there, or generally,
if there is any content that cannot wrap like long urls, they will be
cut off. If that is remotely likely, he can use overflow: auto instead.
Or perhaps just use auto to be safe.
Yes, good point.
There is another too that may be of interest. With either hidden or
auto, if the material on the left is not pretty short, the right will be
squeezed to be easily unusuable, see what happens in Safari or FF when
the left is given more than very few words.
Indeed-- that's why a table is much better for this kind of thing
in the general case (as your example also shows).

[...]
More interesting to assume that OP is not wanting a table because
material is not tabular.
In which case display: table-cell is the proper solution for data that
is not tabular but which you want displayed like a table.

Of course it doesn't work in IE but that doesn't change the principle of
the thing.
Jun 27 '08 #7

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

Similar topics

36
4657
by: toedipper | last post by:
Hello, I am designing a table of vehicle types, nothing special, just a list of unique vehicle types such as truck, lorry, bike, motor bike, plane, tractor etc etc For the table design I am proposing a single column table with a field name called vehicle_type and this will contain the vehicle type. Sot it will be
4
19787
by: Philipp Lenssen | last post by:
I have a site that runs in strict mode in IE6, and IE is making <td>s for simple two-digit numbers really wide. So I want to restrict it (and right-align it) by using <td class="number"> and .number { width: 10px; }. In Mozilla this works, but IE ignores this. Next to adding an invisible "0" precding one-digit numbers, what can I do to solve this?
4
3721
by: Hemant Shah | last post by:
Folks, Our client has a program that browses whole table from begining to end. The table has 1 million rows in it. REORGCHK does not show any problems. It has unique index defined on KEY0 column. If I use SELECT statement without OPTIMIZE FOR clause, then it uses temporary table to sort the data, but if I use OPTIMIZE clause then it uses index access without temporary table. If I use OPTIMIZE FOR more than 700 rows then it uses...
0
9683
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9529
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10231
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10013
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7550
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6792
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5443
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5576
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4119
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.