Tables are one of the most important, but at the same time complex elements that must be present on web pages. With their help it is convenient to submit important and useful information in a fairly concise form. Of course, most editors in templates running on different engines allow you to automatically insert a table on a page of a site or a separate publication, but what if the design of a web resource, its pages are created from scratch? Then before the beginning wizard there can be a problem: how to make the table in HTML. Let's figure out how to create this element correctly and quickly.
Choose an editor
First of all, when you start creating a table, you should determine the editor in which you will work. Of course, the easiest way to choose the program in which you create the main code of the site. But it's best to use an old good notebook for these purposes.
You can ask why to complicate your life, because if you do everything at once in the editor, then you can see the result too, and you can also use the prompts of the program.
Yes, this is true, but when creating a table from scratch, you will not only be able to thoroughly study the very principle of its creation, but also to avoid annoying typos and errors in the main code. Sometimes it happens that the cursor accidentally moves down, and in the process of writing the code creeps in the error, which is sometimes difficult to find. When you create a table in Notepad, you can copy its cipher and insert it into the desired place.
Algorithm for creating a table
First, we will compile a short algorithm for how to make a table in HTML. This is necessary so that you understand the sequence of each step. Then we will analyze how to execute each of the items.
Let's start with the preparatory actions.
1. Draw a diagram of the table on a sheet of paper.
2. Count the number of rows and cells. If the number of the last is different - we consider for each row separately.
3. Determine the number of cells in the row-headers (for example, cells "No.", "Name", etc.).
4. We record the main parameters of the table - color, height and width, alignment of the text - in general, everything that you need.
Next, go directly to creating a table:
1. Insert the tags of the table.
2. Insert the tags of the rows based on the amount that you need.
3. In the rows, insert the tags of cells (regular and capital), also based on the amount that is written on your paper.
4. Set the parameters for the table as a whole.
5. If necessary, we set the indicators for individual cells.
6. Fill our cells with text.
Create a table
So, you chose the editor, now let's figure out how to create a table in HTML. The tag with which the table is inserted into the page code (
) is a pair, that is, our design begins with this tag, and ends with table>.
Inserting the tags of the table, we proceed to create rows and cells.
We note at once that these elements are also paired. The
tag specifies the rows, and the cells.
For header cells, use the | paired element.
As already mentioned, first of all it is necessary to issue the lines, then in them to register the cells. In order not to get confused, we advise you to make either indents between each block in one or two lines, or to prescribe a new block of elements using the "Tab" key.
How can it look like? Like that:
-
; -
; -
No. п / п th>; -
Surname th>; - Tr>;
-
; -
1 | ; -
Ivanov td>; - Tr>;
- Table>.
As you can see, nothing is complicated in this. The main thing is not to get confused about the number of rows and cells. Otherwise, the table may skew.
We have discussed the creation of a table in HTML, now we can move on to the parameters of both the matrix itself and its rows and cells.
Table Options When the code is written, you should pay attention to the following points: alignment in the HTML table, border color , background, text and so on.
The table parameters are specified in the tag. These include:
1. Border - the width of the borders. It is given as an integer. By default, the boundaries of any table are zero.
2. Bordercolor - the color of the border. Can be specified as a hexadecimal color code (# 00008B), and its name in English (DarkBlue). By default it is always gray.
3. Bgcolor - the background color. Also specified using a code or name.
4. Align - align text behind the table. The default is left. There are the following options for this parameter:
- Left is the flow on the right;
- Right-flow to the left;
- Center - displays the table in the center without flow.
5. Width and height - width and height of the table. It can be specified both in pixels and in percent (relative to the browser window size).
Prescribing this or that indicator, you should pay special attention to the design. After specifying the parameter, the equal sign must be followed by the specified value in quotation marks.
As for the color of the text, it is designed in the same way as plain text in HTML format.
An example of a table:
-
; -
; -
No. п / п th>; -
Surname th>; - Tr>;
-
; -
1 | ; -
Ivanov td>; - Tr>;
- Table>.
Line parameters So, we have already figured out how to make a table in HTML and prescribe its basic parameters. But what if we need to select a row? To design it not like the main text of the table?
The string parameters are written in the | tag in the same way as the table data. The following variables can be specified for a string:
1. Already known to you border, bordercolor and bgcolor.
2. Align - align text in the line. It can take values left, center and right.
3. Valign - this tag aligns the text vertically. It takes the following values:
- Top - the text is aligned on the upper border;
- Middle - centered;
- Bottom - on the lower border.
Example of a line:
-
; -
No. п / п th>; -
Surname th>; - Tr>.
Cell Settings And the last thing that should be paid attention to those who want to know how to make a table in HTML are the parameters of individual cells, both conventional and header. In fact, everything is done exactly the same way as for a table or a row. The only thing, two more important elements are added:
1. Colspan - this parameter specifies the number of columns that a cell can span.
2. Rowspan - specifies the number of rows that this cell occupies.
Since the design does not differ from the writing of the line, we will not give you an example of the code.
conclusions Making a table is not as difficult as it might seem at first glance. The main thing when writing her code - assiduity and attention.
As for how to insert a table in HTML, its cipher is copied and pasted exactly to the place of your page, in which it, in your opinion, should be located.
Do not be afraid to experiment, and soon you will master the technique of creating tables. Good luck!
| |
| | |
| | | |
|