How To Set Fixed Width For Regardless Of Its Content

TutorialRepublic HOME HTML5 CSS3 JAVASCRIPT JQUERY BOOTSTRAP5 v4.6 PHP7 SQL REFERENCES EXAMPLES FAQ SNIPPETS Online HTML Editor WEB TUTORIALS HTML Tutorial CSS Tutorial JavaScript Tutorial jQuery Tutorial Bootstrap Tutorial PHP Tutorial SQL Tutorial PRACTICE EXAMPLES HTML Examples CSS Examples JavaScript Examples jQuery Examples Bootstrap Examples PHP Examples HTML REFERENCES HTML Tags/Elements HTML Global Attributes HTML Event Attributes HTML Color Picker HTML Language Codes HTML Character Entities HTTP Status Codes CSS REFERENCES CSS At-rules CSS Properties CSS Animatable Properties CSS Color Values CSS Color Names CSS Web Safe Fonts CSS Aural Properties PHP REFERENCES PHP Array Functions PHP String Functions PHP File System Functions PHP Date/Time Functions PHP Calendar Functions PHP MySQLi Functions PHP Filters PHP Error Levels How to Set Fixed Width for <td> Regardless of its Content

Topic: HTML / CSSPrev|Next

Answer: Use the CSS table-layout Property

If you try to set fixed width for the table columns or <td> by simply applying the width property it may not work, because the default table layout algorithm is automatic. Therefore, first change the table's table-layout property to fixed then the width property will have any effect.

The following example will set up fixed width for the table columns regardless of the amount of text in its cells. Let's try it out to understand how it basically works:

Example

Try this code » <!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <title>Set Fixed Width for Table Columns</title> <style> table { width: 300px; } th, td { width: 50%; } table.fixed { table-layout: fixed; } table, th, td{ border: 1px solid black; } </style> </head> <body> <table> <caption>Example 1. Auto</caption> <tr> <th>Name</th> <th>Email</th> </tr> <tr> <td>John Carter</td> <td>[email protected]</td> </tr> </table> <br> <table class="fixed"> <caption>Example 2. Fixed</caption> <tr> <th>Name</th> <th>Email</th> </tr> <tr> <td>Peter Parker</td> <td>[email protected]</td> </tr> </table> </body> </html>

Related FAQ

Here are some more FAQ related to this topic:

  • How to remove cellspacing from tables using CSS
  • How to highlight alternate table row using CSS
  • How to make a DIV not larger than its contents using CSS
Previous Page Next Page Bootstrap UI Design Templates Property Marvels - A Leading Real Estate Portal for Premium Properties

Is this website helpful to you? Please give us a like, or share your feedback to help us improve. Connect with us on Facebook and Twitter for the latest updates.

About Us

Our Story Terms of Use Privacy Policy

Contact

Contact Us Report Error Advertise

Interactive Tools

Bootstrap Icon Search Utility HTML Formatter Title & Meta Length Calculator HTML Color Picker Bootstrap Button Generator SQL Playground Font Awesome Icon Finder HTML Editor

TutorialRepublic

BMC Copyright © 2024 Tutorial Republic. All Rights Reserved. Share This:

Từ khóa » Html Cell Width Fixed