How to remove space between html table cells. Digression from the topic or how to remove indents along the edges of the page

The tables themselves look rather poor, and browsers display some table characteristics, in particular, frames, in their own way. At the same time, these shortcomings can be easily corrected by using the power of styles. At the same time, the means for designing tables are greatly expanded, which allows you to successfully fit tables into the site design and present tabular data more clearly.

Cell background color

The background color of all table cells at the same time is set through the background property, which is applied to the TABLE selector. In this case, you should remember the rules for using styles, in particular, the inheritance of element properties. Although the background property is not inherited, the default background value for cells is transparent, i.e. transparency, so the background fill effect is also obtained for the cells. If, simultaneously with TABLE, you set a color for the TD or TH selector, then this color will be set as the background of the cell (example 2.3).

Example 2.3. Background color

Tables

Heading 1Heading 2
Cell 3Cell 4

In this example, we get a blue background color for the cells (tag ) and red at the title (tag ). This is because the style for the TH selector is not defined, so the background of the parent, in this case the TABLE selector, is "shown through". And the color for the TD selector is specified explicitly, so the cells are “filled” with blue.

The result of this example is shown in Fig. 2.4.

Rice. 2.4. Changing the background color

Margins inside cells

Margin is the distance between the edge of a cell's contents and its border. Typically the cellpadding attribute of a tag is used for this purpose.

. It defines the margin value in pixels on all sides of the cell. It is possible to use the padding style property by adding it to the TD selector, as shown in Example 2.4.

Example 2.4. Fields in tables

XHTML 1.0 CSS 2.1 IE Cr Op Sa Fx

Tables

Heading 1Heading 2
Cell 3Cell 4

In this example, by grouping selectors, the fields are set simultaneously for the TD and TH selectors. The result of the example is shown in Fig. 2.5.

Rice. 2.5. Fields in cells

If the padding style property is applied to table cells, then the effect of the cellpadding attribute of the tag

ignored.

Distance between cells

To change the distance between cells, use the cellspacing attribute of the tag

. The effect of this attribute is clearly visible when you use borders around cells or when filling cells with a color that stands out from the background of the page. The style property border-spacing acts as a replacement for cellspacing; it sets the distance between the borders of cells. One value sets both the vertical and horizontal distance between cell borders. If this property has two values, then the first determines the horizontal distance (that is, to the left and right of the cell), and the second determines the vertical distance (above and below).

The border-spacing property only takes effect if the TABLE selector does not have the border-collapse property set to collapse (Example 2.5).

Example 2.5. Distance between cell borders

XHTML 1.0 CSS 2.1 IE 7 IE 8+ Cr Op Sa Fx

Replacing cellspacing

Leonardo58
Raphael411
Michelangelo249
Donatello213

The result of this example is shown in Fig. 2.6.

Rice. 2.6. Table appearance when using border-spacing

Internet Explorer version 7 and up does not support the border-spacing property, so tables in this browser will use the default cellspacing value (usually 2px).

When adding a border-collapse property with a value of collapse to a TABLE selector, the cellspacing attribute is ignored and the border-spacing value is reset to zero.

Borders and Frames

By default, there is no border in the table initially, and its addition occurs using the border attribute of the tag

. Browsers display such a border differently, so it is better not to specify this attribute at all, and leave the drawing of borders to styles. Let's look at two methods directly related to styles.

Using the cellspacing attribute

It is known that the cellspacing attribute of the tag

sets the distance between table cells. If you use different background colors for the table and cells, then a grid of lines will appear between the cells, the color of which matches the color of the table, and the thickness is equal to the value of the cellspacing attribute in pixels. Example 2.3 above shows this effect, so I won’t repeat it.

Note that this is not a very convenient way to create boundaries, since it has a limited scope. This way you can only get a single-color grid, and not vertical or horizontal lines in the right places.

Using the border property

The border style property simultaneously sets the border color, style, and thickness around an element. When you need to create separate lines on different sides, it is better to use the derivatives - border-left , border-right , border-top and border-bottom , these properties respectively define the border on the left, right, top and bottom.

By applying the border property to a TABLE selector, we add a border around the table as a whole, and to a TD or TH selector we add a border around the cells (Example 2.6).

Example 2.6. Adding a Double Frame

XHTML 1.0 CSS 2.1 IE Cr Op Sa Fx

Tables

Heading 1Heading 2
Cell 3Cell 4

This example uses a black double border around the table itself and a solid white border around each cell. The result of the example is shown in Fig. 2.7.

Rice. 2.7. Border around table and cells

Please note that double lines are formed where the cells join. They are obtained again due to the action of the cellspacing attribute of the tag

. Although this attribute does not appear anywhere in the example code, the browser uses it by default. If you set
, then we get not double, but single lines, but of double thickness. To change this feature, use the border-collapse style property with the value collapse , which is added to the TABLE selector (example 2.7).

Example 2.7. Creating a Single Frame

XHTML 1.0 CSS 2.1 IE Cr Op Sa Fx

Tables

Heading 1Heading 2
Cell 3Cell 4

This example creates a solid green line between cells and a black line around the table. All borders within the table have the same thickness. The result of the example is shown in Fig. 2.8.

Rice. 2.8. Border around table

Aligning cell contents

By default, text in a table cell is aligned left. The exception to this rule is the tag , it defines a heading that is center-aligned. To change the alignment method, use the text-align style property (example 2.8).

Example 2.8. Align cell contents horizontally

XHTML 1.0 CSS 2.1 IE Cr Op Sa Fx

Tables

Heading 1Cell 1Cell 2
Heading 2Cell 3Cell 4

In this example, the content of the tag is left-aligned, and the contents of the tag - in the center. The result of the example is shown below (Figure 2.9).

Rice. 2.9. Aligning text in cells

Vertical alignment in a cell is always centered unless otherwise noted. This is not always convenient, especially for tables whose cell contents vary in height. In this case, the alignment is set to the top edge of the cell using the vertical-align property, as shown in Example 2.9.

Example 2.9. Align cell contents vertically

XHTML 1.0 CSS 2.1 IE Cr Op Sa Fx

Tables

Heading 1Heading 2
Cell 1Cell 2

This example sets the height of the header like 40 pixels and the text is aligned to the bottom edge. The result of the example is shown in Fig. 2.10.

Rice. 2.10. Aligning text in cells

Empty cells

Browsers display a cell with nothing inside it differently. “Nothing” in this case means that neither a picture nor text was added inside the cell, and the space is not taken into account. Naturally, the appearance of cells differs only if a border is set around them. When using an invisible border, the appearance of the cells, regardless of whether there is anything in them or not, is the same.

Older browsers did not display the background color of empty view cells , so when it was necessary to leave a cell without content but display the background color, a non-separated space () was added inside the cell. Space is not always suitable, especially when you need to set the cell height to 1-2 pixels, which is why the one-pixel transparent design has become widespread. Indeed, such a picture can be scaled at your discretion, but it is not displayed on the web page in any way.

Fortunately, the era of single-pixel drawings and all sorts of spacers based on them has passed. Browsers work quite correctly with tables even without the presence of cell contents.

To control the appearance of empty cells, use the empty-cells property; when set to hide, the border and background are not displayed in empty cells. If all cells in a row are empty, then the entire row is hidden. The cell is considered empty in the following cases:

  • there are no symbols at all;
  • the cell contains only a newline, tab, or space;
  • visibility is set to hidden .

Adding a non-breaking space is perceived as visible content, i.e. the cell will no longer be empty (example 2.10).

Example 2.10. Empty cells

XHTML 1.0 CSS 2.1 IE Cr Op Sa Fx

Using empty-cells

Leonardo58
Raphael 11
Michelangelo24
Donatello 13

The table view in the Safari browser is shown in Fig. 2.11a. The same table in IE7 is shown in Fig. 2.11b.

A. In Safari, Firefox, Opera, IE8, IE9 browser

b. In IE7 browser

Rice. 2.11. Table view with empty cells

CSS allows you to set not only the style of the table border, but also the style of the borders of individual cells. Since each cell has its own borders, the border between adjacent cells is double. But it is possible to combine the boundaries of neighboring cells into one. There is a border-collapse property for this. It takes values:

border-collapse: separate - each cell has its own border (default)

border-collapse: collapse - shared border

border-collapse: inherit - the value is taken from the parent element

For example, let's create a table and set a frame for the cells of all tables that will be on the page. Let's not change anything at first to see how the table will look:

Style:

(“footer” of the table) background color – coral, for element (“table header”) set the background color silver.
  • For elements
  • , which are inside the element (table body) set the background color to change on hover (pseudo class :hover) c white per color khaki(the entire line is highlighted).

    The result of our example:

    Rice. 153 Example of styling rows in tables

    The following example looks at applying corner rounding to table cells (property).

    Example of rounding cell corners

    1
    2
    3
    4
    5
    6

    Page
    Table indentation
    1 2 3 4
    2
    3
    4

    In this example we:

    • We placed the table in the center using the technique of horizontal centering with external indents (margin: 0 auto).
    • For the table name (tag
    ) we set the bottom padding to 19 pixels. I hope the uneven numbers don't bother you :)

    The result of our example:

    Space between cells

    After the example discussed above, you may have noticed that we still have a gap between all the table cells. Let's look at how to remove the space between table cells or increase it.

    To set the distance between the borders of adjacent cells, you must use the CSS property border-spacing.

    Changing the spacing between tables
    border-spacing: 30px 10px;
    1 2 3
    2
    3
    border-spacing: 0;
    1 2 3
    2
    3
    border-spacing:0.2em;
    1 2 3
    2
    3

    In this example we:

    • float: left). If you missed the topic of floating elements, then you can always return to it in this tutorial - "".
    • In addition, we set the right margin for the tables to 30px and set the vertical alignment of the tables (the top of the element is aligned with the top of the tallest element). We will return to a detailed consideration of this property in this article.
    ) – bold style.
  • For the table cells (header and data cells), we set a 1px solid border with #F50 hex color and set 19px padding on all sides.
  • For the first table with class .first we set the space between the table cells (border-spacing property) to be 30px 10px for the second table with the class .second equal to zero, for third tables with class .third equal to 0.2em .
  • Please note that if only one length value is specified in the border-spacing property, then it indicates the intervals, both horizontally and vertically, and if two length values ​​are specified, then the first determines the horizontal distance, and the second vertical. The distance between the borders of adjacent cells can be specified in CSS units (px, cm, em, etc.). Negative values ​​are not allowed.

    The result of our example:

    Show borders around table cells

    You can say: - so, we removed the space between the cells using the border-spacing property with a value of 0 , but why do our cell borders now intersect?

    Double borders are caused by the fact that the bottom border of one cell is added to the top border of the cell that is below it, a similar situation occurs on the sides of cells and this is logical from a table display point of view, but fortunately there is a way to tell the browser that we We don’t want to see such loose behavior of cell borders.

    To do this, you need to use the border-collapse CSS property. Oddly enough, using the border-collapse property with the collapse value is the best way to remove the space between cells without getting double borders between them.

    Let's compare the behavior of borders when using the border-spacing property with a value of 0 and the border-collapse property with a value of collapse :

    Example of displaying borders around table cells
    border-spacing: 0;
    1 2 3
    2
    3
    border-collapse: collapse;
    1 2 3
    2
    3

    In this example we:

    • We made our tables floating and moved them to the left (float: left), set their outer margin on the right to 30px.
    • Set the table name (tag
    ) – bold style.
  • For the table cells (header and data cells), we set a 5px solid border with hex color #F50 and set a fixed width of 50px and height of 75px.
  • For the first table with class .first we set the space between the table cells to zero (border-spacing : 0 ;), and for the second table with the class .second set the border-collapse property to collapse , which collapses the borders of cells into one when possible.
  • The result of our example:

    Behavior of empty cells

    You can use CSS to set whether the borders and backgrounds of empty cells in a table should be displayed or not. This behavior is controlled by the empty-cells property, which by default, as you may have noticed from the previous examples, displays empty cells.

    Let's move on to an example:

    Example of displaying empty table cells
    empty-cells: show;
    1 2 3
    2
    3
    empty-cells: hide;
    1 2 3
    2
    3

    To understand how the empty-cells property works from this example is very simple, if it is set to hide , then empty cells and the background in them will be hidden, if set to show (default), then they will be displayed.

    Table header location

    Let's look at another simple property for styling tables - caption-side , which sets the position of the table header (above or below the table). By default, the caption-side property is set to top , which places the caption above the table. In order to place a title under the table, you need to use the property with the value bottom .

    Let's look at an example of using this property:

    An example of using the caption-side property
    Header above table
    NamePrice
    Fish350 rubles
    Meat250 rubles

    Heading below the table
    NamePrice
    Fish350 rubles
    Meat250 rubles

    In this example we created two classes, which control the position of the table header. First grade ( .topCaption) puts the table title above it, we applied it to the first table, and the second class ( .bottomCaption) places the table title below it, we applied it to the second table. Class .topCaption has the default caption-side property value and is created for demonstration purposes.

    The result of our example:

    Horizontal and vertical alignment

    In most cases, when working with tables, you will need to adjust the alignment of content within header and data cells. The text-align property is used for horizontal alignment, similar to any text information. We discussed the use of this property for text earlier in the article “”.

    To set the alignment for content in cells, you must use special keywords with the text-align property. Let's look at the use of keywords for this property in the following example.

    Example of horizontal alignment in a table
    MeaningDescription
    leftAligns cell text to the left. This is the default value (if the text direction is left to right).
    rightAligns cell text to the right. This is the default value (if the text direction is right to left).
    centerAligns cell text to the center.
    justifyStretches the lines so that each line is the same width (stretches the cell's text to fit its width).

    In this example we created four classes, which specify different horizontal alignments in cells and apply them in order to the rows of the table. The value in the cell corresponds to the value of the text-align property

    The result of our example:

    In addition to horizontal alignment, you can also define vertical alignment in table cells using the vertical-align property.

    Please note that when working with table cells, only the following values ​​* of this property are applied:

    * - Sub , super , text-top , text-bottom , length and % values ​​applied to a table cell will behave as if using the baseline value.

    Let's look at an example of use:

    Example of vertical alignment in a table
    MeaningDescription
    baselineAligns the cell's baseline with the parent's baseline. This is the default value.
    topAligns the contents of a cell vertically to the top edge.
    middleAligns the contents of a cell vertically in the middle.
    bottomAligns the contents of a cell vertically along the bottom edge.

    In this example we created four classes, which specify different vertical alignments in cells and apply them in order to the rows of the table. The value in the cell corresponds to the value of the vertical-align property that was applied to that row.

    Algorithm for placing a table layout in a browser

    CSS by default uses an algorithm for the browser to automatically arrange the table layout. In this case column width is set by the widest non-breaking content of the cell. This algorithm can be slow in some cases because the browser must read all the contents in the table before determining its final layout.

    To change the browser's table layout type with automatic on fixed, you must use the CSS property table-layout with the value fixed .

    In this case, horizontal placement depends only on the width of the table and the width of the columns, and not on the contents of the cells. The browser starts displaying the table immediately after the first row is received. As a result, a fixed algorithm allows you to create a layout for such a table faster than using the automatic option. When working with large tables, you can use a fixed algorithm to improve performance.

    Let's look at the use of this property using the following example:

    An example of using the table-layout property
    table-layout: auto;
    Name 2009 2010 2011 2012 2013 2014 2015 2016
    Wheat 125 215 2540 33287 695878 1222222 125840000 125
    table-layout: fixed;
    Name 2009 2010 2011 2012 2013 2014 2015 2016
    Wheat 125 215 2540 33287 695878 1222222 125840000 125

    In this example we:

    Styling table rows and columns

    We have already partially touched on methods for styling table rows and columns in the article “”. In this article, we looked at using the group pseudo-class, which allows you to alternate row styles in tables using values even (honest) And odd (odd), or by elementary mathematical formula.

    Let's review the techniques we covered earlier and explore new ways to style rows and columns in tables. Let's move on to examples.

    An example of using the pseudo-class:nth-child with tables
    1 2 3 4 5 6 7 8 9 10 11 12 13 14
    2
    3
    4

    In this example we:

    The result of our example:

    Let's move on to the next example, in which we will look at options for styling table rows.

    Example of styling rows in tables
    ServicePrice
    Sum 15 000
    1 1 000
    2 2 000
    3 3 000
    4 4 000
    5 5 000

    In this example we:

    • We set the width of the table to 100% of the width of the parent element, and set a solid border of 1px width for the header and data cells.
    • Set for element
    1 2 3 4 5

    In this example we:

    • We centered the table with outer margins, set the width and height of the header cells to 50px, and specified transparent border 5 pixels.
    • We established that when hovering (pseudo-class :hover) on the header cell, it receives a background blue colors, orange text color, border orange colors 5 pixels and rounding radius 100%.
    • transparent border is necessary in order to reserve space for the border, which will be displayed when hovering; if this is not done, the table will “jump”.

    The result of our example:

    The following example covers the use of HTML elements And and their stylization.

    Example of highlighting table columns
    Application No.Serviceprice, rub.Total
    1Singing 6 000 6 000
    2the washing up 2 000 2 000
    3Cleaning 1 000 1 000
    4Nagging 1 500 1 500
    5Reading 3 000 3 000

    In this example we:

    The result of our example:

    Well, the final example, which is quite difficult to understand and requires advanced knowledge in CSS, as it touches on future topics planned for detailed study in this course.

    In the previous example, we realized that the HTML element You can apply only one CSS property - background color (background-color), but you cannot directly set the background color when hovering (the :hover pseudo-class) on this element. In this example, we'll look at how to highlight a table column using only CSS.

    Example of highlighting table columns and rows on hover
    Application No.Serviceprice, rub.Total
    1Singing 6 000 6 000
    2the washing up 2 000 2 000
    3Cleaning 1 000 1 000
    4Nagging 1 500 1 500
    5Reading 3 000 3 000

    In this example we:

    • We set our table to occupy 100% of the parent element, the table cells to occupy 25% of the parent element and have a solid 1 pixel green border, the height of the header and data cells is 45px. We removed the space between the cells using the border-collapse property with the value .
    • And so, using the pseudo-element ::after we add content after each element on hover. The ::after pseudo-element is required to be used in conjunction with the content property, thanks to which we insert a block element that has a background color forestgreen and has absolute positioning.
    • Absolute positioning here is necessary to offset the element relative to the specified edge of its ancestor, and the ancestor must have a position value other than the default - static , otherwise the counting will be relative to the specified edge of the browser window, for this reason we set for the table relative positioning(relative).
    • We set the top property for our generated block, which specifies the direction in which the positioned element is offset from the top edge, and the bottom property, which specifies the direction in which the positioned element is offset from the bottom edge. For both properties, the value 0 was specified, so the block will completely occupy the element from the bottom and top of the table, the width of this block was set to 25%, this value corresponds to the width of the cell itself.
    • And the final property that we set for this block: z-index with a value of "-1" it determines the order of the positioned elements according to Z axis. This property is necessary for the text to be in front of this block, and not behind it; if you do not set a value less than zero, the block will cover the text.

    The result of our example:

    If at this stage of your study you do not understand the process of positioning elements, then do not be discouraged; this is a difficult topic to understand, which we also did not consider, but we will definitely consider it in the next article of the textbook “Positioning elements in CSS”.

    Questions and tasks on the topic

    Before moving on to the next topic, complete the practice assignment:


    If you have difficulty completing the practice task, you can always open the example in a separate window and inspect the page to understand what CSS code was used.


    2016-2020 Denis Bolshakov, you can send comments and suggestions on the site to [email protected]

    Tabular data- information that can be displayed in a table and logically divided into columns and rows. HTML tag is used to display tabular data on web pages

    , which is a container with the contents of the table. The content of an HTML table is described line by line, each line starting with an opening tag and ends with a closing tag .

    Inside a tag

    table cells represented by tags are located
    or . It is the cells that contain all the table content displayed on the web page.

    Table frame

    By default, an HTML table on a web page is displayed without a border; to add a border to the table, like all other elements, the CSS border property is used. But it is worth paying attention to the fact that if you add a frame only to an element

    , then it will be displayed around the entire table. In order for the table cells to also have a border, you will need to set the border property for the elements
    And .

    Table, th, td ( border: 1px solid black; ) Try »

    Now both the table and the cells have borders, and each cell and table have their own borders. As a result, empty space appeared between the frames; the size of this space can be controlled by the border-spacing property, which is set for the entire table. In other words, you cannot control the spacing between different cells individually.

    Even if you remove the spaces between cells using the border-spacing property value 0, the borders of the cells will touch each other, doubling the size. To combine cell borders, use the border-collapse property. It can take two meanings:

    • separate: is the default. Cells are displayed a short distance from each other, each cell has its own border.
    • collapse: joins adjacent frames into one, all spaces between cells, as well as between cells and the table frame, are ignored.
    Document's name
    NameSurname
    HomerSimpson
    MargeSimpson

    NameSurname
    HomerSimpson
    MargeSimpson
    Try »

    Table size

    After adding borders to table cells, it became noticeable that the contents of the cells were too close to the edges. To add space between the edges of cells and their contents, you can use the padding property:

    Th, td ( padding: 7px; ) Try »

    The size of a table depends on its contents, but situations often arise when the table is too narrow and it becomes necessary to stretch it. The width and height of the table can be changed using the width and height properties, setting the desired dimensions either to the table itself or to the cells:

    Table (width: 70%; ) th (height: 50px; ) Try »

    Text alignment

    By default, text in table header cells is center aligned, while text in regular cells is left aligned; using the text-align property you can control the horizontal alignment of text.

    The vertical-align CSS property allows you to control the vertical alignment of text content. By default, text is aligned vertically to the center of cells. Vertical alignment can be overridden using one of the vertical-align property values:

    • top: text is aligned to the top border of the cell
    • middle: aligns text to the center (default)
    • bottom: text is aligned to the bottom border of the cell
    Document's name
    NameSurname
    HomerSimpson
    MargeSimpson
    Try »

    Alternating the background color of table rows

    When viewing large tables that contain many rows with a lot of information, it can be difficult to keep track of what data belongs to a particular row. To help users find their way around, you can use two different background colors alternately. To create the effect described, you can use the class selector, adding it to every second row of the table:

    Document's name

    NameSurnamePosition
    HomerSimpsonfather
    MargeSimpsonmother
    BartSimpsonson
    LisaSimpsondaughter
    Try »

    Adding a class attribute to every other line is quite tedious. The pseudo-class:nth-child was added to CSS3 to provide an alternative solution to this problem. Now the interleaving effect can be achieved solely using CSS, without resorting to changing the HTML markup of the document. Using the pseudo-class:nth-child, you can select all even or odd rows of a table using one of the keywords: even (even) or odd (odd):

    Tr:nth-child(odd) ( background-color: #EAF2D3; ) Try »

    Change row background on hover

    Another way to improve the readability of tabular data is to change the background color of a row when you hover your mouse over it. This will help highlight the desired content of the table and increase the visual perception of the data.

    Implementing such an effect is very simple; to do this, you need to add a pseudo-class:hover to the table row selector and set the desired background color:

    Tr:hover ( background-color: #E0E0FF; ) Try »

    Aligning a table to the center

    Centering an HTML table is only possible if the table's width is smaller than the width of its parent element. To align the table to the center, you need to use the margin property, giving it at least two values: the first value will be responsible for the outer margin of the table at the top and bottom, and the second value will be responsible for automatic alignment to the center:

    Table ( margin: 10px auto; ) Try »

    If you need different margins at the top and bottom of the table, you can set the margin property to three values: the first will be responsible for the top margin, the second for the horizontal alignment, and the third for the bottom margin:

    Table ( margin: 10px auto 30px; )

    So, we have studied the simplest actions that can be performed with table boundaries. And now the table looks much more aesthetically pleasing. However, the filling of the cells directly rests on the boundaries. This can be easily fixed by just indenting the cells in the HTML table. And then the text inside the frame, in the cell, will be more readable.

    To indent a cell, use the attribute cellpadding for tag

    . However, there is another, more preferable option: CSS.

    In this case, the indentation is set using the property padding. With its help, it will not be difficult to indent where necessary, that is, at the top, right, bottom or left, using, respectively, one of these properties: padding-top, padding-right, padding-bottom And padding-left.

    You can specify exactly how many pixels the indentation should be. Let's give an example in which the bottom indent will be 20 pixels, and all the rest will be 10 . Such CSS-the code will look like this:

    Td ( padding: 10px; padding-bottom: 20px; )

    And the complete style code at this stage:

    Table ( border: solid 1px blue; border-collapse: collapse; ) td ( border: solid 1px blue; padding: 10px; padding-bottom: 20px; )

    Result in browser:

    Spaces between cells

    As a rule, problems associated with creating tables can be solved by using tags, attributes and properties that allow you to create frames, indents in cells, and also set the color background of the cells themselves.

    Indents in tables are not only found inside cells. They may also be present between the cells themselves.

    There are two options for making indents between cells:

    1. using attribute cellspacing for tag
    .
  • using CSS-properties border-spacing.
  • It must be emphasized that border-spacing is specified for the table as a whole, while the property padding is written directly for cells.

    Let's look at an example:

    Table ( border: solid 1px blue; border-collapse: separate; border-spacing: 5px; ) td ( border: solid 1px blue; padding: 10px; padding-bottom: 20px; )

    And the resulting result:

    Let us immediately stipulate that you should not try to make such indentations using border-collapse: collapse. After all, when using this option, the cells “stick” to each other.

    And to keep them separate from each other, you should use border-collapse: separate. It is important to understand that this value is the default value. And it is used only to clearly show how this problem is solved. If we delete this line, the result in the form of cells located separately from each other will be saved.

    Share with friends or save for yourself:

    Loading...