How to set the size of an html table.

It became popular, web designers mainly used the table layout method and got very good results.


Tags used to build a table in html

table- a required tag that opens and closes the table
caption- optional tag indicating the table title
th- an optional tag, the opening and closing tags of which contain the column name. Typically appears bold
tr- a required tag that opens and closes the line
td- a required tag indicating the opening and closing of a cell in a row

Example code for a simple table



HTML table





Table name

Stobets 1

Stobets 2

Text in first cell

Text in second cell



The browser will display

Purpose of tables in html

The lesson on tables is very important! Thanks to tables, you can arrange not only text, but also images, links and much more. In the table you can specify background(or its color), indentation, width, border And other parameters that will give her a beautiful appearance. Table - Your first step to understanding web design! Previously, many sites were entirely laid out as tables, that is, everything that the user saw ( sidebar, Top Menu, content) - was the content of the cells of a large table.
On that note, let's move directly to the attributes that make the table beautiful...

Properties and parameters of html tables: indentation, width, background color, border (frame)

U table tag has the following attributes:

width- table width. can be in pixels or % of screen width.
bgcolor- background color of table cells
background- fills the table background with a pattern
border- frame and borders in the table. Thickness is indicated in pixels
cellpadding- padding in pixels between the cell contents and its internal border
As before, we write the attribute value in quotes.

Let's look at the use of these attributes using an example. To do this, let's create a table (but already without the extremely rarely used caption and th tags) and set the parameter to the attribute border, width (width of table, row or cell) And bgcolor (cell color)



HTML table







As a result, the following table will be displayed in the browser:

frame- an attribute indicating the frame around the table. There are the following values:

Void - no frame,
above - only the top frame,
below - bottom frame only,
hsides - only the top and bottom frames,
vsides - only left and right frames,
lhs - left frame only,
rhs - right frame only,
box - all four parts of the frame.

rules- an attribute indicating the boundaries within the table, between cells. There are the following values:

None - there are no borders between cells,
groups - boundaries only between groups of rows and groups of columns (will be discussed a little later),
rows - boundaries between rows only,
cols - boundaries only between columns,
all - display all borders.

Let's look at the code example



HTML table


Stobets 1

Stobets 2









Result

Now let's try to create beautiful table. To do this, let's start using table alignment. To do this, there are the following already familiar parameters:

align- table alignment. It can be placed on the left (left), on the right (right), in the center (center)
cellspacing- distance between table cells. Specified in pixels (default 0 pixels)
cellpadding- padding in pixels between the cell contents and its internal border (default 0 pixels)
Let's look at an example



HTML table


Stobets 1

Stobets 2

Text in the first cell of the first column

Text in the second cell of the second column







The browser will display a centered table that looks like this:

tr rows and td cells in HTML tables

Let me remind you again that tables are formed row by row (tr). The rows (tr) already contain cells (td). If you specify a parameter for a string (tr), it will be valid for all cells(td) in this line, if for a specific cell, then only for it. In the examples above, I specified the color for the row; this parameter was distributed accordingly to all cells.





For tr and td tags there are the following

align- alignment of text inside a cell. Left edge (left), right edge (right), center (center)
valign- vertical alignment of text inside a cell. Up (top), down (bottom), center (middle)
bgcolor- sets the color of the line
width- column width (all cells below will take this parameter) is specified in pixels or as a percentage, where 100% is the width of the entire table
height- cell height (all cells in the row will accept this parameter)

Let's look at the code where the contents of the cells (td) are aligned along different edges: in the first one to the left, in the second to the right:



HTML table


Stobets 1

Stobets 2

Text in the first cell of the first column

Text in the second cell of the second column

Stobets 1

Stobets 2







Result

Using tables you can create a very good page. Don’t forget that you can insert not only text into cells, but also images, links, etc.!)

Thank you for your attention! I hope the material was useful!

The CSS specification gives unlimited possibilities for designing tables. By default, the table and table cells have no visible borders or background, and cells within the table are not adjacent to each other.

The width of table cells is determined by the width of their content, so the width of table columns can vary. The height of all cells in a row is the same and is determined by the height of the highest cell.

Formatting tables

1. Table borders

By default, the table and the cells inside it are displayed in the browser without visible borders. Table Borders are specified by the border property:

Table ( border-collapse: collapse; /*remove empty spaces between cells*/ border: 1px solid gray; /*set an outer border for the table gray 1px thick*/ )

Header cell borders each column are specified for the th element:

Th (border: 1px solid grey;)

Cell Borders table bodies are specified for the td element:

Td (border: 1px solid grey;)

The thickness of the borders of adjacent cells is not doubled, so you can set borders for the entire table in the following way:

Th, td (border: 1px solid grey;)

You can highlight the outer border of a table by giving it an increased width:

Table (border: 3px solid grey;)

Boundaries can be set partially:

/* set a gray outer border of 3px thickness for the table */ table (border-top: 3px solid gray; ) /* set a gray border of 1px thickness for the table body cell */ td (border-bottom: 1px solid gray;)

Read more about border property you can read.

2. How to set the table width and height

Default table width and height determined by the contents of its cells. If the width is not specified, then it will be equal to the width of the widest row (row).

Table and column width is set using the width property. If table (width: 100%;) is specified for a table, then the width of the table will be equal to the width of the container block in which it is located.

The width of the table and columns is usually specified in px or %, for example:

Table (width: 600px;) th (width: 20%;) td:first-child (width: 30%;)

Table height not specified. Row height tables can be manipulated by adding top and bottom padding to elements

. In practice, there are cases when special formatting of columns is necessary, which is possible in the following ways:

using tag

You can set the background for any number of columns;

using the selector table td:first-child , table td:last-child you can set styles for the first or last column of the table (except for the first cell of the table header);

Using the table selector td:nth-child (column selection rule), you can set styles for any table columns.

You can read more about CSS selectors.

5. How to add a table title

You can add a title to a table using a tag

- html table line
- column (cell) of an html table.

Now let's try to combine all the tags into one table. To do this, we will create an html table that consists of two rows and three columns:

This html table is very easy to make. First, let’s put the tags of the table itself, inside which we place the required number of rows (in our example, 2 rows):


Stobets 1

Stobets 2

Text in the first cell of the first column

Text in the second cell of the second column
And . Fix the height using height properties Not recommended.

Th, td (padding: 10px 15px;)

3. How to set the table background

Default table background and cells are transparent. If the page or block containing the table has a background, it will show through the table. If the background is specified for both the table and cells, then in places where the background of the table and cells overlap, only the background of the cells will be visible. The background for the table as a whole and its cells can be:
filling,
,
.

4. Table columns

Model CSS tables focused mainly on lines (rows) formed using the tag

, and using the caption-side property it can be placed in front of or below the table. For horizontal alignment title text is applied text-align property. Inherited.

...
Table No. 1
Company Q1 Q2 Q3 Q4
caption (caption-side: bottom; text-align: right; padding: 10px 0; font-size: 14px; ) Rice. 2. Example of displaying a header under a table

6. How to remove space between cell frames

By default, table cell frames are separated by a small space. If you set border-collapse: collapse for the table, the gap will be removed. The property is inherited.

Syntax

Table (border-collapse: collapse;)
Rice. 3. Example of tables with merging and separate cell frames

7. How to increase the space between cell frames

Using the border-spacing property, you can change the distance between cell frames. This property applies to the table as a whole. Inherited.

Syntax

Table (border-collapse: separate; border-spacing: 10px 20px;) table (border-collapse: separate; border-spacing: 10px;) Rice. 4. Example of tables with increased spaces between cell frames

8. How to hide empty table cells

The empty-cells property hides or shows empty cells. Only affects cells that do not contain any content. If a cell is set to a background and a table is set to table (border-collapse: collapse;) , then the cell will not be hidden. Inherited.

Company Q1 Q2 Q3
Microsoft 20.3 30.5
Google 50.2 40.63 45.23
table ( border: 1px solid #69c; border-collapse: separate; empty-cells: hide; ) th, td (border: 2px solid #69c;) Rice. 5. Hiding example empty cell tables

9. Layout a table using the table-layout property

The table layout layout is determined by one of two approaches: fixed layout or automatic layout. Under the layout in in this case refers to how the width of the table is distributed among the widths of the cells. The property is not inherited.

Syntax

Table (table-layout: fixed;)

10. Best Table Layouts

1. Horizontal minimalism

Horizontal tables are tables in which the text is read horizontally. Each entity is a separate row. You can arrange similar tables in minimalist style by placing a two-pixel border under the th header.

EmployeeSalaryBonusSupervisor
Stephen C. Cox$300$50Bob
Josephine Tan$150-Annie
Joyce Ming$200$35Andy
James A. Pentel$175$25Annie
table ( font-family: "Lucida Sans Unicode", "Lucida Grande", Sans-Serif; font-size: 14px; background: white; max-width: 70%; width: 70%; border-collapse: collapse; text -align: left; ) th ( font-weight: normal; color: #039; border-bottom: 2px solid #6678b1; padding: 10px 8px; ) td ( color: #669; padding: 9px 8px; transition: .3s linear; ) tr:hover td (color: #6699ff;)

At large quantities rows, this table design makes them difficult to read. To solve this problem, you can add a one-pixel border below all td elements.

Td ( border-bottom: 1px solid #ccc; color: #669; padding: 9px 8px; transition: .3s linear; )/*the rest of the code is as in the example above*/

Adding a :hover effect to the tr element will make tables designed in a minimalist style easier to read. When you hover your mouse over a cell, the remaining cells in the same row are highlighted simultaneously, making it easier to track information if tables have multiple columns.

Th ( font-weight: normal; color: #039; padding: 10px 15px; ) td ( color: #669; border-top: 1px solid #e8edff; padding: 10px 15px; ) tr:hover td (background: #e8edff ;)

2. Vertical minimalism

Although such tables are rarely used, vertically oriented tables are useful for categorizing or comparing descriptions of objects represented by a column. You can design them in a minimalist style by adding space to separate the columns.

Th ( font-weight: normal; border-bottom: 2px solid #6678b1; border-right: 30px solid #fff; border-left: 30px solid #fff; color: #039; padding: 8px 2px; ) td ( border- right: 30px solid #fff; border-left: 30px solid #fff; color: #669; padding: 12px 2px )

3. Boxed style

The most reliable style for designing tables of all types is the so-called “boxed” style. It's enough to choose a good one color scheme, and then set the background color for all cells. Don't forget to emphasize the difference between lines by setting borders as a separator.

Th ( font-size: 13px; font-weight: normal; background: #b9c9fe; border-top: 4px solid #aabcfe; border-bottom: 1px solid #fff; color: #039; padding: 8px; ) td ( background : #e8edff; border-bottom: 1px solid #fff; border-top: 1px solid transparent; tr:hover td (background: #ccddff;)

The most difficult thing is to find the color scheme that will harmoniously match your website. If the site is heavy on graphics and design, then it will be quite difficult for you to use this style.

Table ( font-family: "Lucida Sans Unicode", "Lucida Grande", Sans-Serif; font-size: 14px; max-width: 70%; width: 70%; text-align: center; border-collapse: collapse ; border-top: 7px solid #9baff1; border-bottom: 7px solid #9baff1; font-size: 13px; font-weight: normal; background: #e8edff; border-right: 1px solid #9baff1; border- left: 1px solid #9baff1; color: #039; padding: 8px; ) td ( background: #e8edff; border-right: 1px solid #aabcfe; border-left: 1px solid #aabcfe; color: #669; padding: 8px ; )

4. Horizontal zebra

The zebra table looks quite attractive and comfortable. Additional color The background can serve as a visual cue for people when reading the table.

Th ( font-weight: normal; color: #039; padding: 10px 15px; ) td ( color: #669; border-top: 1px solid #e8edff; padding: 10px 15px; ) tr:nth-child(2n) ( background: #e8edff;)

5. Newspaper style

To achieve the so-called newspaper effect, you can apply borders to table elements and play with the cells inside. A light, minimalistic newspaper style might look like this: play with the color scheme, add borders, padding, different backgrounds, and effect:hover when hovering over a line.

Table (border: 1px solid #69c;) th ( font-weight: normal; color: #039; border-bottom: 1px dashed #69c; padding: 12px 17px; ) td ( color: #669; padding: 7px 17px; ) tr:hover td (background: #ccddff;)

Table (border: 1px solid #69c;) th ( font-weight: normal; color: #039; padding: 10px; ) td ( color: #669; border-top: 1px dashed #fff; padding: 10px; background: #ccddff; ) tr:hover td (background: #99bcff;)

Table (border: 1px solid #6cf;) th ( font-weight: normal; font-size: 13px; color: #039; text-transform: uppercase; border-right: 1px solid #0865c2; border-top: 1px solid #0865c2; border-left: 1px solid #0865c2; border-bottom: 1px solid #fff; padding: 20px; )

6. Table background

If you are looking for a fast and unique way table design, choose an attractive image or photo related to the table theme and set it as the table background.

Jpg") no-repeat; background-position: 100% 55px; ) th ( font-weight: normal; color: #339; padding: 10px 12px; ) td ( background: url("https://site/images/ back..png"); background: transparent; )

1. What are HTML tables and why are they needed?

html tables- this is one of the most basic components of every html page and, accordingly, every site. For example, the entire site consists of tables: pictures, texts, links, registration forms - everything is placed relative to each other using html tables (in fact, the entire site is also located in one large table).

2. What tags do html tables have?

Tags, defining the html table are written like this:

But since we know that all tables consist of rows and columns (cells), so we need to set tags for them too:




Then we split each row into cells using column tags:



- cell 1.1
- cell 1.2
- cell 1.3


- cell 2.1
- cell 2.2
- cell 2.3

In fact, the first digit in the inscriptions is the row number, and the second is the cell number (1x2 - first row, second cell, etc.).

3. How to set the background color of html tables?

Now let's figure out how to set the background of the table or each cell separately.

So, to set the background the attribute is used bgcolor="background_color".

For example, if we need to set one color for the entire sign, then we do it like this:

bgcolor="background_color">

- cell 1.1
- cell 1.2
- cell 1.3


- cell 2.1
- cell 2.2
- cell 2.3

For example, if you need to make a yellow sign, then we write:

If needed set background color a number of html table, then the attribute bgcolor="background_color" apply to tag :

bgcolor="#FFFF00">
bgcolor="#0000FF">









1.1 1.2 1.3
2.1 2.2 2.3
1.1 1.2 1.3
2.1 2.2 2.3

In this case, the attribute cell number sets White color text located inside the tag.

In exactly the same way it is specified color of each cell separately. For example, if you want to change the color of cell 1.2 to blue, then inside the opening tag attribute bgcolor="background_color":

4. How to set the size of the width and height of html table cells?

So, in order to manually set the width and height of cells, use the height and width attributes. They can be set for the entire table, for one row, or for a cell (column). Height and width can be specified in either pixels or percentages. In our case, we will set the width and height in pixels for the columns (cells).

height- attribute that sets the height of the cell

width- attribute that specifies the width of the cell

And now for an example:

Now I'll explain why we set the cell height only once in each row.

If in a row you set a height for any cell greater than for others, then, despite this, all cells (columns) of your row will be equal in height to the largest one. And the width of each row is best set separately!

You can set the height and width for the entire table. In this case, all cells (columns) and rows will divide the space given to them equally, if you do not set these parameters to them personally (as a percentage of the total width (height) of the table or in pixels).

Also, very often you have to set the height and width width in percentages:

cell contents

If we set the width of a cell to 40 percent, as in our example, this means that we still have 60 percent left for the remaining cells, i.e. the sum of their widths should not exceed 60 percent. Everything is very simple: in total we have only 100%. We count: 100 – 40 = 60.

5. How to align text inside an html table?

Now let's figure out how to align the text in our html table to the left, right and center.

This is done using the attribute:

align=”left”- aligns the text inside the html table to the left

align=”center”- aligns html text tables centered

align=”right”- aligns the text inside the html table to the right

Accordingly, the align attribute can also take the values ​​right and left. The meaning of justify when used with a tag the align attribute cannot be accepted.

For example, the html code for a table whose text is centered looks like this:

align="center">










align="left"> 1x1 align="center">1.2 align="right"> 1x3
align="left">2.1 align="center"> 2x2 align="right">2.3

By registering the attribute align="center" in the opening

, we aligned the html table to the center of the browser page.

This is the result you will get in the browser:

1x1 1.2 1x3
2.1 2x2 2.3

Now let’s look at an example of how to align text inside an html table along the top or bottom edge, that is, how you can make sure that the contents of a cell are not only located exactly in the middle of it (as by default), but also at the top or bottom.

Vertical alignment specified by the attribute:

valign="top"- the content will be located at the top of the cell

valign="middle"- the content will be located in the center of the cell

valign="bottom"- the content will be located at the bottom of the cell

Let's look at these attributes using our example:












valign="top"> 1x1 1.2 valign="top"> 1x3
valign="bottom">2.1 2x2 valign="bottom">2.3

This is what we get if we look at the result of the attributes in the browser: align And valign:

1x1 1.2 1x3
2.1 2x2 2.3

6. How to combine cells and columns of an html table?

In this part of our article we will talk about attributes colspan And rowspan.

colspan- defines the number of columns to be applied this cell

rowspan- determines the number of rows to which this cell extends

Values colspan And rowspan can take a value from 2 or more, i.e. a cell can stretch across two or more columns (rows).

So, now, using the example, we will stretch a 1x1 cell into two columns (cells). For this we will use colspan attribute="2", registering it for the 1x1 cell. The code will look like this:

As we can see, the 1x1 cell extends over the length of two cells. Accordingly, its length is equal to the summed length of these two cells (160 pixels). We didn't specify a width attribute for the 1x1 cell, but if we decided to do so, we would set the width to 160 pixels. And also, please note that in our example there is no 1x3 cell, i.e. there are only two cells in the first row, why - we have already discussed this - a 1x1 cell is equal to two cells, thanks to the colspan attribute.

The colspan and rowspan attributes must be handled very carefully. An error may cause your site to crash.

And now that we understand the colspan parameter, let's look at the rowspan parameter. The operating principle is the same:










colspan="2"> 1.1 1.2
2.1 2.2
1.1 1.2
2.1 2.2

Thus, we learned how to combine cells in rows and columns of html tables.

7. How to remove, add or change indents and how to set a frame for an html table?

So, earlier we created an html table, the indents between the cells are clearly visible. To make them visible even better, let's add a frame for our table. This is done using attributes:

border="border width in pixels"- sets the frame width

bordercolor="border color"- sets the frame color

Let's, for example, give our html table a black frame 1 pixel wide.

For this tag

add attributes:

Now we can clearly see the indentations between html cells tables and padding from the inner edges of cells to text. Therefore, we can manage these indentations without any problems. The attributes are for this purpose:

cellspacing="space width in pixels"- space between cells

cellpadding="padding width in pixels"- indentation inside the cell (from the edge of the cell to the text, image, link...)

For example, let's make the indent between cells 10 pixels, and increase the indent from the edge of the cell to the text to 20 pixels. This is done like this:

cellpadding="20"cellspacing="10">








1.1 1.2
2.1 2.2

If we look at the result in the browser, we clearly see that the distance between cells ( cellspacing) of our html table has increased to 10 pixels, and the distance between the text and the inner edge of the cell has increased by 20 pixels.

1.1 1.2
2.1 2.2

If you need to remove indents altogether, then simply put cellpadding="0" And cellspacing="0".

8. How to insert one html table inside another?

We are approaching the final stage of learning html tables. Now we will learn how to insert one table inside another.

For example, inside cell 1.2 we will insert new table, consisting of one row and two columns. In the internal html table we will set a red border with a width of 2 pixels and a distance between cells of 0 pixels. We will also place the internal table at the top of the cell.

This is done very simply:










1.1






3.13.2

2.1 2.2

This is what happened as a result of the new transformations of our table (red cells are an internal table located inside a large table):

1.1
3.1 3.2
2.1 2.2

At this point we will finish this article. I think it turned out to be successful and not difficult to understand, and I hope you won’t have any more problems with the tables.

the body of the table is located. The body consists of rows and columns. The table is filled in line by line.

Each tag creates new line. Further in nested columns are created. You can create multiple columns. In this case, you need to monitor the number of columns in each row. For example, if the first row had 5 columns, then the following lines there should be 5 columns. Otherwise the table will float. It is possible to merge cells.

How to make a table in html

Let's give an example, html code:

Example table
Column 1 Column 2

Pay attention to the cell . We use the special colspan attribute to span cells horizontally. Its numeric value indicates the number of columns to be merged. There is also an analogue of this attribute: tag (table header), where you also need to enter colspan. The result will be the same. But often they use regular td.

Now let's take a closer look at all the tag attributes

.

Tag Attributes and Properties

To opening tag

You can specify various attributes.

1. Property align="parameter" - sets the table alignment. Can take the following values:

In the example above, we aligned the table to the center align="center" .

This attribute can be applied not only to the table, but also to individual table cells

. Thus, in different cells alignment will be different.

For example

, , , or
  • cols - line is displayed between columns
  • none - all borders are hidden
  • rows - a border is drawn between table rows created through the tag
  • 12. Property width="number" - sets the width of the table: either in pixels or in percentages.

    13. Property class="class_name" - you can specify the name of the class to which the table belongs.

    14. Property style="styles" - styles can be set individually for each table.

    Now it's time to dive inside the table and look at the attributes of the table cells. These attributes should be written in the opening tag

    And The same options are available as for will be hierarchically applied to all

    However, we would like to note that it is not necessary to change the cell sizes individually very often. As a rule, this is done in situations where it is necessary to set a certain width for table columns. In this case, the problem is solved easier. You just need to specify the width of the cells in the first row.

    or lines
    ... ... ...

    2. Property background="URL" - sets background picture. Instead of the URL, the address of the background image should be written.

    Example

    Example table
    Column 1 Column 2

    Converts to the following on the page:

    In the example considered, our background image is located in the img folder (which is in the same directory as the html page), and the image is called fon.gif . Please note that in the tag we added style="color:white;" . Since the background is almost black, to prevent the text from blending into the background, we made the text white.

    3. Property bgcolor="color" - sets the background color of the table. You can choose any color from the entire palette (see codes and names of html colors)

    4. Property border="number" - sets the thickness of the table border. In previous examples, we specified border="1" , which means the border thickness is 1 pixel.

    5. Property bordercolor="color" - sets the color of the border. If border="0" then there will be no border and the border color will have no meaning.

    6. Property cellpadding="number" - indent from the frame to the cell contents in pixels.

    7. Property cellspacing="number" - the distance between cells in pixels.

    8. Property cols="number" - number of columns. If you do not set it, the browser itself will determine the number of columns. The only difference is that specifying this parameter will most likely speed up the loading of the table.

    9. Property frame="parameter" - how to display borders around the table. Can take the following values:

    • void - do not draw borders
    • border - border around the table
    • above - border along the top edge of the table
    • below - border at the bottom of the table
    • hsides - add only horizontal borders (top and bottom of table)
    • vsides - draw only vertical borders (to the left and right of the table)
    • rhs - border only on right side tables
    • lhs - border only on the left side of the table

    10. Property height="number" - sets the height of the table: either in pixels or in percentages.

    11. Property rules="parameter" - where to display borders between cells. Can take the following values:

    • all - a line is drawn around each table cell
    • groups - a line is displayed between groups formed by tags
    .

    Attributes and Properties

    1. Property align="parameter" - sets the alignment of an individual table cell. Can take the following values:

    • left - left alignment
    • center - center alignment
    • right - right alignment

    2. Property background="URL" - sets the background image of the cell. Instead of the URL, the address of the background image should be written.

    3. Property bgcolor="color" - sets the background color of the cell.

    4. Property bordercolor="color" - sets the color of the cell border.

    5. Property char="letter" - specifies the letter from which the alignment should be made. The value of the align attribute must be set to char.

    6. Property colspan="number" - sets the number of horizontal cells to be merged.

    7. Property height="number" - sets the height of the table: either in pixels or as a percentage.

    8. Property width="number" - sets the width of the table: either in pixels or as a percentage.

    9. Property rowspan="number" - sets the number of vertical cells to be merged.

    10. Property valign="parameter" - vertical alignment of the cell contents.

    • top - align cell contents to the top edge of the row
    • middle - middle alignment
    • bottom - alignment to the bottom edge
    • baseline - alignment to the baseline
    Note 1

    For tag

    . Parameters for one tag
    inside him

    How to prevent cell borders in a table from sticking together

    When using border(cell border) and zero padding between cells, they still stick together and you get a double border . To avoid this, you need to specify border-collapse: collapse in the table styles:

    ...

    Dear reader, now you have learned much more about html tag table. Now I advise you to move on to the next lesson.

    The dimensions of the table, its height and width, are determined automatically depending on what the cells contain inside them. The more filling in the cells, the larger sizes tables and vice versa.

    However CSS features allow you to resize a table in HTML, specifying exactly the width and height that you need. To be fair, it should be noted that table attributes also allow you to set required sizes. However, in currently we'll only talk about CSS.

    It must be emphasized that each table has its own minimum width and minimum height, which are affected by its content. And even if you set the width and height values ​​even smaller, nothing will happen. The sides of the table will not exceed their minimum.

    To specify the width of the table you need to use a CSS property width, and to set the height you need to use the property height.

    In an example it looks like this.

    Table ( width: 500px; height: 100px; )

    Result in browser:

    Full code:

    Table with given sizes

    Table with given sizes
    1 2 3 4 5
    1 2 3 4 5
    1 2 3 4 5

    The table width and height values ​​can be specified either as an absolute value (in pixels) or as a relative value - as a percentage. For example, 20px and 20% respectively.

    If you use percentages to set table dimensions, they will be calculated based on the dimensions of the parent element. If we talk about our example, we are talking about a browser window.

    There is another meaning - auto. And it is special because with its help, the table width and height are calculated automatically, by default. In practice, specifying this value looks like this.

    Width: auto;

    Height: auto;

    We would like to draw your attention to one more thing: important point. It is better not to indicate the height as a percentage, since, as a rule, in this case they will not work.

    Specifying the sizes of individual cells and columns

    If you think that the browser did not correctly set the width of the columns based on the contents of the cells, then you have the right to specify the sizes of the cells and columns yourself. And now we will talk about how to change the cell size in an HTML table.

    Resizing cells is done using the same CSS properties as table sizes, namely: width And height.

    To add styles to cells, you can use one of two options:

    1. Give cells individual class names. It will look like this: class="cell-50px"

      And after that you should apply styles for these classes.

    2. Enable attribute style, inside which write the necessary CSS code.

    In practice, the second option will look like this:

    ...
    Table with given sizes
    1 2 3 4 5
    1 2 3 4 5
    1 2 3 4 5

    Result in browser:

    How to change the font size in a table

    Often there is a need to change the size of text in a table. For example, in header cells. This can be done using a CSS property font-size. Let's set the font size for the elements :

    Th (font-size: 30px; )

    On this this lesson ends. I suggest you think carefully about your homework. Just study it carefully and think about it. All the best to everyone!