|
Problem with th / td widths
10-08-2010, 03:49 PM
|
Problem with th / td widths
|
Posts: 876
Name: Matt Pealing
Location: England, north west
|
I'm trying to style a table with CSS and having a nightmare doing so:
http://bit.ly/ccxu3V
I thought <td> and <th> elements always stayed 'in line' with each other? But the 3 <th> elements are not resizing based on the cells below them.
Also, I've set:
Code:
<th class="first" colspan="2">
On the first <th>, but it just seems to be ignoring the colspan completely!
Does anyone have any ideas what might be wrong?
Thanks
|
|
|
|
10-08-2010, 08:15 PM
|
Re: Problem with th / td widths
|
Posts: 481
Location: Gold Coast - Brisbane QLD, Australia
|
Strange behaviour - can you post a link or an example?
|
|
|
|
10-08-2010, 08:25 PM
|
Re: Problem with th / td widths
|
Posts: 876
Name: Matt Pealing
Location: England, north west
|
Yup, see the bit.ly link above.
Cheers.
|
|
|
|
10-08-2010, 09:21 PM
|
Re: Problem with th / td widths
|
Posts: 481
Location: Gold Coast - Brisbane QLD, Australia
|
bortram.css line 58, get rid of tr display:block;
|
|
|
|
10-09-2010, 10:17 AM
|
Re: Problem with th / td widths
|
Posts: 876
Name: Matt Pealing
Location: England, north west
|
Thanks that appears to fix the colspan issue etc, but then no matter what widths I apply to any <tr> elements they seem to be completely ignored! When I need them to stretch the full width of the containing <div>
Hmmmm
|
|
|
|
10-09-2010, 02:44 PM
|
Re: Problem with th / td widths
|
Posts: 9,007
Name: Tim Daily
Location: Apex, NC, US, Sol 3
|
Hooray! Someone's actually using a table for what it's intended for--data!
A colspan of 2, when the rest of your table has four data elements per row, will automatically squish your header to what? The first two columns. Make sense?
And, actually, you only apply colspan to a <td> that you want to take up more than one column. Otherwise, the <td>s naturally follow how many blocks you're putting in the grid.
You also didn't put a table opening in there.
tim 
Last edited by serandfae; 10-09-2010 at 07:17 PM..
Reason: correction
|
|
|
|
10-09-2010, 06:52 PM
|
Re: Problem with th / td widths
|
Posts: 481
Location: Gold Coast - Brisbane QLD, Australia
|
what are you talking about serandfae? <tr><th>---</th></tr> is perfectly valid markup! th is a table header cell, not row.
The correct markup for a table header row is:-
Code:
<table>
<thead>
<tr>
<th>Header cell</th>
</tr>
</thead>
</table>
pealo86: tr cannot have width. Apply width to table instead. If you want tr's to have differing widths, then you shouldn't use tables.
The parent container, #container .grid_12 has a width of 700px. A width applied to .grid_12 table of 100% will make the table expand to fill the width of .grid_12 minus border, padding and margin:-
.grid_12 table { width: 100%; }
|
|
|
|
10-09-2010, 07:28 PM
|
Re: Problem with th / td widths
|
Posts: 9,007
Name: Tim Daily
Location: Apex, NC, US, Sol 3
|
Corrected, regarding the <th>, by the way, <thead>, <tbody>, <tfoot> aren't universally supported. Why add in markup for fluff's sake?
There's nothing wrong with the remainder, and the most important thing: Where's the opening element for the table? What he's asking is why the headers aren't going above the things they're supposed to be over. Answer, old school: Put an empty cell in before the headings, take out the colspan, position within the cells as necessary, done.
tim 
|
|
|
|
10-09-2010, 08:01 PM
|
Re: Problem with th / td widths
|
Posts: 481
Location: Gold Coast - Brisbane QLD, Australia
|
It's not fluff, it's semantic html. A data table usually has a row of column names that place the data that follows into context, the table header.
What I would like to know is how that page validates as xhtml WITHOUT the opening table tag. Is the opening table tag optional I wonder?
http://validator.w3.org/check?verbos...%2Ffor-sale%2F
|
|
|
|
10-11-2010, 04:26 AM
|
Re: Problem with th / td widths
|
Posts: 297
Name: Michael Pehl
Location: Palma de Mallorca
|
No, <table> tag is necessary. Without <table> it is not valid code.
__________________
Chief Web Officer / Front-End Developer / System Engineer
Please login or register to view this content. Registration is FREE - Please login or register to view this content. Registration is FREE
|
|
|
|
10-11-2010, 11:42 AM
|
Re: Problem with th / td widths
|
Posts: 9,007
Name: Tim Daily
Location: Apex, NC, US, Sol 3
|
It did validate, though, but it shouldn't have. Probably a glitch in the validator, maybe it associated the open div with the closing for the table, but that's a guess.
However, even if all the markup was semantically correct, that does not mean that everything will function how you want it to. Validation is a tool to help you along, nothing more.
<table> is indeed necessary, and the likely culprit of the odd behavior, and the rest of the solution is still: Put an empty cell in before the headings, take out the colspan, position within the cells as necessary.
tim 
|
|
|
|
10-12-2010, 04:25 AM
|
Re: Problem with th / td widths
|
Posts: 408
Name: mushget
|
Can you post a link.
|
|
|
|
10-13-2010, 09:50 AM
|
Re: Problem with th / td widths
|
Posts: 876
Name: Matt Pealing
Location: England, north west
|
Thanks for the tips. I managed to style it using <thead>, <tbody> tags etc.
Although with regards to the <table> opening tag, it is in there  But in my code view in FF it's shifted to the right, so you might have missed it.
|
|
|
|
10-13-2010, 11:16 AM
|
Re: Problem with th / td widths
|
Posts: 481
Location: Gold Coast - Brisbane QLD, Australia
|
Glad u got it sorted. It's a good looking table. Could use some very subtle alternating row background colours though....
|
|
|
|
|
« Reply to Problem with th / td widths
|
|
|
| Thread Tools |
Search this Thread |
|
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|