bugl
bugl
HomeLearnPatternsPathsSearchPremium
HomeLearnPatternsPaths

Loading lesson path

Learn/CSS/CSS Foundations
CSS•CSS Foundations

CSS Responsive Tables

A responsive table will display a horizontal scrollbar if the screen is too small to display the full content.

Resize the browser window to see the effect:

First NameLast NamePointsPointsPointsPointsPointsPointsPointsPointsPointsPointsPointsPoints
JillSmith505050505050505050505050
EveJackson949494949494949494949494
AdamJohnson676767676767676767676767

How to do it

Wrap the <table> element in a <div> container.

Set the overflow-x property to auto for the <div> element:

Example

Formatted code
div.tablecontainer {
  overflow-x: auto;
}

Live preview

Note

In OS X Lion (on Mac), scrollbars are hidden by default and are only shown when being used (even though "overflow:scroll" is set).

CSS Table Properties

PropertyDescription
borderSets all the border properties in one declaration
border-collapseSpecifies whether or not table borders should be collapsed
border-spacingSpecifies the distance between the borders of adjacent cells
caption-sideSpecifies the placement of a table caption
empty-cellsSpecifies whether or not to display borders and background on empty cells in a table
table-layoutSets the layout algorithm to be used for a table

Previous

CSS Table Styling

Next

CSS The display Property