Professional Documents
Culture Documents
100%.
18
Compiled By Aliazar D. (MSc in SEng)
Conti..
• HTML Table Headers • Vertical Table Headers • Align Table Headers
To use the first column as table headers,
Table headers are defined define the first cell in each row as a <th> By default, table headers are
with th elements. Each th element: bold and centered.
<table>
element represents a table <tr> To left-align the table headers,
<th>Firstname</th>
cell. <td>Jill</td> use the CSS text-align
<td>Eve</td>
<table> </tr> property:
<tr>
<tr> <th>Lastname</th> th {
<th>Firstname</th> <td>Smith</td>
<th>Lastname</th> <td>Jackson</td> text-align: left;
</tr>
<th>Age</th> <tr> }
<th>Age</th>
</tr> <td>94</td>
<tr> <td>50</td>
</tr>
</table>
19
Compiled By Aliazar D. (MSc in SEng)
• Table Caption
Conti.. You can add a caption that serves as a
heading for the entire table.
• Header for Multiple Columns To add a caption to a table, use the
You can have a header that <caption> tag:
spans over two or more <table style="width:100%">
columns. <caption>Monthly savings</caption>
<tr>
To do so, use the colspan <th>Month</th>
attribute on the <th> element: <th>Savings</th>
</tr>
<table> <tr>
<tr> <td>January</td>
<td>$100</td>
<th colspan="2">Name< </tr>
/th> <tr>
<td>February</td>
<th>Age</th> <td>$50</td>
</tr> </tr>
</table>
<tr>
Conti..
HTML Table Styling
• HTML Table - Zebra Stripes • Combine Vertical and Horizontal Zebra
• Horizontal Dividers
If you add a background color on Stripes
every other table row, you will get a You can combine the styling from the two If you specify borders only at the bottom
nice zebra stripes effect. examples above and you will have stripes of each table row, you will have a table
To style every other table row on every other row and every other column. with horizontal dividers.
element, use the :nth-child(even). If you use a transparent color you will get Add the border-bottom property to all tr
If you use (odd) instead of (even), the an overlapping effect. elements to get horizontal dividers:
styling will occur on row 1,3,5 etc. Use an rgba() color to specify the tr {
instead of 2,4,6 etc. transparency of the color border-bottom: 1px solid #ddd;
tr:nth-child(even) { tr:nth-child(even) { }
background-color: #D6EEEE; background-color: rgba(150, 212,
} 212, 0.4);
}
th:nth-child(even),td:nth-
child(even) { • Hoverable Table
background-color: rgba(150, 212, Use the :hover selector on tr
212, 0.4); to highlight table rows on
}
mouse over:
tr:hover {background-
Compiled By Aliazar D. (MSc in SEng) color: #D6EEEE;} 23
Conti..
• HTML Table Colgroup <table> • The <colgroup> tag must be a child of a
The <colgroup> element is used to <colgroup> <table> element and should be placed before
style specific columns of a table.
<col span="2" style any other table elements, like <thead>, <tr>,
If you want to style the two first <td> etc., but after the <caption> element, if
columns of a table, use the <colgroup> ="background-color:
and <col> elements. #D6EEEE"> present.
The <colgroup> element should be used </colgroup> • Multiple Col Elements
as a container for the column <tr> If you want to style more columns with
specifications. <th>MON</th> different styles, use more <col> elements
Each group is specified with a <col> <th>TUE</th> inside the <colgroup>:
element. <colgroup>
<th>WED</th>
The span attribute specifies how many <col span="2" style="background-
columns that get the style. <th>THU</th>
... color: #D6EEEE">
The style attribute specifies the style to
give the columns. <col span="3" style="background-
• Hide Columns color: pink">
You can hide columns with the </colgroup>
visibility: collapse property:
<col span="3" style="visibility:
collapse">
Compiled By Aliazar D. (MSc in SEng) 24
HTML Lists
HTML lists allow web developers to group a set of related items in lists.
• HTML Unordered • The CSS list-style-type property is
• Nested HTML Lists
A list item (<li>) can contain a
Lists used to define the style of the list new list, and other HTML
An unordered list starts item marker. It can have one of the elements, like images and links,
etc.
with the <ul> tag. Each following values:
Value Description <ul>
list item starts with the disc Sets the list item marker to a <li>Coffee</li>
<li> tag. bullet (default) <li>Tea
circle Sets the list item marker to a <ul>
<ul style="list- circle
<li>Black tea</li>
style-type:disc;"> square Sets the list item marker to a
square <li>Green tea</li>
<li>Coffee</li> none The list items will not be </ul>
marked </li>
<li>Tea</li> Disk Circle Square None <li>Milk</li>
<li>Milk</li> </ul>
</ul>
Compiled By Aliazar D. (MSc in SEng) 25
Conti..
<!DOCTYPE html>
<html>
<head>
<style>
ul {
list-style-type: none;
margin: 0;
padding: 0;
overflow: hidden;
background-color: #333333;
}
li {
float: left;
}
li a {
display: block;
color: white;
text-align: center;
padding: 16px;
text-decoration: none;
}
li a:hover {
background-color: #111111;
}
</style>
</head>
<body>
<ul>
<li><a href="#home">Home</a></li>
<li><a href="#news">News</a></li>
<li><a href="#contact">Contact</a></li>
<li><a href="#about">About</a></li>
</ul>
</body> Compiled By Aliazar D. (MSc in SEng) 26
</html>
Conti..
• HTML Ordered Lists • The type attribute of • Nested HTML Lists
The HTML <ol> tag defines an A list item (<li>) can contain a
ordered list. An ordered list can be the <ol> tag, defines new list, and other HTML
numerical or alphabetical. Each list the type of the list item elements, like images and links,
item starts with the <li> tag. etc.
Numbers marker: <ol>
Type Description
<ol type="1"> <li>Coffee</li>
type="1" The list items will be numbered
<li>Coffee</li> with numbers (default) <li>Tea
<li>Tea</li> <ol>
<li>Milk</li> type="A" The list items will be numbered
with uppercase letters
<li>Black tea</li>
</ol> <li>Green tea</li>
By default, an ordered list will start type="a" The list items will be numbered
with lowercase letters
</ol>
counting from 1. If you want to start </li>
counting from a specified number, type="I" The list items will be numbered <li>Milk</li>
you can use the start attribute with uppercase roman numbers
</ol>
1 A a I i type="i" The list items will be numbered
with lowercase roman numbers
• Every HTML element has a default display value, depending on what • Two commonly used block
type of element it is. elements are: <p> and <div>.
• There are two display values: block and inline. • The <p> element defines a
• Block-level Elements paragraph in an HTML
A block-level element always starts on a new line, and the browsers document.
automatically add some space (a margin) before and after the • The <div> element defines a
element. division or a section in an
A block-level element always takes up the full width available HTML document.
(stretches out to the left and right as far as it can).
<p>Hello World</p>
<div>Hello World</div>