| | |
Making a table column auto-resize
Please support our HTML and CSS advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
![]() |
•
•
Join Date: Nov 2004
Posts: 4
Reputation:
Solved Threads: 0
I'm working on a website for my friend and we're having some problems. We have set up a table to handle the main page, which has within the table a shoutbox, news posts, and links. The news bits within the table are (obviously) longer in terms of space used up than the other bits on the table. So what I did was use the rowspan argument to increase the amount of space that the news feed takes up, but that really isn't enough room, since when we add more news we'll run low on room. Now I would assume that the table would auto-resize to accomidate the length of the news feed, and it does. The problem is that it seems to auto-resize the shoutbox and the first box on the links list as well. Also annoying is the fact that the news is centered both horizontally and vertically, and I would like to center it horizontally only. Both of these are interconnected, because before I resized the news stuff everything worked perfectly, but after I did the problems began coming up. What can I do?
Personally I use css not tables for layout, but similar principles apply.
Because you can't say how big a persons screen will be, there is no one no. of pixels that can be defined as the screen width. Hence if you set the width of the side columns in pixels you can allow the center column to expand without altering the width of the others.
Does that help you at all? if not then you might want to show us the page you're working on - upload or zip.
Because you can't say how big a persons screen will be, there is no one no. of pixels that can be defined as the screen width. Hence if you set the width of the side columns in pixels you can allow the center column to expand without altering the width of the others.
Does that help you at all? if not then you might want to show us the page you're working on - upload or zip.
•
•
Join Date: Aug 2008
Posts: 16
Reputation:
Solved Threads: 1
maybe you can try this one. hope it helps
add to your HTML command:
Javascript:
-- uos...wrong thread...sorry
add to your HTML command:
HTML and CSS Syntax (Toggle Plain Text)
<script type="text/javascript" language="javascript1.2">installTable(tableID);</script>
Javascript:
javascript Syntax (Toggle Plain Text)
var markerHTML = "<>"; var minWidth = 100; var dragingColumn = null; var startingX = 0; var currentX = 0; function getNewWidth () { var newWidth = minWidth; if (dragingColumn != null) { newWidth = parseInt (dragingColumn.parentNode.style.width); if (isNaN (newWidth)) { newWidth = 0; } newWidth += currentX - startingX; if (newWidth < minWidth) { newWidth = minWidth; } } return newWidth; } function columnMouseDown (event) { if (!event) { event = window.event; } if (dragingColumn != null) { ColumnGrabberMouseUp (); } startingX = event.clientX; currentX = startingX; dragingColumn = this; return true; } function columnMouseUp () { if (dragingColumn != null) { dragingColumn.parentNode.style.width = getNewWidth (); dragingColumn = null; } return true; } function columnMouseMove (event) { if (!event) { event = window.event; } if (dragingColumn != null) { currentX = event.clientX; dragingColumn.parentNode.style.width = getNewWidth (); startingX = event.clientX; currentX = startingX; } return true; } function installTable (tableId) { var table = document.getElementById (tableId); // Test if there is such element in the document if (table != null) { // Test is this element a table if (table.nodeName.toUpperCase () == "TABLE") { document.body.onmouseup = columnMouseUp; document.body.onmousemove = columnMouseMove; for (i = 0; i < table.childNodes.length; i++) { var tableHead = table.childNodes[i]; // Look for the header // Tables without header will not be handled. if (tableHead.nodeName.toUpperCase () == "THEAD") { // Go through THEAD nodes and set resize markers // IE in THEAD contains TR element which contains TH elements // Mozilla in THEAD contains TH elements for (j = 0; j < tableHead.childNodes.length; j++) { var tableHeadNode = tableHead.childNodes[j]; // Handles IE style THEAD with TR if (tableHeadNode.nodeName.toUpperCase () == "TR") { for (k = 0; k < tableHeadNode.childNodes.length; k++) { var column = tableHeadNode.childNodes[k]; var marker = document.createElement ("span"); marker.innerHTML = markerHTML; marker.style.cursor = "move"; marker.onmousedown = columnMouseDown; column.appendChild (marker); if (column.offsetWidth < minWidth) { column.style.width = minWidth; } else { column.style.width = column.offsetWidth; } } } // Handles Mozilla style THEAD else if (tableHeadNode.nodeName.toUpperCase () == "TH") { var column = tableHeadNode; var marker = document.createElement ("span"); marker.innerHTML = markerHTML; marker.style.cursor = "move"; marker.onmousedown = columnMouseDown; column.appendChild (marker); if (column.offsetWidth < minWidth) { column.style.width = minWidth; } else { column.style.width = column.offsetWidth; } } } table.style.tableLayout = "fixed"; // Once we have found THEAD element and updated it // there is no need to go through rest of the table i = table.childNodes.length; } } } } }
-- uos...wrong thread...sorry
Last edited by vee_liang; Dec 11th, 2008 at 4:53 am.
Vee Liang
To be right, first you have to know what wrong is.
To be right, first you have to know what wrong is.
•
•
•
•
I'm working on a website for my friend and we're having some problems. We have set up a table to handle the main page, which has within the table a shoutbox, news posts, and links. The news bits within the table are (obviously) longer in terms of space used up than the other bits on the table. So what I did was use the rowspan argument to increase the amount of space that the news feed takes up, but that really isn't enough room, since when we add more news we'll run low on room. Now I would assume that the table would auto-resize to accomidate the length of the news feed, and it does. The problem is that it seems to auto-resize the shoutbox and the first box on the links list as well. Also annoying is the fact that the news is centered both horizontally and vertically, and I would like to center it horizontally only. Both of these are interconnected, because before I resized the news stuff everything worked perfectly, but after I did the problems began coming up. What can I do?
vertical-align: top; style. This moves all of the text in each cell to the top.I always include that style with a table, because IE and FF do different things by default.When you use rowspan or colspan, how the rows and columns are divided without any styles controlling them depends on the relative sizes of the contents. So if you have a rowspan of 2 in the second column, content in the top cells of columns 1 and 3, but nothing in the second rows of columns 1 and 3, the top cells in those columns will be taller.
Don't use pixels to define sizes. This locks you in to one screen resolution. Use points or percent instead.
Last edited by MidiMagic; Dec 15th, 2008 at 2:11 am.
Daylight-saving time uses more gasoline
![]() |
Similar Threads
- Frame auto resize (HTML and CSS)
- Width Auto Resize to fit Screen (HTML and CSS)
- Table/Column Layout for multiple pricing (MySQL)
- auto resize only 1 column in jtable (Java)
- Making a table, help please (Java)
Other Threads in the HTML and CSS Forum
- Previous Thread: Prevent browser from saving form value(s)
- Next Thread: Class.something vs .class
| Thread Tools | Search this Thread |
Tag cloud for HTML and CSS
2002 appointments asp background backgroundcolor beta browser bug calendar cart cgi code codeinjection corporateidentity create css deleted design development displayimageinsteadofflash dreamweaver drupal emailmarketing epilepsy explorer firefox flash font fonts form format frontpage google griefers hackers hitcounter hover html ide ie7 ie8 iframe image images internet internetexplorer intranet iphone javascript jpeg layout macbook maps marketshare microsoft missing mozilla multimedia navigationbars news offshoreoutsourcingcompany opacity opera optimization perl pnginie6 positioning problem scroll seo shopping studio swf swf. templates textcolor theme timecolor titletags url urlseparatedwords visual visualization web webdevelopment webform website windows7 wordpress xml xsl






