Formatting tables in an html document. Browser display
colspan tag - combining columnsThe most common use of tables of complex structures is web page markup. Look at the picture:
It turns out that we need the first and third rows to have one column each. This is achieved using the parameter colspan tag
For example,
For our example:
Document title
site header | |
menu | content |
bottom of the site |
Notice that the first and third rows now contain one column each.
Let's look at another example of web page markup:
site header | |||||
menu | menu | menu | menu | menu | menu |
news | content |
Count - how many rows and columns are there in this table? To do this, mentally apply a grid to the drawing. This will result in three rows and six columns.
The first row consists of one column, which includes six columns. Let's write this down:
The second row consists of six columns:
The third line consists of two columns, with the first including two columns and the second four:
It's not that difficult. We visually overlay the grid on the drawing and write the rows one by one from top to bottom, describing the required number of columns in each.
Rowspan tag - concatenation of rows
What if we need markup like this?
Please note that in the second row we have only one column, because the first column extends from the first row, simply including two.
At first glance, this may seem difficult, but with a little practice you will be able to create tables of any complexity.
Let's look at another example:
cap | menu |
content | |
bottom of the site |
So in the first row we have two columns, with the second column concatenating the two rows. Let's write this down:
The second row is one column (it's just that part of it is hidden by the second column of the first row):
Finally, the third row is a single column that includes three columns:
Using these two options rowspan And colspan You can create tables of any complexity. Practice.
Nested tables
As the name suggests, one table can be placed inside another, or inside any column. Let's do this using our last markup as an example.
So we have this code.
This lecture discusses in detail the principles of using tables in HTML markup. This includes a tabular organization of text, a tabular coordinate grid, and graphics organized in tables.
Tools for describing tables in HTML
As the WWW developed, it became clear that the funds contained in HTML were not enough for high-quality display various types documents. The disadvantage of HTML was the lack of tools for displaying tables. For this purpose, preformatted text (tag
), in which the table was outlined in ASCII characters. But this form of table presentation was not enough high quality and stood out from the general style of the document. After the introduction of tables in HTML, Webmasters had not just a tool for placing text and numerical data, but a powerful design tool for placing graphic images and text in the right place on the screen.Creating tables in HTML
The tag is used to describe tables<ТАВLЕ>. Tag<ТАВLЕ>, like many others, automatically translates the line before and after the table.
Creating a table row - tag<ТR>
Tag<ТR>(Table Row) creates a table row. All text, other tags and attributes that need to be placed on one line must be placed between the lt;TR> tagsТR>.
Defining table cells - tag<ТD>
Cells with data are usually placed inside a table row. Every cell containing text or image must be surrounded by tags<ТD>ТD>. Number of tags<ТD>ТD>in a row defines the number of cells
Table
If a table has two TR tags, then it has two rows. If there are three TD tags in a line, then in it three columns. Table column headings - tag<ТН>
Headings for table columns and rows are set using the header tag<ТН>ТН>(TableHeader, table title). These tags are similar<ТD>ТD>. The difference is that the text enclosed between the tags<ТН>ТН>, is automatically written in bold and is placed in the middle of the cell by default. You can cancel the centering and align the text to the left or right. If you use<ТD>ТD>with tag<В>and attribute<АLIGN=center>, the text will also look like a title. However, be aware that not all browsers support in tables bold type, so it's better to set table headers using<ТН>.
Header is centered by default | The header can join columns | |
---|---|---|
The header can be placed before the columns | Text or data | Text or data |
Header can concatenate lines | Text or data | Text or data |
Text or data | Text or data | |
Text or data | Text or data |
Using table headers - tag<САРТIОN>
Tag
Text or data | Text or data | Text or data | Text or data |
Text or data | Text or data | Text or data |
NOWRAP attribute
Typically, any text that does not fit on one line of a table cell goes to next line. However, when using the NOWRAP attribute with tags<ТН>or<ТD>The length of the cell is expanded so that the text contained within it fits on one line.
COLSPAN attribute
Tags<ТD>And<ТН>modified using the COLSPAN attribute (Column Span, column connection). If you want to make a cell wider than the top or bottom, you can use the COLSPAN attribute to stretch it over any number of regular cells.
If you want to make any cell wider than the top or bottom, | you can use the COLSPAN=2 attribute, |
to stretch it over any number of regular cells. |
ROWSPAN attribute
ROWSPAN attribute used in tags<ТD>And<ТН>, is similar to the COLSPAN= attribute, only it specifies the number of lines over which the cell is stretched. If you specified a number greater than one in the ROWSPAN=s attribute, then the corresponding number of rows must be under the stretched cell. It cannot be placed at the bottom of the table.
WIDTH attribute
The WIDTH attribute is used in two cases. You can put it in a tag<ТАВLЕ>to give the width of the entire table, or can be used in tags<ТD>or<ТН>to set the width of a cell or group of cells. The width can be specified in pixels or as a percentage. For example, if you set in the tag<ТАВLЕ>WIDTH=250, you will get a table that is 250 pixels wide regardless of the page size on your monitor. When setting WIDТН=50% in the tag<ТАВLЕ>the table will occupy half the width of the page at any image size on the screen. So, when specifying the table width as a percentage, keep in mind that if the user has a narrow viewport, your page may look a little weird. If you are using pixels and the table is wider than the viewing area, a scroll bar will appear at the bottom to move left and right on the page. Depending on the tasks at hand, either method of setting the width of the table may be useful.
Text or data - width 100% |
Text or data - width 50% |
Text or data - 200 pixels wide |
Text or data - 100 pixels wide |
Applying empty cells
If a cell contains no data, it will have no borders. If you want a cell to have borders but no content, you need to put something in it that won't be visible when viewed. You can use an empty string<ВR>. You can even specify empty columns by defining their width in pixels or relative units and not entering any data into the resulting cells. This tool can be useful when placing text and graphics on a page.
CELLADDING attribute
This attribute determines the width of the empty space between the contents of the cell and its borders, that is, it sets the margins inside the cell.
Text or data | Text or data | Text or data |
Text or data | Text or data | Text or data |
Text or data | Text or data | Text or data |
Text or data | Text or data | Text or data |
ALIGN and VALIGN attributes
Tags<ТR>, <ТD>And<ТН>can be modified using the ALIGN and VALIGN attributes. The ALIGN attribute determines whether text and graphics are aligned horizontally, that is, left or right, or centered. Horizontal alignment can be set in several ways:
ALIGN=bleedleft presses the contents of the cell close to the left edge.
ALIGN=left Aligns the contents of the cell to the left, taking into account the indentation specified by the CELLPADDING attribute.
ALIGN=center Centers the contents of the cell.
ALIGN=right Aligns the contents of a cell to the right, taking into account the indentation specified by the CELLPADDING attribute.
Text or data | Text or data | Text or data |
Text or data | Text or data | Text or data |
Text or data | Text or data | Text or data |
Text or data | Text or data | Text or data |
Text or data | Text or data | Text or data |
The VALIGN attribute vertically aligns text and graphics within a cell. Vertical alignment can be set in several ways:
VALIGN=top Aligns the contents of a cell to its top border.
VALIGN=middle Centers the contents of the cell vertically.
VALIGN=bottom Aligns the contents of a cell to its bottom border.
The VALIGN attribute vertically aligns text and graphics within a cell. | top, | middle, | bottom. |
VALIGN=top Aligns the contents of a cell to its top border. | top, | top, | top. |
VALIGN=middle Centers the contents of a cell vertically. | middle, | middle, | middle. |
VALIGN=bottom Aligns the contents of a cell to its bottom border. | bottom, | bottom, | bottom. |
BORDER attribute
In the tag<ТАВLЕ>often determine how the borders, that is, the lines surrounding the table cells and the table itself, will look. If you do not specify a frame, you will get a table without lines, but space will be allocated for them. The same result can be achieved by setting<ТАВLЕ ВОRDER=0>. Sometimes you want to make the border thicker so that it stands out better. You can set exceptionally bold borders to attract attention to a picture or text. When creating nested tables, you have to make borders of different thicknesses for different tables to make them easier to distinguish.
CELLSPACING attribute
The CELLSPACING attribute specifies the width of the spaces between cells in pixels. If this attribute is not specified, the default value is two pixels. Using the CELLSPACING= attribute, you can place text and graphics wherever you need them. If you want to leave an empty space, you can write a space in the cell.
Text or data | Text or data | Text or data |
Text or data | Text or data | Text or data |
Text or data | Text or data | Text or data |
Text or data | Text or data | Text or data |
Text or data | Text or data | Text or data |
Text or data | Text or data |
BGCOLOR attribute
This attribute allows you to set the background color. Depending on which tag (TABLE, TR, TD) it is used with, the background color can be set for the entire table, for a row, or for an individual cell. The value of this attribute is the RGB code or standard name colors.
Text or data | Text or data | Text or data |
Text or data | Text or data | Text or data |
BACKGROUND attribute
This attribute specifies the background image for tables. Applies to TABLE and TD tags. Its meaning is File URL With background image. The use of this attribute is discussed below.
Using tables in page design
The good thing about tables is that you can make their borders invisible if you want. This allows using the tag<ТАВLЕ>beautifully place text and graphics on the page. Bye tag<ТАВLЕ>remains the only powerful formatting tool in HTML. Web page designers now have almost the same freedom regarding the use of white space as printed page designers. Tables are the best way to move away from hierarchical placement of text on Web pages.
If the browser supports tables, it will usually correctly display most interesting effects obtained with their help
Ural State Pedagogical UniversityWelcome!
|
Creating colorful tables
Some browsers allow you to display colors. There are several ways to color a table, mostly depending on the browser you are using.
Colored borders in Netscape Navigator. Not only can you surround the table beautiful frame, but also set a color for it that is different from the text and background colors. Create a simple gray GIF (or any GIF you would like to have as a background) and define it in a tag<ВODY>as a page background. Then set the page background color. As a result, your tag<ВОDY>will look something like this:
You have created a double background - GIF and a specified color. As a result background color will be visible on all table borders and horizontal lines (<НR>). Whether your background GIF is gray or not, the colored lines and table borders will stand out noticeably. If the background GIF is not too complex, the page load time will only increase slightly.
Task
Create a table and specify its parameters (margins and distance between cells) through styles.
Solution
A table consists of rows and columns of cells that can contain text and pictures. To add a table to a web page, use the tag
. The table must contain at least one cell (example 1). Allowed instead of tag | use tag | . Text in a cell styled with a tag | , is displayed by the browser in bold font and aligned to the center of the cell. Otherwise, the differences between cells created through tags | And | No.
Example 1: Creating a table HTML5 IE Cr Op Sa Fx
The order of the cells and their appearance is shown in Fig. 1. Rice. 1. Result of creating a table with four cells border tag attribute
A table with fields and distance between cells is shown in Fig. 2. A similar result can be achieved using a white frame around the cells. Rice. 2. Fields in table cells Using the COLSPAN and ROWSPAN attributes, you can combine several adjacent cells of a column or row into one large cell. COLSPAN tag attribute
, | allows you to merge cells of several columns within one row.
| ROWSPAN attribute - cells of several rows within one column. The number specified in these attributes indicates the number of cells that will be merged. Because When performing merge operations it is very easy to get confused, I strongly recommend making a preliminary sketch of the table on paper. Example:
|
---|