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

jQuery simulates picker to achieve sliding selection effect

This article shares the specific code of jQuery t...

Comparison of the usage of EXISTS and IN in MySQL

1. Usage: (1) EXISTS usage select a.batchName,a.p...

How to build a redis cluster using docker

Table of contents 1. Create a redis docker base i...

In-depth analysis of MySQL indexes

Preface We know that index selection is the work ...

JavaScript gets the scroll bar position and slides the page to the anchor point

Preface This article records a problem I encounte...

A detailed introduction to for/of, for/in in JavaScript

Table of contents In JavaScript , there are sever...

Detailed Explanation of JavaScript Framework Design Patterns

Table of contents mvc mvp mvvm The source of Vue ...

Linux /etc/network/interfaces configuration interface method

The /etc/network/interfaces file in Linux is used...

Use of Linux usermod command

1. Command Introduction The usermod (user modify)...

JavaScript file loading and blocking issues: performance optimization case study

Let me start with a question: When writing an HTM...

MySQL green version setting code and 1067 error details

MySQL green version setting code, and 1067 error ...

MySQL Optimization: Cache Optimization (Continued)

There are caches everywhere inside MySQL. When I ...