440 likes | 600 Views
TABLES. Tables. Consider the following web-page. This web-page shows a H1 followed by a TABLE The TABLE has the following parts: a THEAD a TFOOT a TBODY a CAPTION The THEAD, TFOOT and TBODY contains TRs The TRs contain either THs or TDs Many of these have attributes. Tables.
E N D
Tables • Consider the following web-page
This web-page shows a H1 followed by a TABLE • The TABLE has the following parts: • a THEAD • a TFOOT • a TBODY • a CAPTION • The THEAD, TFOOT and TBODY contains TRs • The TRs contain either THs or TDs • Many of these have attributes
Tables • A table is delimited by <TABLE> and </TABLE> • Inside these tags we have a TBODY • We can also have a THEAD, TFOOT and a CAPTION if we wish
<HTML> <HEAD> <TITLE>Simple Table</TITLE> </HEAD> <BODY> <TABLE> <TBODY> <TR> <TD>10-11</TD> <TD>Maths</TD> </TR> <TR> <TD>11-12</TD> <TD>Physics</TD> </TR> </TBODY> </TABLE> </BODY> </HTML>
Tables and style • A <TABLE> tag has several attributes, some of which can be controlled by stylesheets and some of which cannot • I expect that, in the future, all attributes will be controllable by stylesheets
Rules between Table data • One <TABLE> attribute that still cannot be controlled by a stylesheet is the RULES attribute • This can take one of the following values:none (default), groups, cols, rows, all
<HTML> <HEAD> <TITLE>Simple Table</TITLE> </HEAD> <BODY> <TABLE RULES=“all”> <TBODY> <TR> <TD>10-11</TD> <TD>Maths</TD> </TR> <TR> <TD>11-12</TD> <TD>Physics</TD> </TR> </TBODY> </TABLE> </BODY> </HTML>
<HTML> <HEAD> <TITLE>Simple Table</TITLE> </HEAD> <BODY> <TABLE RULES=cols> <TBODY> <TR> <TD>10-11</TD> <TD>Maths</TD> </TR> <TR> <TD>11-12</TD> <TD>Physics</TD> </TR> </TBODY> </TABLE> </BODY> </HTML>
<HTML> <HEAD> <TITLE>Simple Table</TITLE> </HEAD> <BODY> <TABLE RULES=rows> <TBODY> <TR> <TD>10-11</TD> <TD>Maths</TD> </TR> <TR> <TD>11-12</TD> <TD>Physics</TD> </TR> </TBODY> </TABLE> </BODY> </HTML>
THEAD • A table head is used to explain the data in the TBODY
<HTML> <HEAD> <TITLE>Simple Table</TITLE> </HEAD> <BODY> <TABLE RULES=all> <THEAD> <TR> <TH> Time </TH> <TH> Subject </TH> </TR> </THEAD> <TBODY> <TR> <TD>10-11</TD> <TD>Maths</TD> </TR> <TR> <TD>11-12</TD> <TD>Physics</TD> </TR> </TBODY> </TABLE> </BODY> </HTML>
TFOOT • A table foot can be used to summarise the data in the table
<TABLE RULES=all> <THEAD> <TR> <TH> Time </TH> <TH> Subject </TH> </TR> </THEAD> <TFOOT> <TR> <TD> Number of hours </TD> <TD> 2 </TD> </TR> </TFOOT> <TBODY> <TR> <TD>10-11</TD> <TD>Maths</TD> </TR> <TR> <TD>11-12</TD> <TD>Physics</TD> </TR> </TBODY> </TABLE>
CAPTION • A caption describes the complete table
<TABLE RULES=all> <THEAD> <TR> <TH> Time </TH> <TH> Subject </TH> </TR> </THEAD> <TFOOT> <TR> <TD> Number of hours </TD> <TD> 2 </TD> </TR> </TFOOT> <CAPTION> Lecture Schedule </CAPTION> <TBODY> <TR> <TD>10-11</TD> <TD>Maths</TD> </TR> <TR> <TD>11-12</TD> <TD>Physics</TD> </TR> </TBODY> </TABLE>
TDs of Non-standard sizes • Sometimes, we need TDs that are wider or higher than the normal ones in a table
In the previous slide, the “Session” TDs in the TBODY were taller than the normal TDs • each of them was as tall as two normal rows • In the TFOOT, the “Number of hours” TD was wider than the normal TDs • it was as wide as two normal columns • This done by using two attributes of TDs: • the ROWSPAN attribute enables us to make taller than normal TDs • the COLSPAN attribute enables us to make wider than normal TDs
<TABLE RULES=all> <THEAD> <TR> <TH> Session </TH> <TH> Time </TH> <TH> Subject </TH> </TR> </THEAD> <TFOOT> <TR> <TD COLSPAN=2> Number of hours </TD> <TD> 4 </TD> </TR> </TFOOT> <CAPTION> Lecture Schedule </CAPTION> <TBODY> <TR> <TD ROWSPAN=2> Morning </TD> <TD>10-11</TD> <TD>Maths </TD> </TR> <TR> <TD>11-12</TD> <TD>Physics </TD> </TR> <TR> <TD ROWSPAN=2> Afternoon </TD> <TD>14-15</TD> <TD>Chem </TD> </TR> <TR> <TD>16-17</TD> <TD>Logic </TD> </TR> </TBODY> </TABLE>
Non standard THs • We can also have THs of non-standard sizes • We use the same ATTRIBUTES: • COLSPAN • ROWSPAN
<TABLE RULES=all> <THEAD> <TR> <TH COLSPAN=2> Lecture Time </TH> <TH> Lecture </TH> </TR> <TR> <TH> Session </TH> <TH> Time </TH> <TH> Subject </TH> </TR> </THEAD> <TFOOT> <TR> <TD COLSPAN=2> Number of hours </TD> <TD> 4 </TD> </TR> </TFOOT> <CAPTION> Lecture Schedule </CAPTION> <TBODY> <TR> <TD ROWSPAN=2> Morning </TD><TD>10-11</TD> <TD>Maths</TD> </TR> <TR> <TD>11-12</TD> <TD>Physics</TD> </TR> <TR> <TD ROWSPAN=2> Afternoon </TD> <TD>14-15</TD> <TD>Chem</TD></TR> <TR> <TD>16-17</TD> <TD>Logic</TD> </TR> </TBODY> </TABLE>
Using PADDING in TDs • We can use PADDING in TDs to provide some “white space” that makes the table content more legible
<STYLE> TD {PADDING-LEFT : 20 ; PADDING-RIGHT : 20} </STYLE>
Using stylesheets to affect layout of TD content • You should already have seen the TEXT-ALIGN attribute which can be used in stylesheets to affect content layout • We can, of course, use this to affect the layout of the contents of TDs and THs
<STYLE> TH {TEXT-ALIGN : right} TD {PADDING-LEFT : 20 ; PADDING-RIGHT : 20; TEXT-ALIGN : center} </STYLE>