List rendering

M

Michael

Hi.

Below I have included a minimal example of nested unordered lists.
When the page is rendered in Firefox, it looks exactly the way I want it. In
Internet Explorer though (even the newest version) there is a large space
between the "Second item" and the "First subitem".

Can anyone please tell me how to get around this problem without
invalidating the HTML code (I can fix it by removing the <LI> around the
nested list, but that will give me complaints from the W3C validator). Since
I'm using these lists to indicate my document structure (the lists will be
built dynamically from the <H[0-9]> headers), I'd like to get rid of the
spaces. Of course I can find another solution altogether to produce the
indentation, but I thought lists would be a clean way to do it.

Thanks a lot for any help you can offer

Michael.

----------------
Example (minimal useful correct code)

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<HTML>
<HEAD>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html;
charset=Windows-1251">
<TITLE>List test</TITLE>
<STYLE TYPE='text/css'>
ul.main {
padding-left: 10px;
border: solid 1px;
}

ul.sub {
padding-top: 0px;
padding-left: 10px;
border: dashed 1px;
}
</STYLE>
</HEAD>

<BODY>
<UL CLASS='main'>
<LI>First item</LI>
<LI>Second item</LI>
<LI>
<UL CLASS='sub'>
<LI>First subitem</LI>
</UL>
</LI>
</UL>
</BODY>
</HTML>
 
M

Martin Clark

Michael wrote...
Can anyone please tell me how to get around this problem without
invalidating the HTML code (I can fix it by removing the <LI> around the
nested list, but that will give me complaints from the W3C validator). Since
I'm using these lists to indicate my document structure (the lists will be
built dynamically from the <H[0-9]> headers), I'd like to get rid of the
spaces. Of course I can find another solution altogether to produce the
indentation, but I thought lists would be a clean way to do it.

I am not an expert - I expect one will come along in a minute with a
better answer - but when I have encountered a similar problem with a
list, I found the answer was to style the <li>.
Something like:
ul.main li, ul.sub li {
padding: 0;
}
or adjust the amount of padding until it looks right
(e.g. padding: 0.2em; ).
 
M

Michael

Martin Clark said:
Michael wrote...
Something like:
ul.main li, ul.sub li {
padding: 0;
}
or adjust the amount of padding until it looks right
(e.g. padding: 0.2em; ).

Thanks for your answer Martin. Unfortunately, by padding the list I can get
the items to space approximately evenly (though the space before the first
subitem is still larger than the space between the main items), but it's
justified in the space of the original box. Actually, I just want to remove
the space completely, making the main list less tall instead of keeping it's
height but spacing the items in it. If you know what I mean.

By the way, this doesn't change anything in FF, which is good, because FF
already does it the way I want.

Kind regards,

Michael.
 
M

Martin Clark

Michael wrote...
Thanks for your answer Martin. Unfortunately, by padding the list I can get
the items to space approximately evenly (though the space before the first
subitem is still larger than the space between the main items), but it's
justified in the space of the original box. Actually, I just want to remove
the space completely, making the main list less tall instead of keeping it's
height but spacing the items in it. If you know what I mean.
Try specifying all the padding for <ul>, rather than just the padding-
left, as in:
ul.main {
padding: 0 0 0 10px;
etc...
 
J

Jukka K. Korpela

Scripsit Michael:
Below I have included a minimal example of nested unordered lists.

Why no URL?
When the page is rendered in Firefox, it looks exactly the way I want
it. In Internet Explorer though (even the newest version) there is a
large space between the "Second item" and the "First subitem".

That's probably because you're setting just padding and not margin as well:
ul.main {
padding-left: 10px;
border: solid 1px;
}

ul.sub {
padding-top: 0px;
padding-left: 10px;
border: dashed 1px;
}

Browsers use (equivalents of) different default browser style sheets to
format lists in a particular way. The net effects might be roughly similar
but achieved using different properties for different elements. So if you
wish to change the rendering from the default, you should set both margin
and padding for both the list elements (ul, ol) and the list item elements
(li). Naturally you can set some of them zero.
 
J

John Hosking

Michael said:

Hi, back.
I'm using these lists to indicate my document structure (the lists will be
built dynamically from the <H[0-9]> headers), ...

I'm hoping you mean <H[1-6]> headers. Unless my brain slipped a cog
(again) today.
 
M

Michael

Martin said:
Try specifying all the padding for <ul>
I did. Still no good, sorry.
Why no URL?
Whatever you like :) http://www.xs4all.nl/~tba/test.html
I'm used to putting minimal examples inside the message so they'll still be
complete after the test page has disappeared again.
That's probably because you're setting just padding and not margin as well:
The margin doesn't seem to matter. Just check out my example and you'll see
what I mean.

John said:
Hi, back.
And hi, again.
I'm hoping you mean <H[1-6]> headers. Unless my brain slipped a cog (again)
today.
At least you have a brain. Sometimes I begin to doubt I have one myself :)
Obviously I meant [1-6].
By the way, this is unrelated to the actual question. In case you didn't
notice.

Anyway, the problem stands. Experts?

Regards

Michael.
 
M

Michael

Jonathan N. Little wrote
add:

UL.main, UL.sub { list-style: inside; }

then adjust as need.

Thanks, at least it looks the same everywhere.
Now I only need a trick to set the top margin to -(height of one line) :)

Actually I think I found a "fix" without the list-style: inside,
ul.sub { margin-top: expression("-2.5ex"); }

IE will evaluate the expression and use -2.5ex, which looks good.
FF will ignore the entire line and use it's default which already looked
okay.

Regards

Michael.
 
J

Jukka K. Korpela

Scripsit Michael:
Now I only need a trick to set the top margin to -(height of one
line) :)

Uh, why?
Actually I think I found a "fix" without the list-style: inside,
ul.sub { margin-top: expression("-2.5ex"); }

Is that supposed to solve a problem or create a time bomb?

You still haven't specified what you originally saw as the problem. If you
set all margins and paddings for ul and li elements zero, then set the
desired left padding (or margin) to whatever value you prefer (you should
prefer one expressed in em units, btw), what _is_ the problem?
 
M

Michael

Because I still get the white line, in both FF and IE
Is that supposed to solve a problem or create a time bomb?
It's supposed to work around my problem. Which didn't really work because
even with this ugly hack IE7 renders it as IE6 did without it.
You still haven't specified what you originally saw as the problem.
Well, check the image at http://www.xs4all.nl/~tba/test.html
The top image is what I want.
The bottom image is what IE does.
Notice the extra vertical space marked with a red bracket. I want to get rid
of it.
If you set all margins and paddings for ul and li elements zero
.... then IE still has the ugly white line

I just want the sublist to start on the SAME line as the parent list and not
on the NEXT line.
Which I can do by using <UL> <UL> ... </UL> </UL> instead of <UL> <LI> <UL>
.... </UL> </LI> </UL> but -- according to the W3C validator -- that would
break the HTML 4.01 standard.

Kind regards

Michael.
 
J

Jukka K. Korpela

Scripsit Michael:
Well, check the image at http://www.xs4all.nl/~tba/test.html
The top image is what I want.
The bottom image is what IE does.

OK, _now_ the question is understandable.
I just want the sublist to start on the SAME line as the parent list
and not on the NEXT line.

Basically you have a list item that _starts_ with an inner list. This is of
course syntactically allowed and might make sense in odd cases, but normally
there's some kind of a header for the inner list and the problem does not
occur. When it does, IE indeed seems to misbehave.

At least on IE 7, both in "standards" and "quirks" mode, the problem can be
fixed by adding the following artificial rule:
li { border: solid transparent 1px; }
(I guess I gets somehow rectified when it notices that it has to draw a
border around a list item. :))
 
M

Michael

Jukka K. Korpela said:
Scripsit Michael:

OK, _now_ the question is understandable.
My apologies for being so unclear. At least I finally did get the point
across :)
Basically you have a list item that _starts_ with an inner list.
Syntactically, yes. Structurally, it's just a nested list.
This is of course syntactically allowed and might make sense in odd cases,
but normally there's some kind of a header for the inner list and the
problem does not occur. When it does, IE indeed seems to misbehave.
Actually, The "Second item" caption should be the header of the inner list,
right?
At least on IE 7, both in "standards" and "quirks" mode, the problem can
be fixed by adding the following artificial rule:
li { border: solid transparent 1px; }
And as that also fixed the problem in my IE 6 and Firefox 1.5 as well as
Firefox 2.0, I think you just solved my problem. Soooo easy (and yet I don't
think I'd have found it).
(I guess I gets somehow rectified when it notices that it has to draw a
border around a list item. :))
I could make a mean remark about Internet Explorer now. But I won't. Just
glad it works.

Thanks so much Jukka!

Kind regards

Michael.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,065
Latest member
OrderGreenAcreCBD

Latest Threads

Top