Set the width of the table to be fixed so that it does not change with the text

Set the width of the table to be fixed so that it does not change with the text
After setting the table width in the page to width="600px", the width is still not fixed. The text does not wrap when it is too long, which deforms the table.

Solution:

1. Table sets width, both absolute and relative width are acceptable

table-layout:fixed;
With this property set, all remaining td's will have the same width.

After this operation, the width of the table is fixed, but if the article inside is very long, the text will cover the

Solution:

Add style="word-wrap:break-word;" to the td to wrap the text. If you don't want to wrap the text, you can hide the content that exceeds the limit and replace it with an ellipsis:

Add above td

Copy code
The code is as follows:

overflow:hidden;
white-space:nowrap;

text-overflow:ellipsis; (currently only tested in IE8)
Recommended method (2013-11-14 by Zhang Lei) Use div to control the content of td

Add in TD

(1) Text will be automatically hidden if it exceeds the width and height

Copy code
The code is as follows:

<div style="width:100px;height:25px;overflow-x:hidden;overflow-y:hidden;">aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa</div>

(2) Set the TD width to automatically wrap when it exceeds the length

Copy code
The code is as follows:

<td><div style="width:100px;word-wrap:break-word;" >aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa</div>
</td>

<<:  Explore how an LED can get you started with the Linux kernel

>>:  Introduction to document.activeELement focus element in JavaScript

Recommend

Html sample code for reading and displaying pictures in a local folder

One purpose Select a local folder on the Html pag...

MySQL dual-machine hot standby implementation solution [testable]

Table of contents 1. Concept 2. Environmental Des...

How to configure static network connection in Linux

Configuring network connectivity for Linux system...

How to install Docker using scripts under Linux Centos

What is the main function of Docker? At present, ...

About the location of the H1 tag in XHTML

There has been a lot of discussion about H1 recent...

MySQL DML language operation example

Additional explanation, foreign keys: Do not use ...

An article teaches you how to implement a recipe system with React

Table of contents 1. Recipe Collection 1.1 Projec...

MySql index improves query speed common methods code examples

Use indexes to speed up queries 1. Introduction I...

The difference between MySQL execute, executeUpdate and executeQuery

The differences among execute, executeUpdate, and...

Websocket+Vuex implements a real-time chat software

Table of contents Preface 1. The effect is as sho...

Linux CentOS6.9 installation graphic tutorial under VMware

As a technical novice, I am recording the process...

8 Reasons Why You Should Use Xfce Desktop Environment for Linux

For several reasons (including curiosity), I star...

Summary of MySQL common SQL statements including complex SQL queries

1. Complex SQL queries 1.1. Single table query (1...