473,378 Members | 1,498 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,378 software developers and data experts.

How to get width I set tables and TD's etc. to be the size I set them?

Hi All,

I really need some help with tables, each time I do a site I find myself wasting hours and hours on end, and this time is no different. I am into hour 10 trying to get this to work.

I just want the widths I set in my table and TD's etc. to be the size I set them. My table is 850px wide, with 12 TD's or TH's being various sizes from 40px to 150px. This also has to take into account the 1px borders and possibly the padding, but that one confuses me.

If someone can show me a way to do this successfully that would be great as I am just having no luck.

I should mention too that I do not want the TD's shrinking or expanding based on content. I want them to stay the size that is laid out for them. If it needs to wrap to the next line, I can live with that.

I have posted my code and CSS below, but I would prefer fresh input of how to do this, not a mickey mouse fix of what I have done that doesn't work, as I am sure it is right out to lunch after all the changes I have done.

Thanks for the help

Table Code

Expand|Select|Wrap|Line Numbers
  1.  
  2.         echo "
  3.         <table class='home' width: 850px' cellspacing='0'>
  4.         <tr align='top'>
  5.         <th>Invoice</th>
  6.         <th>PO</th>
  7.         <th align='center' >Date</th>
  8.         <th align='center'>Pending</th>
  9.         <th align='center'>Completed</th>
  10.         <th>Name</b></th>
  11.         <th>Address</b></th>
  12.         <th align='center'>Status</th>
  13.         <th align='center'>Tech</th>
  14.         <th align='center'>Edit</th>
  15.         <th align='center'>View</th>
  16.         <th align='center'>Print</th>
  17.         </tr>
  18.         <tr style='border-left: solid 1px #FFFFFF; border-right: solid 1px #FFFFFF'><td colspan='12'></td></tr>";
  19.  
  20.         while($r=$db->fetch_row($q)) {
  21.  
  22.             if ($alternate == "1") {
  23.                 $color = "#ffffff";
  24.                 $alternate = "2";
  25.                 }
  26.                 else {
  27.                 $color = "#c0c0c0";
  28.                 $alternate = "1";
  29.             }    
  30.  
  31.             $rn = explode("-", $r['record_number']);
  32.  
  33.             echo "<tr valign='top' style='background-color: {$color}'> 
  34.                   <td><div style='width: 40px'>{$rn[1]}</div></td>
  35.                   <td><div style='width: 60px'>{$r['po']}</div></td>
  36.                   <td><div style='width: 68px'>{$r['dr']}</div></td>
  37.                   <td><div style='width: 68px'>{$r['ds']}</div></td>
  38.                   <td><div style='width: 68px'>{$r['dc']}</div></td>
  39.                   <td><div style='width: 86px'>{$r['firstname']} {$r['lastname']}</div></td>
  40.                   <td><div style='width: 150px'>{$r['st_number']} {$r['address']}, {$r['city']}</div></td>
  41.                   <td><div style='width: 68px' align='center'>{$r['statuscode']}</div></td>
  42.                   <td><div style='width: 30px' align='center'>{$r['tech']}</div></td>
  43.                   <td><div style='width: 30px' align='center' class='link'>Edit</div></td>
  44.                   <td><div style='width: 30px' align='center' class='link'>View</div></td>";
  45.                   ?> 
  46.                   <td><div style='width: 30px' align='center'>
  47.                   <a class='link' href="javascript: void(0)" 
  48.                   onclick="window.open('print-pdf.php?inv=<? echo $r['record_number']; ?>', 
  49.                   'print', 
  50.                   'toolbar=no,location=no,directories=no,status=no,menubar=yes,scrollbars=yes,copyhistory=yes,resizable=yes');
  51.                   return false;">Print</a>
  52.                   </div></td>
  53.                   <?
  54.                   echo "                  
  55.                   </td>                  
  56.                   </tr>";
  57.         }
  58.  
  59.         echo "</table>";    
CSS Code

Expand|Select|Wrap|Line Numbers
  1.  
  2. table.home {
  3.     font-size: 7pt;
  4.     color: #000000; 
  5.     border-width: 1px 1px 1px 1px;
  6.     border-spacing: 1px;
  7.     border-style: solid solid solid solid;
  8.     border-color: gray gray gray gray;
  9.     border-collapse: collapse;
  10.     background-color: white;
  11. }
  12. table.home th {
  13.     color: #000000; 
  14.     font-size: 7pt;
  15.     font-weight: 700;
  16.     background-color: #e5e5e5; 
  17.     height: 20px;
  18.     white-space:nowrap;
  19.     border-width: 1px 1px 1px 1px;
  20.     padding: 2px 2px 2px 2px;
  21.     border-style: inset inset inset inset;
  22.     border-color: gray gray gray gray;
  23.     -moz-border-radius: 0px 0px 0px 0px;
  24. }
  25. table.home td {
  26.     text-align: left;
  27.     vertical-align: middle;
  28.     color: #000000; 
  29.     font-size: 7pt;
  30.     font-weight: 400;
  31.     height: 20px;
  32.     border-width: 1px 1px 1px 1px;
  33.     padding: 2px 2px 2px 2px;
  34.     border-style: inset inset inset inset;
  35.     border-color: gray gray gray gray;
  36.     -moz-border-radius: 0px 0px 0px 0px;
  37. }
  38.  
  39.  
Feb 6 '11 #1
21 3192
Anyone? This is quite time sensitive and any help is appreciated.
Feb 7 '11 #2
Dormilich
8,658 Expert Mod 8TB
not sure how far the browser support is, but you should look into the <col> & <colgroup> elements.
Feb 7 '11 #3
At first glance: the width should be on the <td> and not on the div.

Its easier for us to debug if we can see the code in action. Is there a online example?
Feb 7 '11 #4
JKing
1,206 Expert 1GB
You haven't properly declared a width for your table.

Expand|Select|Wrap|Line Numbers
  1.  <table class='home' width: 850px' cellspacing='0'>
  2.  
Should be one of the following:
Expand|Select|Wrap|Line Numbers
  1. <table class='home' width='850' cellspacing='0' cellpadding='0'>
  2.  
  3. OR
  4.  
  5. <table class='home' style='width:850px;' cellspacing='0' cellpadding='0'>
  6.  
Feb 7 '11 #5
This is why I hate posting code. Typo. Of course the real code is correct.
Feb 8 '11 #6
Tried that, and this is why I put it on the DIV. I have probably tried 3 dozen ways to do this, none of them the way I want it. I am thinking now that this is just not possible with the way tables and CSS currently work.
Feb 8 '11 #7
I have never used these in a table and not sure what they do or how they would help in this circumstance, but I will have a quick look and see if they might add anything.
Feb 8 '11 #8
Thanks for all the replies, but I am still where I was. As I mentioned, I don't think this can work, and since I have yet to get a definative answer on any group, it certainly looks more and more this way. I hope someone comes up with a better tables one day, but probably not in my life time.
Feb 8 '11 #9
Again, a online example? Im not using PHP anymore so I dont have a test environment. But if you have a online example there will be no typo's right? and we see the true code in work.
Feb 8 '11 #10
JKing
1,206 Expert 1GB
You typed both of those code blocks out? Why wouldn't you just copy and paste the code?

This also has to take into account the 1px borders and possibly the padding, but that one confuses me.
Take a look at the box model

If you add up all the widths you have declared you will get 728px. Factor in a 1px border for each element with border collapse on for another 13px. The padding of 2px on each side of the element for another 48px. Add them up 728 + 13 + 48 = 789px.

There is an extra 61px the browser is deciding what to do with.
Feb 8 '11 #11
As long as I have posted to groups, I am at a loss to understand why examples are such a big thing, if you know and understand tables, then you should know of what I am up against. What I am asking is not so much a problem with my code, but a bad design in tables and how to work wih it. In any event, all my coding is done on a private home server.
Feb 9 '11 #12
In a nutshell this is what i want. An 850px table with 12 TD's of various sizes. The sizes need to be static. Wrap if to long but stay the same size if content is shorter or non existent. Look at an excel spread sheet. This can do what I want, how can I get the same effect in tables. Forget any code I have posted as it isn't right anyway. How would you do it if you were creating the same table structure.

Tanks again for all the posts.
Feb 9 '11 #13
JKing
1,206 Expert 1GB
There is nothing wrong with the design of tables in html.

Here is an example.
Expand|Select|Wrap|Line Numbers
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
  2. <html xmlns="http://www.w3.org/1999/xhtml">
  3. <head>
  4. <style type="text/css">
  5.     table {border-collapse:collapse;table-layout:fixed;border:1px solid black;width:850px;}
  6.     td {overflow:hidden;border:1px solid black;}
  7. </style>
  8. </head>
  9. <body>
  10. <table cellspacing="0" cellpadding="0">
  11. <tr>
  12.     <td width="80">Cell 1</td>
  13.     <td width="50">Cell 2</td>
  14.     <td width="50">Cell 3</td>
  15.     <td width="50">Cell 4</td>
  16.     <td width="50">Cell 5</td>
  17.     <td width="70">Cell 6</td>
  18.     <td width="80">Cell 7</td>
  19.     <td width="70">Cell 8</td>
  20.     <td width="150">Cell 9</td>
  21.     <td width="100">Cell 10</td>
  22.     <td width="40">Cell 11 tooooooooooooooooooooooooooo lonnnnggggggggggggggggggggggggggggggg</td>
  23.     <td width="60">Cell 12</td>
  24. </tr>
  25. </table>
  26. </body>
  27. </html>
  28.  
Since you are pulling from a database, I would do a check to see if the content is non existent and insert a non-breaking space if it is indeed non existent.
Feb 9 '11 #14
"There is nothing wrong with the design of tables in html."

I would and will debate this until the end of time. They are a terrible design for todays uses and even in the past were not much better.

However, a debate for another time.

In regards to you post, this, and many variations of this, is what I have been doing and does not work for what I need, and why I make my comment above.

If data is to wide or not wide enough tables screw-up.

So the question again, when I have a table that is 100px wide and 5 TD's that are 10 40 25 15 10 wide for each one. How do I get them to stay that way regardless of what is in them. It will only ever be text, so wrapping is not an issue if to long. But what about other cells.

Unfortunately I can not show an example, but I am 99% there, but the size of the TD still fluxuate.

Thanks again.
Feb 13 '11 #15
Dormilich
8,658 Expert Mod 8TB
maybe the overflow property is of help …
Feb 14 '11 #16
JKing
1,206 Expert 1GB
Did you even try the example I provided?
Did you notice the CSS?
Particularly the table-layout:fixed;?
Did you look at Cell 11?

I gave you everything you needed to satisfy your requirements. I even tested the example in the following browsers: IE6, IE7, IE8, Firefox and Chrome.

Again there is nothing wrong with tables.
It is not debatable. Millions of sites use tables without an issue.
Feb 14 '11 #17
People still use tables!?
Feb 20 '11 #18
JKing
1,206 Expert 1GB
For tabular data, yes.
Feb 20 '11 #19
Why the surprise NetDynamic. I'd be surprise if people would not use it. Many websites needs to show data in tabular form.
Feb 20 '11 #20
I'm just playing although for layout I avoid them like the plague
Feb 20 '11 #21
Ofcourse you should avoid it for layout purpose because it was not designed for that. Its true purpose is displaying data like a excel sheet(colums, rows, cells etc).
Feb 20 '11 #22

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

Similar topics

5
by: Andrew | last post by:
Could someone please tell me why this simple table test is completely mangled by Netscape? HTML: <TABLE WIDTH="90%" ALIGN="center" BORDER="0" CELLPADDING="0" CELLSPACING="1" BGCOLOR="Black">...
3
by: William Gill | last post by:
I can't help but think I'm re-inventing the wheel if I have to code my own interface! Isn't there some script, php code, or something (modifiable / customizable) available that lets me select...
2
by: John Milton | last post by:
Hi all I have a table with data in it, adn the tds inside the table get their width automatic... but, i have above this table another table, and i want the tds inside this table to be the...
1
by: Eshrath Ali Khan | last post by:
Hi, I have a requirement where I am creating table object with different ids using XSL by taking an XML as input. The no of objects (tables) is not fixed. I want to write a javascript to invoke...
11
by: SarahMarsden | last post by:
I'm new to Dreamweaver (using MX 2004). I have a 2 row 3 column table. I have set each column to 200 pixels. The second row I have merged into one cell. When I enter text (or anything else) into...
0
by: DemonJames | last post by:
I have a template that I created in word, that I want to read data into, temporarily store it, go to the next set of records, and then read data into the template again, repeating the process until...
7
by: Ladysniper | last post by:
DESPERATE doesn't begin to describe it. Can someone PLEASE tell me what is WRONG with this code? Now..a bit of background. It is a search results page for http://www.azsoma.info/directory.htm....
1
by: pemigh | last post by:
I'm almost done with an application, and trying to lock it down tightly. But I still want users to be able to point to a new location for the data file. The code below fires off to detect and...
2
by: TonyV | last post by:
Okay, this is driving me nuts, and while I'm still researching, I'm hoping someone here can help. I'm trying to create a simple page with a navigation menu on the left side of the main content...
15
by: Peter | last post by:
I have the following web page and I am trying to have the Field lables NOT to wrap. It looks fine in a designer but when I run the program in a browser the lables that have a space wrap. How do I...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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
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: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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...

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.