473,396 Members | 1,785 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,396 software developers and data experts.

Formatting a table's text

I want to have a table based on the following html:

<table>

<colgroup>
<col class="tableColumnText"/>
<col class="tableColumnText"/>
<col class="tableColumnNumeric"/>
</colgroup>

<tr class="rowHeader">
<td>name</td>
<td>address</td>
<td>cost (£)</td>
</tr>
<tr class="rowOdd">
<td>me</td>
<td>here</td>
<td>500</td>
</tr>
<tr class="rowEven">
<td>you</td>
<td>there</td>
<td>50</td>
</tr>
<tr class="rowOdd">
<td>him</td>
<td>somewhere</td>
<td>80</td>
</tr>

</table>

I'd like to use the class="tableColumnNumeric" to align all text in
that column to be right aligned.

..tableColumnNumeric
{
text-align: right;
}

I'd like to use the class="tableColumnText" to align all text in that
column to be left aligned

..tableColumnText
{
text-align: left;
}

This is great, except I don't want these to affect column headings (in
<tr class="rowHeader">) - I want these to be CENTER aligned.

..rowHeader
{
text-align: center;
}

However...I can't get it to work...it's as if the column over-rides the
row.

Any suggestions? (IE6 main browser client)

Thanks in advance

Griff

Jul 21 '05 #1
4 3780
Griff wrote:
I want to have a table based on the following html:

<table>

<colgroup>
<col class="tableColumnText"/>
<col class="tableColumnText"/>
<col class="tableColumnNumeric"/>
</colgroup>

<tr class="rowHeader">
<td>name</td>
<td>address</td>
<td>cost (£)</td>
</tr>
<tr class="rowOdd">
<td>me</td>
<td>here</td>
<td>500</td>
</tr>
<tr class="rowEven">
<td>you</td>
<td>there</td>
<td>50</td>
</tr>
<tr class="rowOdd">
<td>him</td>
<td>somewhere</td>
<td>80</td>
</tr>

</table>

I'd like to use the class="tableColumnNumeric" to align all text in
that column to be right aligned.

.tableColumnNumeric
{
text-align: right;
}

I'd like to use the class="tableColumnText" to align all text in that
column to be left aligned

.tableColumnText
{
text-align: left;
}

This is great, except I don't want these to affect column headings (in
<tr class="rowHeader">) - I want these to be CENTER aligned.

.rowHeader
{
text-align: center;
}

However...I can't get it to work...it's as if the column over-rides the
row.

Any suggestions? (IE6 main browser client)


Yep. Assuming no bugs (I'm ignorant) review "cascading order",
especially selector specifity.

http://www.w3.org/TR/REC-CSS2/cascad...ascading-order
http://www.w3.org/TR/REC-CSS2/cascade.html#specificity

BugBear
Jul 21 '05 #2
Griff wrote:
I want to have a table based on the following html: <table>
<colgroup>
<col class="tableColumnText"/>
HTML compatible XHTML needs a space before the slash in empty elements.
<tr class="rowHeader">
<td>name</td>
<td>address</td>
<td>cost (£)</td>
</tr>
<thead>
<tr>
<th scope="col">Name</th>
etc.

might be better.
This is great, except I don't want these to affect column headings (in
<tr class="rowHeader">) - I want these to be CENTER aligned.


th { text-align: center; } will probably do the trick if you improve your
markup as suggested.
--
David Dorward <http://blog.dorward.me.uk/> <http://dorward.me.uk/>
Home is where the ~/.bashrc is
Jul 21 '05 #3
Griff (wrote something like this):

<table>
<col><col><col class="numeric">
<thead>
<tr><th>name <th>address <th>cost (£) </tr>
</thead><tbody>
<tr class="o"><td>me <td>here <td>500 </tr>
<tr class="e"><td>you <td>there <td> 50 </tr>
<tr class="o"><td>him <td>somewhere <td> 80 </tr>
</tbody>
</table>
I'd like to use the class="tableColumnNumeric" to align all text in
that column to be right aligned.


Put equal specific rulesets in the order you want or use better mark-up
and selectors.

th, td {text-align: left;}
thead th {text-align: center;}
col.numeric {text-align: right; /*should not work, but does in IE*/}
td:first-child+td+td {text-align: right; /*for CSS2 browsers*/}

Instead of "thead th" one could also use "tr:first-child th" (with a
single 'tbody' and no 'thead') or "th[scope='col']" (supported worse,
add attribute). CSS3 Selectors gives us "td:last-child" or
"td:nth-child(3)" and if the first cell in every row is actually a row
header ("scope='row'") one could use "th+td+td" and variations thereof.
With 'nth-child' you could also get rid of classes for odd and even rows
(actually only one is needed right now) without resorting to endless '+'
selectors.

Actually one would most likely want to use "text-align: '.'" (or ',')
for numeric/currency cells, but AFAIK still no browser supports that and
it has therefore been removed for CSS 2.1. It shouldn't harm to set it,
though:

td:first-child+td+td {text-align: right; text-align: '.'}

PS: Why would one use "tableColumnNumeric" as a class name?
Jul 21 '05 #4

Here the problem is the <tr> style class is over rided by the td style
class.

if you apply the style class for the individual td you can get proper
out put as you expect.
<style>
.rowHeader
{
text-align:center;
}

.tableColumnText
{
text-align: left;
}
.tableColumnNumeric
{
text-align: right;
}
</style>
<table border="1" width="100%">
<colgroup>
<!--<col class="tableColumnText"/>
<col class="tableColumnText"/>
<col class="tableColumnNumeric"/>-->
</colgroup>

<tr class="rowHeader">
<td>name</td>
<td>address</td>
<td>cost (£)</td>
</tr>
<tr class="rowOdd">
<td class="tableColumnText">me</td>
<td class="tableColumnText">here</td>
<td class="tableColumnNumeric">500</td>
</tr>
<tr class="rowEven">
<td class="tableColumnText">you</td>
<td class="tableColumnText">there</td>
<td class="tableColumnNumeric">50</td>
</tr>
<tr class="rowOdd">
<td class="tableColumnText">him</td>
<td class="tableColumnText">somewhere</td>
<td class="tableColumnNumeric">80</td>
</tr>

</table>
--
rarunms
------------------------------------------------------------------------
rarunms's Profile: http://www.highdots.com/forums/member.php?userid=270
View this thread: http://www.highdots.com/forums/showthread.php?t=1519437

Jul 21 '05 #5

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

Similar topics

4
by: Rob Meade | last post by:
Hi all, Ok - this leads on from speaking to a couple here and in the SQL server group... I've an application which allows the user to type in their text into a form, they add 'happy' tags...
2
by: Victor Bien | last post by:
W3C says somewhere that tables should not be used for formatting columns etc. but that style sheets should be used instead. This has a major unlearning/relearning implications for me (and just...
6
by: Kevin G. | last post by:
I'm not sure if this is possible, but if a page uses a CSS style sheet and you would still like to use good old <font> tags... is there a tag to tell the browser to ignore the CSS formatting just...
3
by: Jouke Langhout | last post by:
Hello all! For quite some time now, I've got the following problem: Access won't close properly when a user closes the application. An ACCESS process stays active and that process can only be...
8
by: Mike MacSween | last post by:
tblCourses one to many to tblEvents. A course may have an intro workshop (a type of event), a mid course workshop, a final exam. Or any combination. Or something different in the future. At...
4
by: deko | last post by:
I've heard it's best not to have any formatting specified for Table fields (except perhaps Currency), and instead set the formatting in the Form or Report. But what about Yes/No fields? When I...
4
by: Dave Brydon | last post by:
Access 2003 I have a combo box in my personnel table, which draws its data from a trade code table; the original field in the code table, is numeric, Long Integer, and formatted with 5 zero's . ...
6
by: shoo | last post by:
Any one know how to do this? thank Write a simple text-formatting program that produces neatly printed output from input text containing embedded command lines that determine how to format the...
1
by: msmcg | last post by:
I need to format the data in some textboxes using the Binding method with custom Currency and ShortDate format and parse handlers. Here is the code that I am using. I call it on the form load...
10
by: Coleen | last post by:
Hi all :-) I have a weird formatting problem with an HTML table that I am populating using VB.Net and HTML. Here is the snippet of code for the cell I'm trying to format: Dim...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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: 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
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
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
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.