html table structure,Proper HTML Table Structure?

Almost embarrassed to ask, because I have never had a need to use tables much before...

Now I have a project that will require massive organized tables, go figure.

Suppose I have a table like this:

First NameLast NameAge

JillSmith50EveJackson94JohnDoe80

First of all, from what I have read, and

seem to be optional for grouping purposes, but is this basic set up correct?

It looks fine when displayed in a browser, but I wonder if my code actually structures elements correctly in the DOM? I.E. does the DOM correctly associate the

First Name with the 's that contain the first name data? I ask because I am going to need to rely on that to sort the tables later with javascript.

I apologize if this is really simple question. If there is a reference to a "proper table structure" article, i will accept that as well.

# Answer 1

4d350fd91e33782268f371d7edaa8a76.png

Your HTML markup is fine, except you should favor CSS classes rather than inline styles, and the border attribute is usually better as a style.

If you are ever curious if you have valid markup, you can use a validator tool to check. There is one available here, provided by W3C: http://validator.w3.org/

HTML is a presentational markup. There is no data association implicit in any given element -- that is to say, the td which you know contains the first name does not in any way associate itself with the heading which labels it visually. As far as HTML is concerned, you don't have data, just a bunch of words which it shapes and boxes and moves around on the screen.

This extends to javascript -- there is no association between the heading and table cells in DOM.

That said, sorting tables are a very common UI pattern, and you can find a large number of examples as well as existing plugins. I highly recommend that you consider an established plugin if you are going to use this for anything other than a learning experience. The plugin author has, presumably, already considered all the many ins and outs, gotchyas, and cross-browser considerations that you would have to take in to account if you tried to craft your own.

Documentation

# Answer 2

Best html table structure and css concept :

Header1Header2Header3

Footer1Footer2Footer3data1data2data3data1data2data3data1data2data3data1data2data3data1data2data3

css code and structure

html, body{font-family:Arial, Helvetica, sans-serif; font-size:12px;}

.table{border-collapse:collapse; width:100%}

.table thead th, .table tfoot th{text-align:center; background:#999; color:#FFFFFF;}

.table th, .table td{padding:5px; border:1px solid #ddd;}

.table tr:nth-child(even){background:#eee;}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值