Introduction
HTML Learning Part One - Basics:
https://blog.yexca.net/archives/146
HTML Learning Part Two - Lists, Tables, and Forms:
https://blog.yexca.net/archives/150
HTML Learning Part Three - Web Layout:
https://blog.yexca.net/archives/195
Lists
Lists are categorized into unordered, ordered, and definition lists.
Unordered Lists
unordered list -> list
| |
Output looks like this:
- 第一项
- 第二项
- 第三项
Ordered Lists
ordered list -> list
| |
Output looks like this:
- 第一项
- 第二项
- 第三项
Definition Lists
My mnemonic: define list -> define title -> define description
| |
Output looks like this:
- 第一标题
- 1.1 描述
- 1.2 描述
- 第二标题
- 2.1 描述
- 2.2 描述
A
dltag can only containdtandddtags. However,dtandddtags can contain any content.
Tables
| Tag | Description | My Mnemonic |
|---|---|---|
| table | Defines a table | |
| tr | Table row | table row |
| th | Table header cell | table head |
| td | Content cell | table data |
The following structural tags can be omitted, mainly for browser rendering.
| Tag | Description |
|---|---|
| thead | Defines header content |
| tbody | Defines table body |
| tfoot | Defines table footer, summary info |
Table Example
| |
Output looks like this:
| \ | x | y | total |
|---|---|---|---|
| a | 50 | 50 | 100 |
| b | 50 | 50 | 100 |
| total | 100 | 100 | 100 |
Cell Merging
Table cells can be merged across rows or columns. After merging, the merged cells should be removed.
| Attribute | Description |
|---|---|
| rowspan | Row span, value is the number of rows to span |
| colspan | Column span, value is the number of columns to span |
For example, merge the second column of the second and third rows, and merge the last three columns of the last row in the table above.
| |
Output looks like this:
| \ | x | y | total |
|---|---|---|---|
| a | 50 | 50 | 100 |
| b | 50 | 100 | |
| total | 100 | ||
If structural tags (
thead,tbody,tfoot) are used, you can’t merge across structures. For instance, the third row in the example above cannot merge with the last row.
Forms
form tag
A form needs a form tag to define its area. The tags mentioned below must be placed inside the form tag.
input tag
Most form elements are implemented using the input tag. Different type attribute values result in different functionalities.
type attribute value | Description |
|---|---|
| text | Text field |
| password | Password field |
| radio | Radio button |
| checkbox | Checkbox |
| file | File upload |
Placeholder Text
Placeholder text acts as a hint. It can be used for text and password fields.
| |
Output looks like this:
Radio Button
| Attribute | Function |
|---|---|
| name | Control name |
| checked | Default selected |
The following code implements gender selection:
| |
Output looks like this:
性别: 男 女
File Upload
By default, the file type only allows uploading one file. To upload multiple files, add the multiple attribute.
| |
Checkbox
Also known as a checkbox. Use the checked attribute for default selection.
| |
Dropdown Menu
| |
Text Area
A form control for multi-line text input, typically used for a bio or personal description.
| |
label tag
Used for descriptive text associated with a specific tag on a webpage. It can also link text with a form control, expanding the clickable area of the control.
For instance, with the gender radio buttons above, only clicking the circle selects the radio button. Using this tag allows clicking the text to select the radio button as well.
Method One
Add an id attribute to the input tag and a for attribute to the label tag; both attribute values should match.
| |
Method Two
Directly wrap the text and form control with the label tag.
| |
Controls that support expanding their clickable area with the
labeltag include: text fields, password fields, file uploads, radio buttons, checkboxes, dropdown menus, text areas, etc.
Buttons
The button tag’s functionality varies based on its type attribute value.
type attribute value | Description |
|---|---|
| submit | Default function: submits data to the backend |
| reset | Reset button: restores form controls to their default values |
| button | Generic button: requires JavaScript for functionality |
| |