Table of Contents
Example
Output
Home Web Front-end CSS Tutorial Styling Tables Working with CSS

Styling Tables Working with CSS

Aug 19, 2023 pm 02:29 PM

We can use CSS to define the style of the table. The following properties are used to define styles for <table> and its elements:

  • border

    The border property of CSS is used to define the border width, border style, and border color.

  • border-collapse

    This attribute is used to specify whether the <table> element should have a shared or independent border.

  • caption

    caption-side property is used to position the table title box vertically.

  • empty-cells

    This property is used to specify how empty cells in the table are displayed.

  • table-layout is used to define the algorithm used by the browser when laying out the rows, columns, and cells of a table.

Example

The following example demonstrates the style of the table:

Real-time demonstration

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

&lt;!DOCTYPE html&gt;

&lt;html&gt;

&lt;head&gt;

&lt;style&gt;

body {

   font-family: &#39;Bookman Old Style&#39;, serif;

}

th {

   letter-spacing: 1.9px;

}

#one {

   border-right: thick solid blue;

}

td {

   text-align: center;

}

&lt;/style&gt;

&lt;/head&gt;

&lt;body&gt;

&lt;h2&gt;Employee List&lt;/h2&gt;

&lt;div&gt;

&lt;table&gt;

&lt;tr&gt;

&lt;th id=&quot;one&quot;&gt;Employee&lt;/th&gt;

&lt;th&gt;Department&lt;/th&gt;

&lt;/tr&gt;

&lt;tr&gt;

&lt;td&gt;John &lt;/td&gt;

&lt;td&gt;Marketing&lt;/td&gt;

&lt;/tr&gt;

&lt;tr&gt;

&lt;td&gt;Brad&lt;/td&gt;

&lt;td&gt;Finance&lt;/td&gt;

&lt;/tr&gt;

&lt;tr&gt;

&lt;td&gt;Tim &lt;/td&gt;

&lt;td&gt;IT&lt;/td&gt;

&lt;/tr&gt;

&lt;tr&gt;

&lt;td&gt;Steve&lt;/td&gt;

&lt;td&gt;Operations&lt;/td&gt;

&lt;/tr&gt;

&lt;/table&gt;

&lt;/div&gt;

&lt;/body&gt;

&lt;/html&gt;

Copy after login

Output

This gives the following output −

Styling Tables Working with CSS

Example

Live Demo

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

&lt;!DOCTYPE html&gt;

&lt;html&gt;

&lt;head&gt;

&lt;style&gt;

table {

   float: left;

   empty-cells: hide;

   box-shadow: inset 0 0 4px orange;

}

tr {

   box-shadow: inset 0 0 10px greenyellow;

}

td {

   font-style: italic;

   box-shadow: inset 0 0 8px red;

}

table,td {

   margin: 6px;

   padding: 6px;

   border: 1px solid black;

}

table

&lt;/style&gt;

&lt;/head&gt;

&lt;body&gt;

&lt;table&gt;

&lt;caption&gt;Demo Table&lt;/caption&gt;

&lt;tr&gt;

&lt;th&gt;Head 1&lt;/th&gt;

&lt;th&gt;Head 2&lt;/th&gt;

&lt;th&gt;Head 3&lt;/th&gt;

&lt;/tr&gt;

&lt;tr&gt;

&lt;td&gt;demo&lt;/td&gt;

&lt;td&gt;&lt;/td&gt;

&lt;/tr&gt;

&lt;tr&gt;

&lt;td&gt;&lt;/td&gt;

&lt;td&gt;&lt;/td&gt;

&lt;td&gt;demo&lt;/td&gt;

&lt;/tr&gt;

&lt;tr&gt;

&lt;td&gt;&lt;/td&gt;

&lt;td&gt;demo&lt;/td&gt;

&lt;td&gt;&lt;/td&gt;

&lt;/tr&gt;

&lt;/table&gt;

&lt;/body&gt;

&lt;/html&gt;

Copy after login

Output

This gives the following output −

Styling Tables Working with CSS

The above is the detailed content of Styling Tables Working with CSS. For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot Article Tags

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Adding Box Shadows to WordPress Blocks and Elements Adding Box Shadows to WordPress Blocks and Elements Mar 09, 2025 pm 12:53 PM

Adding Box Shadows to WordPress Blocks and Elements

Create a JavaScript Contact Form With the Smart Forms Framework Create a JavaScript Contact Form With the Smart Forms Framework Mar 07, 2025 am 11:33 AM

Create a JavaScript Contact Form With the Smart Forms Framework

Create an Inline Text Editor With the contentEditable Attribute Create an Inline Text Editor With the contentEditable Attribute Mar 02, 2025 am 09:03 AM

Create an Inline Text Editor With the contentEditable Attribute

Working With GraphQL Caching Working With GraphQL Caching Mar 19, 2025 am 09:36 AM

Working With GraphQL Caching

Making Your First Custom Svelte Transition Making Your First Custom Svelte Transition Mar 15, 2025 am 11:08 AM

Making Your First Custom Svelte Transition

Comparing the 5 Best PHP Form Builders (And 3 Free Scripts) Comparing the 5 Best PHP Form Builders (And 3 Free Scripts) Mar 04, 2025 am 10:22 AM

Comparing the 5 Best PHP Form Builders (And 3 Free Scripts)

File Upload With Multer in Node.js and Express File Upload With Multer in Node.js and Express Mar 02, 2025 am 09:15 AM

File Upload With Multer in Node.js and Express

Show, Don't Tell Show, Don't Tell Mar 16, 2025 am 11:49 AM

Show, Don't Tell

See all articles