By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
449,247 Members | 1,250 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 449,247 IT Pros & Developers. It's quick & easy.

Right aligning text in a table

P: n/a
I am writing some HTML and CSS that will eventually be produced by a program
for running fencing tournaments.

Everything is fine apart from column alignment for numbers. Have a look at
http://murorum.demon.co.uk/engarde/poules.html. The V/M column should be
centred, while the Indicator and HS columns should be right aligned.

Since I was defining column widths within a <colgroup> I thought it would be
cleaner to define the alignment of these columns there too. Is this not
possible, or am I doing something wrong?

--
Colin Walls

Remove the pink meat to mail me
Nov 4 '05 #1
Share this Question
Share on Google+
6 Replies


P: n/a
On Fri, 4 Nov 2005, Colin Walls wrote:
Everything is fine apart from column alignment for numbers. Have a look at
http://murorum.demon.co.uk/engarde/poules.html.
| Object not found!
| The requested URL was not found on this server.

Oh, perhaps you meant

| http://murorum.demon.co.uk/engarde/poules.html

without the final full stop.
Since I was defining column widths within a <colgroup> I thought it would be
cleaner to define the alignment of these columns there too. Is this not
possible, or am I doing something wrong?


Alignment in <col> works only in Internet Explorer. For CSS-conforming
browsers like Mozilla, you need to define the alignment through
"td+td", "td+td+td", etc. See my example at
http://www.unics.uni-hannover.de/nht...-alphabet.html
http://www.unics.uni-hannover.de/nht...able8.css.text

--
Netscape 3.04 does everything I need, and it's utterly reliable.
Why should I switch? Peter T. Daniels in <news:sci.lang>

Nov 4 '05 #2

P: n/a
Andreas Prilop wrote:
On Fri, 4 Nov 2005, Colin Walls wrote:

Since I was defining column widths within a <colgroup> I thought it would
be cleaner to define the alignment of these columns there too. Is this
not possible, or am I doing something wrong?


Alignment in <col> works only in Internet Explorer. For CSS-conforming
browsers like Mozilla, you need to define the alignment through
"td+td", "td+td+td", etc. See my example at
http://www.unics.uni-hannover.de/nht...-alphabet.html
http://www.unics.uni-hannover.de/nht...able8.css.text


This would be a pain, since the central block can have a variable number of
columns.

I must admit to still being baffled. Looking the the HTML 4.01 documentation
at w3.org implies what I am doing is correct. However, when I convert my
code to 4.01 strict I still don't get the formatting I want.

I think the only way forward is to add alignment to the cells, rather than
put them at the <colgroup> level.

--
Colin Walls

Remove the pink meat to mail me
Nov 5 '05 #3

P: n/a
On Sat, 5 Nov 2005, Colin Walls wrote:
Andreas Prilop wrote:
Alignment in <col> works only in Internet Explorer.

It may produce the desired effect, but it does not conform to the
interworking specification, so it cannot be said to truly "work".

It's unfortunate, but the table cell is not a true descendant of col
nor colgroup, and the limited extent to which the (CSS) specification
says that cells can be influenced by properties applied to col /
colgroup is set out in the spec.
I must admit to still being baffled. Looking the the HTML 4.01
documentation at w3.org implies what I am doing is correct.
I'm not sure which part of the HTML spec you are looking at, but the
right place to find out about CSS is in a CSS spec.

Currently there's a bit of a hiatus, since the original CSS2
specification isn't exactly implemented by browsers, whereas the
CSS2.1 proposal (which still has the status of a working draft,
according to what it says itself) contains not only, on the one hand,
some dumbing-down of the things which were in CSS2 but did not get
widely implemented, but also, on the other hand, some additions which
may or may not be found widely implemented. So, in general, 2.1
should be read with some care and reservation.

However, on this point I think the 2.1 spec can be taken as a usable
basis - see section 17.3:

http://www.w3.org/TR/CSS21/tables.html#q4
However, when I convert my code to 4.01 strict I still don't get the
formatting I want.
I'm not quite sure what you mean by that, but if you mean what I
suspect that you mean, then there may be a misunderstanding here...

See http://www.w3.org/TR/CSS21/cascade.html#q13

As it says, the presentational attributes of HTML "transitional" might
be treated by a client agent as equivalent to some corresponding CSS
rules, but these are supposed to have zero specificity, meaning that
if CSS applies any different value for that property then the CSS
specification will supervene.

So, taking the HTML presentational attributes away should never modify
anything which has been explicitly specified by CSS - provided, of
course, that the client agent is applying the CSS. The HTML
presentational attributes are only (meant to be) applied in situations
where no relevant CSS style rule is applicable, or where CSS isn't
applied at all.

In short: converting from HTML Transitional to HTML Strict isn't in
itself going to solve the problems that you're having with your CSS.

[Don't get me wrong: using HTML Strict *is* a good idea for new
developments - or at least aiming for it while using at worst a few
carefully controlled relics from Transitional for well-reasoned
compatibility purposes, and some here are sure to contradict me on
even that. I'm saying no more than that converting your HTML from
transitional to strict isn't an answer to the problem we're currently
discussing, no matter how good an idea it is for other reasons.]
I think the only way forward is to add alignment to the cells,
rather than put them at the <colgroup> level.


Yes, which is what Andreas already said. Using td+td, td+td+td etc.
as selectors can be a useful trick with sufficiently advanced
browsers, to avoid having to apply a class to every table cell in the
relevant column and thereby cluttering the HTML. Those which don't
implement the td+td notation are meant to ignore it: the results will
be no worse than with a browser which doesn't implement CSS at all, or
has its CSS disabled by the user for their own good reasons.

There may be other ways available, depending on circumstances - for
example, if a certain column always contains a specific kind of
content (let's say <pre> or <blockquote> or something) then a CSS
selector such as "td pre" could be useful, even for browsers which
don't implement the td+td... notation.

regards
Nov 5 '05 #4

P: n/a
Alan J. Flavell wrote:
On Sat, 5 Nov 2005, Colin Walls wrote:
Andreas Prilop wrote:
> Alignment in <col> works only in Internet Explorer.


It may produce the desired effect, but it does not conform to the
interworking specification, so it cannot be said to truly "work".

It's unfortunate, but the table cell is not a true descendant of col
nor colgroup, and the limited extent to which the (CSS) specification
says that cells can be influenced by properties applied to col /
colgroup is set out in the spec.


The syntax really doesn't help where I have multiple tables of variable
width in the same document.

Assume I am running a very small competition, 13 people. I would divide
these into two poules, 1 of 6 and 1 of 7. I want to present the results in
the tabular form I have shown, with the last three columns having
alignments of centre, right and right. The centre block (the one with all
the V's in) will now have either 6 or 7 columns. Both tables need
presenting in the same document (otherwise it gets messy when you want to
create a document per poule for a competition of 200+ people).

How would you go about this?

--
Colin Walls

Remove the pink meat to mail me
Nov 8 '05 #5

P: n/a
On Tue, 8 Nov 2005, Colin Walls wrote:
Assume I am running a very small competition, 13 people. I would
divide these into two poules, 1 of 6 and 1 of 7. I want to present
the results in the tabular form I have shown, with the last three
columns having alignments of centre, right and right. The centre
block (the one with all the V's in) will now have either 6 or 7
columns. Both tables need presenting in the same document (otherwise
it gets messy when you want to create a document per poule for a
competition of 200+ people).
What follows is mere theory. Whether it's practical to deploy on the
web in this form, I wouldn't care to say. MSIE6 seems to harmlessly
ignore the fun, though, so it's "working as designed" for a back-level
browser, which is nice (and not at all the sort of behaviour that one
has come to expect from IE6 !).
How would you go about this?


Well, if we can agree that there is some reasonable maximum
number of central columns, then I would write td+td styles for all
of the possibilities.

If one did nothing more, of course, the styles for the central columns
would leak over into the later columns. So I would write some rules
with higher specificity for those right-hand columns.

There's an initial sketch, based on your original, at
http://ppewww.ph.gla.ac.uk/~flavell/tests/poules.html

(view this in Mozilla, or in Opera 8.5 etc.).

I simply made a copy of the first table, ripping out its last row and
the corresponding column, in order to have something to test. Then I
did the same again. I ignored whether the resulting data makes any
kind of sense, obviously.

The empty column on the right of the central section is coming out
styled like the central section, of course - you could assign it a
class, and style that (or maybe better, you could work with decorative
border styles, instead of faking a border with empty columns).

cheers
Nov 8 '05 #6

P: n/a
On Tue, 8 Nov 2005, Alan J. Flavell wrote:
On Tue, 8 Nov 2005, Colin Walls wrote:

Assume I am running a very small competition, 13 people. I would
divide these into two poules, 1 of 6 and 1 of 7. I want to present
the results in the tabular form I have shown, with the last three
columns having alignments of centre, right and right.


There's an initial sketch, based on your original, at

[snip]

OK, continuing on from the early sketch, towards your original
question. Because of the variable numbers of columns in the middle
part: if we want to style the right-hand columns using td+td...
notation, then we still need *something* to key on, which would show
CSS that the middle section was done.

Based on your original, I've chosen to key it on the empty cell
that you're using at the right hand side of the middle section,
and I've chosen to apply 'class="k"' to that in order to key on it.

The further classes "centre" and "nombre" aren't necessary if we
follow this plan.

So now we can apply styles to td.k, td.k+td, td.k+td+td , and so on,
in order to style the right-hand columns, and the test page for that
is at http://ppewww.ph.gla.ac.uk/~flavell/tests/poules2.html

MSIE6 still behaves like a back-level browser. Which in this case
means it doesn't honour the desired alignments of the right-hand
columns, in the way that Mozilla (Gecko) and Opera do so. Clearly,
you might consider that too serious a fault to want to use this method
for general web use. I only did this as a demonstration of something
that's feasible with >=CSS2 if one wants to.

(As I commented before, I think it would be somewhat better to do the
decoration via CSS, rather than by including columns of empty cells as
is being done here, but that was aside from the main diet here, so I
left that alone for the purposes of the demonstration).

hope that goes some way to addressing your original question.

cheers
Nov 9 '05 #7

This discussion thread is closed

Replies have been disabled for this discussion.