How To Set The Width Of The Table Column - W3docs
Có thể bạn quan tâm
- Password Generator
- HTML Editor
- HTML Encoder
- Base 64
- Code Diff
- JSON Beautifier
- CSS Beautifier
- Markdown Convertor
- Find the Closest Tailwind CSS Color
- Phrase encrypt / decrypt
- Browser Feature Detection
- Number convertor
- CSS Maker
- CSS Maker text shadow
- CSS Maker Text Rotation
- CSS Maker Out Line
- CSS Maker RGB Shadow
- CSS Maker Transform
- CSS Maker Font Face
- Color Picker
- Colors CMYK
- Colors HWB
- Colors HSL
- Color Hex
- Color mixer
- Color Converter
- Colors RGB
- Color Contrast Analyzer
- Color Gradient
- String Length Calculator
- MD5 Hash Generator
- Sha256 Hash Generator
- String Reverse
- URL Encoder
- URL Decoder
- Base 64 Encoder
- Base 64 Decoder
- Extra Spaces Remover
- String to Lowercase
- String to Uppercase
- Word Count Calculator
- Empty Lines Remover
- HTML Tags Remover
- Binary to Hex
- Hex to Binary
- Rot13 Transform on a String
- String to Binary
- Duplicate Lines Remover
- Dark
- Light
- System
- Books
- Learn HTML
- Learn CSS
- Learn Git
- Learn Javascript
- Learn PHP
- Learn python
- Learn Java
- How To
- How To NodeJs
- How To Linux
- How To AngularJs
- How To PHP
- How To HTML
- How To CSS
- How To Symfony
- How To Git
- How To Apache
- How To JavaScript
- How To Java
- How To Vue.js
- How To Python
- Snippets
- CSS
- How to Set the Width of the Table Column
Solution with the CSS width property
If you want to set the width of the table column, you can use some CSS. You need to use the width property.
In the example below, we set the width of the the <table> element to 100%. Then, in the HTML part, we distribute the table width of 100% among <col> elements having span attributes. But you’re free to decide to specify the properties in HTML, or CSS.
Here, we use the :first-child, :nth-child, and :last-child pseudo-classes on <td> elements and style them with background-color.
Example of the setting the width of the table column:
<!DOCTYPE html> <html> <head> <title>Title of the document</title> <style> table { width: 100%; } td:first-child { background-color: #32a852; } td:nth-child(2) { background-color: #aaaaaa; } td:last-child { background-color: #5696c7; } </style> </head> <body> <table> <colgroup> <col span="1" style="width: 20%;"> <col span="1" style="width: 50%;"> <col span="1" style="width: 30%;"> </colgroup> <tbody> <tr> <td>20%</td> <td>50%</td> <td>30%</td> </tr> </tbody> </table> </body> </html> Try it Yourself »Result
20% | 50% | 30% |
How to expand the last column in the table without expanding the table?
To expand the width of the last column in the table without changing the width of the entire table, you can set the width property of the last column using a percentage value that is larger than the current width.
<!DOCTYPE html> <html> <head> <title>Title of the document</title> <style> table { width: 100%; } td:first-child { background-color: #32a852; } td:nth-child(2) { background-color: #aaaaaa; } td:last-child { background-color: #5696c7; width: 60%; /* set width of last column to 60% */ } </style> </head> <body> <table> <colgroup> <col span="1" /> <col span="1" /> <col span="1" /> </colgroup> <tbody> <tr> <td>A</td> <td>C</td> <td>C</td> </tr> </tbody> </table> </body> </html> Try it Yourself » Copy Tags column html css table width Sorry about that How can we improve it? Submit Thanks for your feedback! Thanks for your feedback! Do you find this helpful? Yes No Quizzes- PHP basics
- HTML Basics
- Javascript Basics
- CSS Basics
- ES6 Basics
- TypeScript Basics
- React Basics
- Angular Basics
- Sass Basics
- Git Basics
- Vue.js Basics
- SQL Basics
- Python Basics
- Java Basics
- NodeJS Basics
Từ khóa » Html Change Column Width Table
-
HTML Table Sizes - W3Schools
-
Setting Table Column Width - Html - Stack Overflow
-
Changing Column Width - The Complete HTML5 Tutorial
-
How To Fix The Width Of Columns In The Table ? - GeeksforGeeks
-
How To Set Fixed Width For
In A Table ? - GeeksforGeeks Stop Using To Set Table Width In HTML: Here's Why »
Table-layout - CSS: Cascading Style Sheets - MDN Web Docs
How To Set The Table Column Width Regardless Of The Text Amount ...
How Can I Adjust Column Widths In HTML Table Within An Email Body?
Making A Wild Card Column Width - Tables
DataTable Width & Column Width | Dash For Python Documentation
Advanced Table Settings: Column Width, Alignment And Merging Cells
Set Table Column Width - MATLAB & Simulink - MathWorks
Chapter 3. How To Specify Tables And Columns Width
Copyright © 2022 | Thiết Kế Truyền Hình Cáp Sông Thu