HTML How to get thead and tbody to align
I'd like to have a scrollable <tbody> in my table with the header staying fixed. None of the "tips" I've found work for me (Firefox or IE). The following:
Code:
<table> The following: Code:
<table> I can't think of any combinations that will work other than using the 2nd example and hard-coding the width of header elements and body elements -- not what I want to do. Suggestions? |
One ham-fisted way would be to force the columns to be certain widths.
Code:
tr th { width: 10%; } Code:
tr th:nth-child(1) { width: 15%; } |
I got curious and searched a bit. It looks like if you set the scope attribute, it fixes column widths:
Code:
<thead> Source: https://www.w3.org/TR/WCAG20-TECHS/H63.html |
You're putting each cell on a seperate row
Try Code:
<table> Code:
<tr> Not sure what the CSS is doing for you. PS: set width on the <table> tag, not on the <tr> tag. Either Code:
<table width=500px> Code:
<table style="width: 500px"> |
Quote:
Quote:
Quote:
Hopefully you all, or someone, has some additional ideas. Otherwise, it seems like setting explicit widths on the columns is the only solution -- which I'm not going to do. In which case I think the thead and tbody tags need a bit more work to be really useful. |
Quote:
Code:
<tr><th>content</th></tr> and the only place you've set width is on the tbody tag, which is NOT the <table> tag Please try my suggestions to see if they give you what you want...then state specifically why they don't, if they don't. Does this help? |
Quote:
In any case, my actual table <thead> section does have two rows of multiple columns. I've also done one row of multiple columns, makes no difference. That link you referenced is exactly where I went in the first place, having never done anything with thead or tbody tags before. As an experiment, if you think you have a handle on how this should work, snag the html below and see if any of your ideas let the thead section line up with the tbody. Never mind explicitly setting column widths. I know I can make that work. They also line up OK if there is no block/height/overflow styling on the tbody, but that, I think, is rather the point of having the thead/tbody tags. Otherwise, it's just a normal table and thead/tbody adds nothing. Code:
<!DOCTYPE html> |
started fiddling, then i remembered:
some folks never search before posting. try this: HTML How to get thead and tbody to align |
Quote:
Code:
<style> |
I had read about javascript code about this topic now googled this.
https://codereview.stackexchange.com...igning-columns It's got "run script options" to check it out. Does it help? |
Quote:
I was hoping for something a bit less complex, but maybe that's as good as it gets. I'll experiment with that and post back. |
You might try asking on css-d -at- lists.css-discuss.org before sinking to javascript. That list, if any, would have people who should be able to figure out the answer to getting both the scrolling and the matching columns at the same time. If you do find an answer that is only CSS, please do remember to post it here.
|
I'm throwing in the towel on this one. I tried a simplified javascript based on AnanthaP's link:
Code:
function adjusttbody() Turbocapitalist, excellent suggestion with the maillist, but I'm done investing time in this. Besides, if there were a css only solution someone would have probably posted it. I'm on a number of lists and normally those list postings are findable. I suppose <tbody> could be useful for hiding sections of a table given multiple <tbody> statements, but for scrolling it seems near useless. I'll revert to an easier solution I've used in the past which is to have 2 tables: Code:
<table style="margin: 0; width: <nnn>px"> |
Actually, the <table><div> technique works like a champ with the auto-adjust javascript function. I don't even need to hard-code column widths unless I want to tweak. You do have to set the header table with and the <div> width to line up. To the devil with <thead><tbody>!
Code:
<!DOCTYPE html> |
What were the CSS specialists on the mailing list able to figure out? Or did they not respond?
|
All times are GMT -5. The time now is 03:59 PM. |