A school website has a timetable, term marks, a photo of the school and links to other pages. All of them are built with the tags of this lesson: tables, colours, images and links.
Every entrance exam paper has one task on an HTML table: find how the table will look, a given column, the element where a row and a column meet or the number of cells in bold. Tags and formatting are explained in the lesson “Web programming: building a site, HTML tags and lists”.
Building a table: table, tr, th, td
| Tag | Meaning | How it looks |
|---|---|---|
<table> | table | without border no frame is shown |
<tr> | row (table row) | its cells line up in one row |
<th> | header cell (table header) | bold and centred |
<td> | data cell (table data) | plain text, aligned left |
<caption> | table caption | above the table, centred |
Attributes of <table>: border — frame thickness (in pixels), width — width (pixels or %), cellpadding — space inside a cell, cellspacing — space between cells, align — alignment, bgcolor — background colour (also works on <tr> and <td>).
- The number of rows equals the number of
<tr>tags; the header row is a row too. - The number of columns is the number of cells in one row (counting merges).
- In DİM tasks rows are counted from the top, including the header row, and columns from the left.
- An empty
<td></td>is still a cell: with a border it shows as an empty cell.
<table border="1" cellpadding="6">
<caption>Class timetable</caption>
<tr><th>Time</th><th>Monday</th><th>Tuesday</th></tr>
<tr><td>09:00</td><td>Math</td><td rowspan="2">Chemistry lab</td></tr>
<tr><td>10:00</td><td>History</td></tr>
<tr><td>11:00</td><td colspan="2">Sports day</td></tr>
<tr><td>12:00</td><td><b>Test</b></td><td></td></tr>
</table>border or add a new <tr>.Example 1. Where a row and a column meet
Problem
According to the HTML code fragment, which element will be where the third row and the second column of the table meet?<table border="1"><tr><th>Day</th><th>Lesson 1</th><th>Lesson 2</th></tr><tr><td>Monday</td><td>Math</td><td>Physics</td></tr><tr><td>Tuesday</td><td>History</td><td>Chemistry</td></tr><tr><td>Wednesday</td><td>Informatics</td><td>Biology</td></tr></table>
A) Math B) Chemistry C) History D) Informatics E) Tuesday
Show solutionHide solution
Solution
2) The cells of row 3: Tuesday, History, Chemistry. Column 2 holds “History”.
Correct answer: C) History. (If you skip the header row, you wrongly get Informatics.)
Example 2. How many cells are bold?
Problem
According to the HTML code fragment, in how many cells of the table will the text be shown in bold?<table border="1"><tr><th>Subject</th><th>Term I</th><th>Term II</th></tr><tr><td>Math</td><td><b>5</b></td><td><em>4</em></td></tr><tr><td>Physics</td><td><strong><u>5</u></strong></td><td><i>3</i></td></tr><tr><td><tt>Chemistry</tt></td><td>4</td><td><b><i>5</i></b></td></tr></table>
A) 3 B) 4 C) 6 D) 5 E) 7
Show solutionHide solution
Solution
<th> cells are always bold: Subject, Term I, Term II — 3 cells.2) Among the
<td> cells: <b>5</b>, <strong><u>5</u></strong>, <b><i>5</i></b> — 3 cells. <em>, <i>, <tt> and plain text are not bold.3) 3 + 3 = 6.
Correct answer: C) 6. (Forgetting the
<th> cells gives 3.)Merging cells: colspan and rowspan
colspan="k" stretches a cell across k columns — that row has k − 1 fewer cells written. rowspan="k" stretches a cell down k rows — the next k − 1 rows have no cell written for that column, and their other cells shift to the right.
Example 3. Merged cells
Problem
<table border="1"><tr><td rowspan="2">A</td><td>B</td><td>C</td></tr><tr><td>D</td><td>E</td></tr><tr><td colspan="2">F</td><td>G</td></tr></table>
1) How many columns does the table have? 2) Which element is where row 2 and column 3 meet? 3) How many cells does F take up?
Show solutionHide solution
Solution
2) A spans two rows (
rowspan="2"), so column 1 of row 2 is taken by A; D moves to column 2 and E to column 3. Answer: E.3) F with
colspan="2" covers columns 1 and 2 — 2 cells; G is in column 3.The colour scheme of a web page
The main colours of a page are set with attributes of the <body> tag, and the colour of single words with <font color="…">. A colour is written as an English name (red, blue) or as a #RRGGBB code: RR, GG, BB are the amounts of red, green and blue light, each from 00 to FF in hexadecimal (0–255).
| Attribute | What it colours |
|---|---|
bgcolor | the page background |
text | ordinary text |
link | links not yet visited |
vlink | links already visited — visited |
alink | a link at the moment it is clicked — active |
Where
- #RRGGBB
- colour code: three hexadecimal pairs — red, green, blue
- 256
- number of values of one pair: 00…FF = 0…255
- N
- number of colours that can be written
Every colour is coded with 3 bytes = 24 bits — the same as True Color in raster graphics.
| Name | Code | R, G, B |
|---|---|---|
black | #000000 | 0, 0, 0 |
white | #FFFFFF | 255, 255, 255 |
red | #FF0000 | 255, 0, 0 |
lime — bright green | #00FF00 | 0, 255, 0 |
green | #008000 | 0, 128, 0 |
blue | #0000FF | 0, 0, 255 |
yellow | #FFFF00 | 255, 255, 0 |
gray | #808080 | 128, 128, 128 |
purple | #800080 | 128, 0, 128 |
Example 4. Reading a colour scheme
Problem
A page’s code contains <body bgcolor="#FFFF00" text="#0000FF" link="#FF0000" vlink="#008000" alink="#800080">. 1) What colour are the background, ordinary text, unvisited and visited links? 2) What colour does <font color="#FF8000"> give?
Show solutionHide solution
Solution
bgcolor #FFFF00 — red + green = a yellow background; text #0000FF — blue text; link #FF0000 — red; vlink #008000 — green; at the moment of clicking (alink) #800080 — purple.2) FF = 15 · 16 + 15 = 255, 80 = 8 · 16 = 128, 00 = 0: full red + half green — orange.
Interactive
<body bgcolor="#FFFFE0" text="#003366" link="#CC0000" vlink="#800080" alink="#FF8000">
<h2>Colour scheme</h2>
<p>Ordinary text is dark blue on a light yellow background.</p>
<p><a href="#top">This link</a> is red before you open it.</p>
<p><font color="green">green</font>,
<font color="#FF8000">orange #FF8000</font>,
<font color="#808080">grey #808080</font></p>
</body>bgcolor, text and link values and look at the result.Images and links
An image is placed with the single tag <img>. Its main attributes: src — the address of the graphic file (JPEG, PNG, GIF, SVG, WebP); alt — the text shown when the image cannot load and read out by screen readers; width, height — size in pixels or percent; align="left" / "right" — the image moves to the side and text wraps around it (top, middle, bottom set its vertical place in a line); border — frame thickness (pixels).
Where
- w₁, h₁
- the image’s own width and height (pixels)
- w₂
- the width written in the
widthattribute - h₂
- the height the browser shows
If only width (or only height) is given, the browser keeps the proportions.
Example 5. The size of an image
Problem
1) A 1200 × 800 pixel image is placed with <img src="tower.jpg" width="300">. At what height will the browser show it? 2) A 640 × 480 pixel image has height="120". What will its width be?
Show solutionHide solution
Solution
2) This time the height is given: w₂ = 640 · 120 / 480 = 160 pixels.
A link (hyperlink) is text or an image that leads to another page, a file or another place on the page: <a href="address">text</a>. href can hold an absolute address (https://… — another site), a relative one (contact.html — a page of your own site), #name (the place with id="name" on the same page) or mailto: (the mail program). target="_blank" opens the link in a new window (tab). Put an <img> inside <a> and the picture becomes a link.
<p id="top">
<img src="data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 160 100'%3E%3Crect width='160' height='60' fill='%23fdba74'/%3E%3Ccircle cx='80' cy='60' r='22' fill='%23f97316'/%3E%3Crect y='60' width='160' height='40' fill='%230ea5e9'/%3E%3C/svg%3E"
width="160" align="right" border="2" alt="Sunset over the sea">
The picture is on the right (align="right"), with a 2-pixel frame,
and this text wraps around it on the left.
</p>
<p><a href="https://example.com" target="_blank">Opens in a new tab</a></p>
<p><a href="mailto:info@example.com">Write an e-mail</a></p>
<p><a href="#top">Back to the top of the page</a></p>align to left and border to 0, change width — the height changes in proportion.Example 6. Kinds of links
Problem
1) <a href="https://www.example.com">Site</a>2) <a href="contact.html">Contact</a>3) <a href="#prices">Prices</a>4) <a href="mailto:info@example.com">Write to us</a>5) <a href="book.pdf" target="_blank">Book</a>
Which link: a) leads to another site; b) jumps within the same page; c) opens the mail program; d) opens in a new tab; e) leads to another page of the same site?
Show solutionHide solution
Solution
https://. b) 3 — #prices jumps to the place with id="prices". c) 4 — mailto:. d) 5 — target="_blank". e) 2 — the relative address contact.html.Remember
- Table:
<table>→<tr>rows →<th>(bold, centred) and<td>(plain) cells;borderdraws the frame,<caption>gives the title. - Rows are counted from the top including the header row, columns from the left; an empty
<td>is still a cell. - Bold cells = all
<th>+ the<td>cells containing<b>or<strong>. colspanstretches a cell to the right,rowspandownwards; cells of the rows below go to the right of the merged cell.<body>:bgcolor— background,text— text,link— unvisited,vlink— visited,alink— clicked link; #RRGGBB writes 2²⁴ colours.<img src alt width height align border>is a single tag; with only a width the proportions stay;<a href>:https://, relative address,#id,mailto:,target="_blank".