Setting the width of table cell td is invalid and the internal content always stretches it

Setting the width of table cell td is invalid and the internal content always stretches it
When making a table page, sometimes the width set for td is invalid. The width of td is always expanded by the internal content. You can set padding, but setting width directly is invalid. Let's take a closer look at this example:

Copy code
The code is as follows:

<div>
<table border="1px">
<tr>
<td width="100px" style="width: 100px !important;">1000800</td>
<td>1000000</td>
<td>1000000</td>
</tr>
<tr>
<td>1000000</td>
<td>10000300</td>
<td>1000000</td>
</tr>
</table>
</div>
<table border="1px">
<tr>
<td width="100px">1000000</td>
<td>1000000</td>
<td>1000000</td>
</tr>
<tr>
<td>1000000</td>
<td>10000300</td>
<td>1000000</td>
</tr>
</table>
* {margin: 0; padding: 0;}
.div1 {position: relative; width: 150px; height: 100px; overflow: scroll; border: 1px solid red;}


We can see that although the width of the first cell in class div1 is set, it is invalid. The cell content is always determined by the content. Since it is determined by the content, we should find a way to let the "content" expand the cell. That's it.

We can add a div in td and set the width of the div. Let's try it:

Modify part of the code in class div1:

Copy code
The code is as follows:

<td width="100px" style="width: 100px !important;">1000800</td>

Modified to

Copy code
The code is as follows:

<td><div>1000800</div></td>

Then write in the style:

Copy code
The code is as follows:

td div {
width:100px;
}

Refresh the page, and the effect is as follows:

We can see that the width of the cells in class div1 has taken effect.

<<:  How to make a tar file of wsl through Docker

>>:  Example code for building an admin dashboard layout using CSS and JavaScript

Recommend

jQuery implements breathing carousel

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

Introduction to SSL certificate installation and deployment steps under Nginx

Table of contents Problem description: Installati...

Solve the conflict between docker and vmware

1. Docker startup problem: Problem Solved: You ne...

MySQL 8.0.12 winx64 decompression version installation graphic tutorial

Recorded the installation of mysql-8.0.12-winx64 ...

How to use CSS to display multiple images horizontally in the center

Let me first talk about the implementation steps:...

A brief understanding of the three uses of standard SQL update statements

1. Environment: MySQL-5.0.41-win32 Windows XP Pro...

Detailed comparison of Ember.js and Vue.js

Table of contents Overview Why choose a framework...

Develop calculator example code using native javascript

The main function of a calculator is to perform n...

MySQL SQL statement analysis and query optimization detailed explanation

How to obtain SQL statements with performance iss...

Native JavaScript implementation of progress bar

The specific code for JavaScript to implement the...

Using MySQL database with Python 3.4 under Windows 7

The detailed process of using MySQL database with...

Docker builds python Flask+ nginx+uwsgi container

Install Nginx First pull the centos image docker ...