473,503 Members | 2,174 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Different rendering with div versus table data

I'm trying to figure out how to avoid tables when presenting
a sidebar on an html 4 strict page, by using div instead. I've
run into a situation where I get different rendering of the
elements within the main div, depending on whether it is
contained within a <td> or a <div> -

http://www.chem.utoronto.ca/~dstone/test1.html
http://www.chem.utoronto.ca/~dstone/test2.html

I've been trying to understand why, particularly, the <ul>
and <dl> items are not indented the way I would have expected
when in the <div> element. If someone could explain why this
is so in plain English (not having had much luck with the
html 4 spec!) I would appreciate it. The table version
renders the way I would have expected both to do so, when
viewed in Firefox or Safari.

I've figured out how to move things around using CSS, but
I'd also like to know if there's a more elegant solution,
based on my having missed some important concept regarding
div elements?
May 17 '06 #1
11 4049
To further the education of mankind, David Stone <no******@domain.invalid>
vouchsafed:
I'm trying to figure out how to avoid tables when presenting
a sidebar on an html 4 strict page, by using div instead. I've
run into a situation where I get different rendering of the
elements within the main div, depending on whether it is
contained within a <td> or a <div> -

http://www.chem.utoronto.ca/~dstone/test1.html
http://www.chem.utoronto.ca/~dstone/test2.html

I've been trying to understand why, particularly, the <ul>
and <dl> items are not indented the way I would have expected
when in the <div> element. If someone could explain why this
is so in plain English (not having had much luck with the
html 4 spec!) I would appreciate it. The table version
renders the way I would have expected both to do so, when
viewed in Firefox or Safari.

I've figured out how to move things around using CSS, but
I'd also like to know if there's a more elegant solution,
based on my having missed some important concept regarding
div elements?


In case 2, you need to add a margin on the li's, like:

li { margin-left:2em; }

Why? My own feeling is that it's a flaw in the <ul> element which does not
respect the boundaries of the <div> when adjacent to the float. Even
setting "position:relative;" on the div didn't help, and if you border the
<ul>, you see it stretches all the way across the page. Interesting
conundrum, though.

--
Neredbojias
Infinity has its limits.
May 18 '06 #2
David Stone wrote:
I've run into a situation where I get different rendering of the
elements within the main div, depending on whether it is
contained within a <td> or a <div> -

http://www.chem.utoronto.ca/~dstone/test1.html
http://www.chem.utoronto.ca/~dstone/test2.html


The second DIV in test2.html extends *underneath* the first DIV. You can
see this by adding "border:2px solid magenta" to the second DIV and then
removing the background from the first.

Thus the left margin of your LI and DD elements are underneath the first
DIV.

The solution is to fix a width to your first DIV -- 10em seems appropriate
in this case -- and then set the margin-left on the second DIV a little
higher than that (to take padding and margin into account) -- say 12em.

If we put the background back in, we've now got:

..sbmenu {
text-align: center;
float: left;
background-color: silver;
padding: 0.5em;
margin-right: 1em;
width: 10em;
}
..second-div {
margin-left: 12em;
border: 2px solid magenta;
}
dt {
font-weight: bold;
}

(Remember to add "class=second-div" to the second DIV!). Reload and
everything will be hunky dory (except for the garish border).

The reason this issue doesn't occur with the table-based version is that
the two table cells don't overlap.

This is really a question for comp.infosystems.www.authoring.stylesheets
though.

--
Toby A Inkster BSc (Hons) ARCS
Contact Me ~ http://tobyinkster.co.uk/contact

May 18 '06 #3
In article <sj************@ophelia.g5n.co.uk>,
Toby Inkster <us**********@tobyinkster.co.uk> wrote:
David Stone wrote:
I've run into a situation where I get different rendering of the
elements within the main div, depending on whether it is
contained within a <td> or a <div> -

http://www.chem.utoronto.ca/~dstone/test1.html
http://www.chem.utoronto.ca/~dstone/test2.html
The second DIV in test2.html extends *underneath* the first DIV. You can
see this by adding "border:2px solid magenta" to the second DIV and then
removing the background from the first.


That depends on the browser settings, I suspect - certainly, on my
setup the second div is actually shorter than the first. The same is
true of the original pages where I ran into this problem, and from
which I derived the test pages.
Thus the left margin of your LI and DD elements are underneath the first
DIV.

But shouldn't the dd be positioned relative to the dt immediately
prior to it in the document flow? Similarly, I would have expected
the li's in the ul to be positioned relative to the immediately
proceeding paragraph; hierarchically, this makes more sense than
positioning relative to the enclosing div.
The solution is to fix a width to your first DIV -- 10em seems appropriate
in this case -- and then set the margin-left on the second DIV a little
higher than that (to take padding and margin into account) -- say 12em.

If we put the background back in, we've now got:

.sbmenu {
text-align: center;
float: left;
background-color: silver;
padding: 0.5em;
margin-right: 1em;
width: 10em;
}
.second-div {
margin-left: 12em;
border: 2px solid magenta;
}


That works, as you say:

http://www.chem.utoronto.ca/~dstone/test3.html

...but I still can't shake the feeling that each dd ought to be
positioned relative to its preceding dt within a dl!

Is there a way in html (not css) to specify the flow of elements
other than what I did originally? I tried nesting the p, dl and
ul inside divs or blockquotes within the main div, but that didn't
work either.

I'm beginning to understand why so many people use tables for layout...
May 18 '06 #4
David Stone wrote:
Toby Inkster wrote:
The second DIV in test2.html extends *underneath* the first DIV.
That depends on the browser settings, I suspect


It doesn't depend on browser settings -- it's underneath in any
standards-compliant CSS-implementing browser.
certainly, on my setup the second div is actually shorter than the
first.


Same here -- shorter -- that doesn't stop it extending underneath the
first DIV on the left though.

--
Toby A Inkster BSc (Hons) ARCS
Contact Me ~ http://tobyinkster.co.uk/contact

May 18 '06 #5
In article <0b************@ophelia.g5n.co.uk>,
Toby Inkster <us**********@tobyinkster.co.uk> wrote:
David Stone wrote:
Toby Inkster wrote:
The second DIV in test2.html extends *underneath* the first DIV.


That depends on the browser settings, I suspect


It doesn't depend on browser settings -- it's underneath in any
standards-compliant CSS-implementing browser.
certainly, on my setup the second div is actually shorter than the
first.


Same here -- shorter -- that doesn't stop it extending underneath the
first DIV on the left though.


Do you mean "underneath" in terms of document flow, rather than
"underneath" in terms of appearance of the rendered page? If so,
then I understand, although "underneath" is perhaps not the best
term to describe this. ("Follows" might be a more appropriate
term.)
May 19 '06 #6
David Stone wrote:
Do you mean "underneath" in terms of document flow, rather than
"underneath" in terms of appearance of the rendered page? If so,
then I understand, although "underneath" is perhaps not the best
term to describe this. ("Follows" might be a more appropriate
term.)


I mean underneath in terms of overlapping:

+-----------+------------------+
| | |
| | |
| | |
| - - - |------------------+
| |
| |
| |
+-----------+
--
Toby A Inkster BSc (Hons) ARCS
Contact Me ~ http://tobyinkster.co.uk/contact

May 19 '06 #7
In article <nn************@ophelia.g5n.co.uk>, Toby Inkster
<us**********@tobyinkster.co.uk> wrote:
David Stone wrote:
Do you mean "underneath" in terms of document flow, rather than
"underneath" in terms of appearance of the rendered page? If so,
then I understand, although "underneath" is perhaps not the best
term to describe this. ("Follows" might be a more appropriate
term.)


I mean underneath in terms of overlapping:

+-----------+------------------+
| | |
| | |
| | |
| - - - |------------------+
| |
| |
| |
+-----------+


That's a lot clearer!
May 20 '06 #8
On Fri, 19 May 2006 19:52:07 +0100 Toby Inkster <us**********@tobyinkster.co.uk> wrote:

| David Stone wrote:
|
|> Do you mean "underneath" in terms of document flow, rather than
|> "underneath" in terms of appearance of the rendered page? If so,
|> then I understand, although "underneath" is perhaps not the best
|> term to describe this. ("Follows" might be a more appropriate
|> term.)
|
| I mean underneath in terms of overlapping:
|
| +-----------+------------------+
| | | |
| | | |
| | | |
| | - - - |------------------+
| | |
| | |
| | |
| +-----------+

Is there anything wrong with doing this intentionally to create effects
like the shadows on:
http://linuxhomepage.com/
or in this sample:
http://phil.ipal.org/usenet/ciwas/20...corners-2.html
?

--
-----------------------------------------------------------------------------
| Phil Howard KA9WGN | http://linuxhomepage.com/ http://ham.org/ |
| (first name) at ipal.net | http://phil.ipal.org/ http://ka9wgn.ham.org/ |
-----------------------------------------------------------------------------
May 21 '06 #9
phil-news-nospam wrote:
Is there anything wrong with doing this intentionally to create effects
like the shadows on:
http://linuxhomepage.com/


No, but the OP wasn't doing it intentionally -- he was doing it
accidentally and seeing some undesired side-effects.

I often use a DIV-within-DIV trick with a little relative positioning to
create a drop-shadow effect.

<div id=outer>
<div id=inner>...</div>
</div>

#outer {
padding: 0;
position: relative; top: 3px; left: 3px;
background: silver;
}
#inner {
margin: 0;
position: relative; top: -6px; left: -6px;
background: white;
border: 1px solid black;
padding: 0.5em;
}

--
Toby A Inkster BSc (Hons) ARCS
Contact Me ~ http://tobyinkster.co.uk/contact

May 21 '06 #10
On Sun, 21 May 2006 07:33:28 +0100 Toby Inkster <us**********@tobyinkster.co.uk> wrote:
| phil-news-nospam wrote:
|
|> Is there anything wrong with doing this intentionally to create effects
|> like the shadows on:
|> http://linuxhomepage.com/
|
| No, but the OP wasn't doing it intentionally -- he was doing it
| accidentally and seeing some undesired side-effects.
|
| I often use a DIV-within-DIV trick with a little relative positioning to
| create a drop-shadow effect.
|
| <div id=outer>
| <div id=inner>...</div>
| </div>
|
| #outer {
| padding: 0;
| position: relative; top: 3px; left: 3px;
| background: silver;
| }
| #inner {
| margin: 0;
| position: relative; top: -6px; left: -6px;
| background: white;
| border: 1px solid black;
| padding: 0.5em;
| }

For more fun, make the apparently height of the front ("inner" in your IDs)
rise up when the pointer hovers (on browsers that support the necessary CSS
standard to do so). Now, move the point around in the corners and see if
you can make it oscillate. If you applied the hover to the boxes that do
the moving (e.g. hover changes the relative offset), you can do that at 2
of the corners. The fix I use is to wrap one more box around the whole
thing and make everything work from that.

<div id=riser>
<div id=outer>
<div id=inner>...</div>
</div>
</div>

#riser #outer {
padding: 0;
position: relative; top: 3px; left: 3px;
background: silver;
}
#riser #inner {
margin: 0;
position: relative; top: -6px; left: -6px;
background: white;
border: 1px solid black;
padding: 0.5em;
}
#riser:hover #outer {
position: relative; top: 4px; left: 4px;
}
#riser:hover #inner {
position: relative; top: -8px; left: -8px;
}

Actually, I just avoid IDs or classes on the inner 2 DIVs and use
a class on the added one and work it that way:

..riser>* {
padding: 0;
position: relative; top: 3px; left: 3px;
background: silver;
}
..riser>*>* {
margin: 0;
position: relative; top: -6px; left: -6px;
background: white;
border: 1px solid black;
padding: 0.5em;
}
..riser:hover>* {
position: relative; top: 4px; left: 4px;
}
..riser:hover>*>* {
position: relative; top: -8px; left: -8px;
}

Probably won't work in web standards challenged browsers.

One annoying thing about this is one cannot just use CSS to create a
style to an existing single HTML element, such as locally overriding
the style on a page obtained from online. What I would like to see
is an enhancement to CSS in the next version that allows the _effect_
of inserting extra "virtual elements". There would be selectors to
select the specific real element, as well as a specific virtual element
by its index number. Then the above could be done like:

<div class="riser">...</div>

..riser {
virtual-elements: div 2; /* add 2 virtual DIV elements */
}
..riser[1] {
padding: 0;
position: relative; top: 3px; left: 3px;
background: silver;
}
..riser[2] {
margin: 0;
position: relative; top: -6px; left: -6px;
background: white;
border: 1px solid black;
padding: 0.5em;
}
..riser:hover[1] {
position: relative; top: 4px; left: 4px;
}
..riser:hover[2] {
position: relative; top: -8px; left: -8px;
}

--
-----------------------------------------------------------------------------
| Phil Howard KA9WGN | http://linuxhomepage.com/ http://ham.org/ |
| (first name) at ipal.net | http://phil.ipal.org/ http://ka9wgn.ham.org/ |
-----------------------------------------------------------------------------
May 24 '06 #11
phil-news-nospam wrote:
.riser {
virtual-elements: div 2; /* add 2 virtual DIV elements */
}


Adding in two extra DIV elements is really just a workaround for the
problem that the effect that you want can't be achieved without adding in
some redundant elements.

Surely better for CSS 3 to solve that problem directly (e.g. allowing drop
shadows) rather than indirectly (allowing the inserion of extra nodes into
the DOM for styles to be attached to).

--
Toby A Inkster BSc (Hons) ARCS
Contact Me ~ http://tobyinkster.co.uk/contact

May 27 '06 #12

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

Similar topics

6
5404
by: g pavlov | last post by:
W3C recommendations notwithstanding (see http://w3.org/TR/html401/appendix/notes.html#notes-tables) I can't seem to persuade either of the leading browsers to do true incremental table loading....
6
3791
by: V | last post by:
I have found that when I have a composite control that uses the CreateChildControls method, on a regular page load, Page_Load executes before CreateChildControls, but on a postback it is the...
3
3826
by: Vithar | last post by:
I have a database that is being used as sort of a reports data warehouse. I use DTS packages to upload data from all the different sources. Right now I have it truncating the tables and appending...
6
1922
by: david epsom dot com dot au | last post by:
I have a report with an OLE bound frame. A bitmap has been pasted into the bound field. The bitmap displays and prints differently on different computers. In particular, the alignment is...
3
3018
by: David Whitney | last post by:
All: I have a control that renders a table. As the table is rendered, each row in the table is constructed by creating a run-time (dynamic) object that is derived from an HtmlTableRow. The row...
2
4157
by: Jon Lapham | last post by:
I have a table that stores TEXT information. I need query this table to find *exact* matches to the TEXT... no regular expressions, no LIKE queries, etc. The TEXT could be from 1 to 10000+...
1
1769
by: hansyin | last post by:
HI, I got a problem about restoring data in mysql: I have 2 or more PCs installed with mysql database, with same or almost same table structure, but with different data. Can I combine those data...
61
4667
by: phil-news-nospam | last post by:
Why does SVG need a different tag than other images? IMHO, SVG should be implemented as an image type just like any other image type, allowing it to work with <img> tags, and ... here is the...
3
2185
by: UJ | last post by:
I had somebody (who was an idiot) tell me that tables are slow in rendering? That you shouldn't do things like tables inside of tables. Is that true? I think she didn't know what she was...
0
7205
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,...
0
7093
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
7287
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
7467
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...
1
5022
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...
0
3177
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...
0
3168
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1521
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 ...
1
746
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.