HTML dl, dt, dd tags to create a table vs. Table creation table

HTML dl, dt, dd tags to create a table vs. Table creation table
Not only does it reduce the cost of website development and maintenance, but the code is also more semantic. However, it does not mean that tables have disappeared. They are still used by many people as a necessity for data presentation on web pages, such as lists of personal information data. In fact, using HTML's dl, dt, and dd tags will save you more code and make the code more semantically consistent with the content. Of course, tables have their uses, and that is for data tables with large amounts of data, but small data lists and forms do not require tables at all!

dl列表和table表格哪個更適合數據列表

If you are still using traditional tables to create data lists, please read on to see how using HTML's dl, dt, and dd tags can make your work easier...

table data list

The data list code of the traditional table is as follows. We need to add a tr tag for each row, and then add a td tag for the title and data. Since the tags are all td, if we want to add styles, we also need to add a class attribute to each td.


Copy code
The code is as follows:

<table>
<tbody>
<tr>
<td class="title">Name:</td>
<td class="text">Squall Li</td>
</tr>
<tr>
<td class="title">Age:</td>
<td class="text">23</td>
</tr>
<tr>
<td class="title">Gender:</td>
<td class="text">Male</td>
</tr>
<tr>
<td class="title">Day of Birth:</td>
<td class="text">26th May 1986</td>
</tr>
</tbody>
</table>

Below is the corresponding CSS code. We add styles to the classes declared in the HTML before.


Copy code
The code is as follows:

/*TABLE LIST DATA*/
table {
margin-bottom:50px;
}
table tr .title {
background:#5f9be3;
color:#fff;
font-weight:bold;
padding:5px;
width:100px;
}
table tr .text {
padding-left:10px;
}

As can be seen from the above code, when using the table tag, if you want to use CSS to modify or modify the content, you need to add some corresponding class attributes to the td cell. This will invisibly increase your workload and the code will become a little more. What does more code mean? This means that the website traffic is wasted, the chance of bugs is increased, and subsequent maintenance is more difficult.

dl, dt, dd data list

Now let's look at data lists using the HTML dl, dt, and dd tags. First we use the dl (definition list) tag to hold the entire data structure, and then we use the dt (custom title) tag and dd (custom description) tag to hold the title and content in the data.


Copy code
The code is as follows:

<dl>
<dt>Name: </dt>
<dd>Squall Li</dd>
<dt>Age: </dt>
<dd>23</dd>
<dt>Gender: </dt>
<dd>Male</dd>
<dt>Day of Birth:</dt>
<dd>26th May 1986</dd>
</dl>

In the CSS code, we only need to float dt and dd to the left.
/*DL, DT, DD TAGS LIST DATA*/


Copy code
The code is as follows:

dl {
margin-bottom:50px;
}
dl dt {
background:#5f9be3;
color:#fff;
float:left;
font-weight:bold;
margin-right:10px;
padding:5px;
width:100px;
}
dl dd {
margin:2px 0;
padding:5px 0;
}

From the examples of dl, dt, and dd, you should be able to clearly see that their codes are simpler, smoother, and more semantic.

Seeing this, if you still insist on using table tags to complete web forms or other web page layouts, now is the time to change your code. Make your work easier!

<<:  Prototype and prototype chain prototype and proto details

>>:  Each time Docker starts a container, the IP and hosts specified operations

Recommend

Prevent HTML and JSP pages from being cached and re-fetched from the web server

After the user logs out, if the back button on the...

Specific use of CSS front-end page rendering optimization attribute will-change

Preface When scroll events such as scroll and res...

CSS Transition expands and collapses elements by changing the Height

A common development need is that we want to coll...

Implementation method of Nginx+tomcat load balancing cluster

The experimental environment is as follows Here y...

Use of environment variables in Docker and solutions to common problems

Preface Docker can configure environment variable...

Docker+nextcloud to build a personal cloud storage system

1. Docker installation and startup yum install ep...

JavaScript implements password box verification information

This article example shares the specific code of ...

Detailed tutorial on MySQL installation and configuration

Table of contents Installation-free version of My...

Summary of block-level elements, inline elements, and variable elements

Block element p - paragraph pre - format text tabl...

How to implement MySQL master-slave replication based on Docker

Preface MySQL master-slave replication is the bas...

Solve the problem of blocking positioning DDL in MySQL 5.7

In the previous article "MySQL table structu...

Detailed explanation of JavaScript function this pointing problem

Table of contents 1. The direction of this in the...

Jenkins builds Docker images and pushes them to Harbor warehouse

Table of contents Dockerfile pom.xml Jenkins Conf...

Detailed analysis of GUID display issues in Mongodb

Find the problem I recently migrated the storage ...