473,387 Members | 1,542 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

How to make a column data adjust itself to the width of the cell

Hi,
Iam making a report based on some database values. The fields are displayed in different columns of a table(Iam using php+mysql). My problem is that how can I make the width of a column fixed and make the data insert new line itself whenever the content exceed the width.

Thanks & Regards,
Appu
Jan 23 '08 #1
2 2218
Hi,
Iam making a report based on some database values. The fields are displayed in different columns of a table(Iam using php+mysql). My problem is that how can I make the width of a column fixed and make the data insert new line itself whenever the content exceed the width.

Thanks & Regards,
Appu
Hi,
Fix the width of table and every column in numbering.
Expand|Select|Wrap|Line Numbers
  1. <table width="500"></table>
  2. <tr><td width="300"></td>
  3. <td width="200"></td>
  4. </tr>
  5. </table>
so whenever first column data is exeed the width then it will be start from new line
Jan 23 '08 #2
Atli
5,058 Expert 4TB
Hi,
Fix the width of table and every column in numbering.
Expand|Select|Wrap|Line Numbers
  1. <table width="500"></table>
  2. <tr><td width="300"></td>
  3. <td width="200"></td>
  4. </tr>
  5. </table>
so whenever first column data is exeed the width then it will be start from new line
Hi.

This will work 99% of the time, but if you have huge words, without spaces, most browsers will stretch the cell to fit the line.

Like for example:
Expand|Select|Wrap|Line Numbers
  1. <table border="1">
  2.   <tr>
  3.     <td width="10">
  4.       1234567890abcdefg...etc...
  5.     </td>
  6.   </tr>
  7. </table>
  8.  
If you try this HTML you will find that the cell far exceeds the 10px limit I set for it.

If you run into this problem, you should check out the wordwrap PHP function.
(Works well with fonts like 'Courier New')

There is, unfortunately, no standard way to have the cell automatically wrap long words. We must resort to some sort of Javascript or server-side trickery to manage that.

The closes standard way to handle situations like these is the CSS overflow property, but it's usefulness is extremely limited.

P.S.
sandeepsandeep, please put your code inside [code] tags, and don't just put it in bold. It's much more readable that way.
Jan 24 '08 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

9
by: Eric | last post by:
I would like to setup a two column layout for my web page using CSS. I would like the Left column width to be auto. Can I have the right column be offset by 8 pixels from the right edge of the...
5
by: javaguy | last post by:
I have a data entry web application that is formatted heavily with tables. Having learned a bit of CSS, I'm hoping to rewrite this using <div> tags. But I have run into a formatting problem that...
9
by: kojim | last post by:
Test page: http://www.key-horse.com/linkt.html I have a td that's styled to look something like a button, and on that button is anchor text. So far, I can't make the entire "surface" of the...
5
by: Jean Pion | last post by:
Dear readers, Can anyone explain how to set column width of a table in ccs. I use the following style in an external stylesheet: table.tbl { table-layout:fixed; border-top: 5px solid #333;...
0
by: Grant | last post by:
Gday, Im using C# in a web solution. Ive placed a WebControls.Table on my webform and am building rows and cells during runtime. How do I dynamically set the column width of the table according to...
1
by: Jeronimo Bertran | last post by:
I am creating a table and inserting an iframe inside a cell for which the width depends on the screen size. The table has 7 columns and the fourth column is resized depeding on the screen...
6
by: Bill | last post by:
I am trying to figure out how to do page layouts using tables (obviously not my background). If I have, say, a 5x5 table defaulting to20px wide per cell, why can't I make the cell in, for example,...
2
by: ricky | last post by:
Hello, If anyone could help me with this I would highly appreciate it. I've tried everything and nothing works. What I am trying to do is so damn basic and it's just frustrating that it seems...
6
by: scottyman | last post by:
I can't make this script work properly. I've gone as far as I can with it and the rest is out of my ability. I can do some html editing but I'm lost in the Java world. The script at the bottom of...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.