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

Understand the use of CSS3's all attribute

1. Compatibility As shown below: The compatibilit...

Summary of Form Design Techniques in Web Design

“Inputs should be divided into logical groups so ...

A small question about the execution order of SQL in MySQL

I encountered a sql problem at work today, about ...

WeChat applet custom scroll-view example code

Mini Program Custom Scroll-View Scroll Bar Withou...

JavaScript implements the generation of 4-digit random verification code

This article example shares the specific code for...

TypeScript installation and use and basic data types

The first step is to install TypeScript globally ...

Complete steps to use samba to share folders in CentOS 7

Preface Samba is a free software that implements ...

MySQL log trigger implementation code

SQL statement DROP TRIGGER IF EXISTS sys_menu_edi...

How to write asynchronous tasks in modern JavaScript

Preface In this article, we'll explore the ev...

JavaScript design pattern learning adapter pattern

Table of contents Overview Code Implementation Su...

Summary of @ usage in CSS (with examples and explanations)

An at-rule is a declaration that provides instruc...