Presentation is loading. Please wait.

Presentation is loading. Please wait.

1 Tables and Lists. 2 Are Tables still needed? Tables were once used to help structure and style our pages CSS now replaces most of the old uses for tables.

Similar presentations


Presentation on theme: "1 Tables and Lists. 2 Are Tables still needed? Tables were once used to help structure and style our pages CSS now replaces most of the old uses for tables."— Presentation transcript:

1 1 Tables and Lists

2 2 Are Tables still needed? Tables were once used to help structure and style our pages CSS now replaces most of the old uses for tables We can still use tables but should use CSS to structure and format our content When using tables, use CSS to add style and formatting

3 3 How Tables are being used One way tables are being used is with sliced graphics, which are placed within a table to maintain their layout and seamless appearance Another way tables are still being used are with forms to keep forms and their fields neatly organized Probably the most common use for tables is to display data in a tabular form

4 4 Tables being used with XHTML Displaying data in a tabular form is now one of the most common uses for tables Displaying data within a table mimics the appearance of spreadsheets Tables are made up of columns (vertical) and rows (horizontal) for displaying data in a useful and presentable way Many websites have to use tables in order to display their database data

5 5 Tables with XHTML A table consists of opening and closing elements A table can contain rows (table rows) and cells (table data) within each row The above example contains two rows, with each each row containing two cells

6 6 Tables with XHTML A table consists of opening and closing elements The cells in the first row in the table are often referred to as the table header cells, using the header tags (instead of ) will make any text inside these rows appear bold Within the table tags you have table rows and within each row you have table cells, also known as table data or columns, you can have multiple table cells as well as multiple rows in your table

7 7 Tables with XHTML Table example: Above Table has four rows, first row uses a header and each row has only two cells (two elements or columns)

8 8 Table example with sample data Artists Songs Joe Smith Singin Mary Time Raps Tim Jazz Happy

9 9 Table example with sample data

10 10 Adding a table summary is optional and doesnt appear in the webpage but helps with accessibility by screen readers

11 11 Adding a table caption is optional but will display in the browser, usually above the table Caption goes inside the elements You can add the caption after the opening table tag, the caption will appear above the table Artists Songs Joe Smith Singin Mary Time Raps Tim Jazz Happy

12 12 Styling tables, add style to CSS table { margin-left: 20px; margin-right: 20 px; border: thin solid black; caption-side: bottom; } td, th { border: thin dotted gray; padding: 5px; } caption { font-style: italic; padding-top: 8px; }

13 13 Styling the table using CSS, what is styled? Table is displayed with a thin black border Table cells have a thin dotted gray style border There is a margin on both sides of the table There is padding in each table cell Caption is also styled caption-side property displays caption at bottom of table

14 14 Table cells and their appearance Table cells can have padding, border, and border spacing td { border: 1px dotted red; padding: 5px; border-spacing: 5px; }

15 15 Table cells appearance Content Padding Content Border-spacing Border

16 16 border-spacing: property The space in between the cells is known as border-spacing Table cells dont have margins, they instead have spacing around their borders Defined over the entire table You cant set the margin of an individual cell You can set a common spacing around all cells td { border-spacing: 5px; }

17 17 border-spacing: property There is a way to define different border spacing on the vertical than the horizontal td{ border-spacing: 10px 30px; }

18 18 border-spacing: property problems Limitations and problems with border spacing Border spacing not supported on Internet Explorer version 6

19 19 Border-collapse property An alternative to border-spacing is the border-collapse property Collapses the borders so that there is no border spacing at all Browser will ignore any border spacing you have set on the table Combines two borders that are right next to each other into one border Border-collapse property table{ border-collapse: collapse; }

20 20 Background-color property Adding color to a table can improve readability of the content The following adds a background color only to the table header cells th{ background-color: #cc6600; }

21 21 Background-color property Adding alternating colors to each row in your table Enables viewers to more easily read one row when multiple rows of content are being displayed Define a new class and call rowcolor.rowcolor { background-color: #fcba7a; }

22 22 Background-color property Add the class attribute to each alternating row you want colored Artists Songs Joe Smith Singin Mary Time Raps Tim Jazz Happy Don Loud Scremin

23 23 rowspan attribute Using rowspan with tables enables a cell to span more than one row Useful for making table data appearance more readable and more presentable Use for visually showing data repeats of a span of rows without actually repeating data on each row A good example would be a class schedule where a class spans several hours

24 24 rowspan attribute Monday Tuesday GRC 275 open GRC 175 GRC 103 GRC 188 GRC 101 GRC 156 GRC 182

25 25 rowspan attribute When using rowspan the cells which rowspan is being applied to do not have elements listed in the row(s) below them that are being spanned onto

26 26 rowspan attribute For example, the second row shown below has GRC 275 spanning two rows, so, the third row which shows GRC 175 doesnt display a for the GRC 275 cell from the row above, instead it is displaying a for the other cell open which isnt being spanned two rows Monday Tuesday GRC 275 open GRC 175

27 27 colspan attribute Using colspan with tables enables a column to span more than one column Useful for making table data appearance more readible and more presentable where a particular value spans more than one column

28 28 colspan attribute Monday Tuesday GRC 275 GRC 175 open GRC 188 GRC 101 GRC 156 GRC 182

29 29 colspan attribute When using colspan, the cells which colspan is being applied to remove the original columns following the cell it was applied to

30 30 colspan attribute For example, the second row shown below has GRC 275 spanning two columns, so, the second column which normally would show below Tuesday doesnt display and therefore the second row only has one table cell listed Monday Tuesday GRC 275 GRC 175 open

31 31 Using both colspan and rowspan attributes You can use both colspan and rowspan in the same table Make sure all the account for both the row and column spans For example, remove s from both row and column where applicable for spans to occur

32 32 Changing text alignment You can change the alignment of the data in your table cells with the text-align and vertical-align CSS properties table { text-align: center; vertical-align: middle; }

33 33 XHTML allows table nesting You can nest a table within a table Artists Songs Joe Smith Singin Mary Time Raps Poppin Happy Trails Tim Jazz Happy

34 34 Overriding any inherited CSS Styles in our table If our main table has CSS styles, the nested table will inherit these same styles Add a descendant selector to specify style to the nested table table table tr { background-color: red; }

35 35 Overriding any inherited CSS Styles in our table There are several ways to style the nested table Alternatively we could have created a class.nestedtable { background-color: red; } Must also add the class to nested element

36 36 You can style the table within a table Artists Songs Joe Smith Singin Mary Time Raps Poppin Happy Trails Tim Jazz Happy

37 37 List Items within XHTML A list can be styled using CSS Lists display bullets next to each item Only a few properties specific to lists List-style-type property allows you to control the bullets used in your list Monday Tuesday Wednesday Thursday Friday

38 38 List-style-type property: Default appearance round li{ list-style-type: disc; }

39 39 List-style-type property: Appearance hollow circle li{ list-style-type: circle; }

40 40 List-style-type property: Appearance square li{ list-style-type: square; }

41 41 List-style-type property: Appearance none li{ list-style-type: none; }

42 42 List-style-type property: Appearance custom image li{ list-style-image: url(images/logo.gif); } -end


Download ppt "1 Tables and Lists. 2 Are Tables still needed? Tables were once used to help structure and style our pages CSS now replaces most of the old uses for tables."

Similar presentations


Ads by Google