Example of how to change the line spacing of HTML table

Example of how to change the line spacing of HTML table

When using HTML tables, we sometimes need to change the line spacing, but changing margin, padding, collapse and other methods are not very effective. Here I found a useful little trick. Use the display attribute + margin to achieve this.
example:

tr{margin-top:0px;padding:0px;display:block;}

Let's take a look at the comparison


tr{margin-top:-10px;padding:0px;display:block;}


It can be clearly seen that the line spacing has been shortened a lot.

Other solutions

Question:

The default display of tr in table is display:table-row. Although it can be changed to display:block, it will lose the unique display effects of tr, such as (automatic alignment of td);

And it is useful to set padding in tr, which can increase the inner margin, but it is useless to set margin, the outer spacing of tr is still 0;

Solution:

Two CSS properties: border-collapse:collapse / separate & border-spacing:10px 10px;

Need to use border-collapse & border-spacing to control the spacing of tr;

like:

<table style="border-collapse:separate; border-spacing:10px;">
    <tr></tr>
</table>

This is the end of this article about examples of how to change the line spacing of HTML tables. For more relevant content about HTML table line spacing, please search 123WORDPRESS.COM’s previous articles or continue to browse the following related articles. I hope that everyone will support 123WORDPRESS.COM in the future!

<<:  Sharing the structure and expression principles of simple web page layout

>>:  CSS3 uses transform-origin to achieve dot distribution on a large circle and rotation effects

Recommend

Vuex implements simple shopping cart function

This article example shares the specific code of ...

Code to display the contents of a txt book on a web page

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML ...

The vue project realizes drawing a watermark in a certain area

This article shares with you how to use Vue to dr...

IDEA complete code to connect to MySQL database and perform query operations

1. Write a Mysql link setting page first package ...

Ubuntu 20.04 Best Configuration Guide (Newbie Essential)

1. System Configuration 1. Turn off sudo password...

Analysis of the use and principle of Docker Swarm cluster management

Swarm Cluster Management Introduction Docker Swar...

Vue component organization structure and component registration details

Table of contents 1. Component Organization 2. Co...

MySQL series 15 MySQL common configuration and performance stress test

1. Common MySQL configuration All the following c...

TypeScript enumeration basics and examples

Table of contents Preface What are enums in TypeS...

CentOS 6 uses Docker to deploy redis master-slave database operation example

This article describes how to use docker to deplo...

Detailed installation tutorial of mysql 5.7 under CentOS 6 and 7

You always need data for development. As a server...

Introduction to the use of select optgroup tag in html

Occasionally, I need to group select contents. In ...