官术网_书友最值得收藏!

  • Web Developer's Reference Guide
  • Joshua Johanan Talha Khan Ricardo Zea
  • 430字
  • 2021-07-09 20:18:26

Tables

Tables, tables, tables! Together with images, HTML tables are the black sheep of web design.

Regardless of being the black sheep, the power of tables is amazing. And if there's an HTML element that does its job well, very well, it's tables.

Let's dig in.

table-layout

The table-layout CSS property allows us to define the how HTML tables are laid out on the document, and it looks like this:

table-layout: fixed;
Description

There are two keyword values: auto and fixed.

  • auto: This is the default value. Tables are automatically laid out by the browser this way without declaring anything in the CSS. The table cells adapt to the content inside of them; the behavior of table can sometimes be unpredictable.
  • fixed: By declaring the width of the table cells from the first row, the rendering of the entire table can be actually faster; anything we do to improve performance is big win for everyone.

Since the table cells have a fixed width, depending on the data in the cells, some information can overflow the cells. Using a combination of the overflow properties and text-overflow: ellipsis; we can fix the issue.

CSS:

table {
  table-layout: fixed;
}

border-collapse

The border-collapse CSS property tells the table cells to stay separated or get close together (collapse), and it looks like this:

border-collapse: collapse;
Description

This property supports two keyword values: separate and collapse.

  • separate: This is the default value. There is a space between the table cells, and each cell has its own border.
  • collapse: This value brings the cells together, thus the space is lost and the cells share borders.

CSS:

table {
  border-collapse: collapse;
}

border-spacing

The border-spacing CSS property creates a space between the table cells, and it looks like this:

border-spacing: 10px;
Description

The border-spacing property only works when the border-collapse: separate; declaration is present.

CSS:

table {
  border-collapse: separate;
  border-spacing: 10px;
}

empty-cells

The empty-cells CSS property allows us to define how browsers should render borders and backgrounds on cells that have no content in them, and it looks like this:

empty-cells: hide;
Description

The empty-cells property supports two keyword values: show and hide, which determine whether the borders and background should, or should not, be rendered.

CSS:

table {
  empty-cells: hide;
}

caption-side

The caption-side CSS property defines the location of the table caption, and it looks like this:

caption-side: bottom;
Description

It supports two keyword values: top and bottom.

In CSS 2, other keyword values, such as left and right, were supported, but they were dropped in CSS 2.1.

CSS:

caption {
  caption-side: bottom;
}
主站蜘蛛池模板: 江门市| 万载县| 闽清县| 丰顺县| 蒲江县| 澄迈县| 宜黄县| 临潭县| 惠东县| 吉水县| 清原| 涟源市| 淄博市| 大厂| 开江县| 清徐县| 永康市| 汉阴县| 扎囊县| 呼伦贝尔市| 湖州市| 奉节县| 大同市| 太原市| 通州市| 越西县| 河东区| 招远市| 东平县| 修文县| 五峰| 阿坝县| 桑日县| 巴青县| 祥云县| 云南省| 十堰市| 赤壁市| 建始县| 沁水县| 澜沧|