CSS - Tables

Tables

In this tutorial, I will be showing you how to style HTML tables using CSS styling properties.

TABLE BORDERS

The table-border property is used to add borders to your HTML tables.

COLLAPSE BORDERS

The collapse-border property is used to collapse table cell borders into a single border.

note
NOTE:

The default value for border-collapse is separate separate which separates each cell borders.


SPACING

The spacing inside the table cells and between the borders of the cells can be adjusted using the padding and border-spacing properties.

WIDTH AND HEIGHT

Table can be set to occupy the entire width. Height of each table tags (th, tr, td) can also be set to you desired value or choice.

TABLE DATA ALIGNMENT

The text-align and vertical-align properties are used to align table data horizontally and vertically depending on the specified value.

TABLE LAYOUT

The table expands and contracts to accommodate its data. The table-layout property is used to set whether the table should adjust its cells, rows and columns (depending on the size of the data) or not. Its values include:

TABLE CAPTION POSITION

The caption-side property is used in CSS to set the positioning of the table caption. Its value includes:

  • top
  • bottom
  • block-start
  • block-end
  • inline-start
  • inline-end
  • inherit

EMPTY CELLS

The empty-cells property is used in CSS to control how cells which has no data are being handled.

  • show - show borders and backgrounds.
  • hide - do not show any borders and backgrounds.

STRIPED TABLES

The nth-child() pseudo class selector is used in CSS to give your table a zebra-strip. You can add a background color to all even or odd table rows.

HOVERABLE TABLE

You can add hover effect to your table row, to highlight it anytime you place your mouse on top each row. This is done using the :hover pseudo class selector.

RESPONSIVE TABLE

The ability of the table to automatically add horizontal and vertical scrollbars if the screen of the device or the size of the container is too small to display the full data. This is done using the overflow-x property in CSS.

tips
TIP:

Other styling that can be applied to HTML elements can also be applied to table such as: font-family, font-weight, letter-spacing, color and many more.

ADVERTISEMENTS

LEARNING IS A CONTINOUS PROCESS - PRACTICE MAKES PERFECT