/    Sign up×
Community /Pin to ProfileBookmark

Set a table columns width

Hi,

I tried to do it by adjusting the [I]<td>[/I] width:

[CODE]<!DOCTYPE HTML PUBLIC “-//W3C//DTD HTML 4.01 Transitional//EN” “http://www.w3.org/TR/html4/loose.dtd”>
<html>
<head>
<title>Sample Page</title>
<style type=”text/css”>
div {width:100%; overflow:auto;}
table, td {border:1px solid #000;}
td {width:1000px;}
</style>
</head>
<body>
<div>
<table>
<tr>
<td>First cell</td>
<td>Second cell</td>
<td>Third cell</td>
</tr>
<tr>
<td>Forth cell</td>
<td>Fifth cell</td>
<td>Sixth cell</td>
</tr>
</table>
</div>
</body>
</html>[/CODE]

But it didn’t work.

Many thanks for any help!
Mike

to post a comment
CSS

1 Comments(s)

Copy linkTweet thisAlerts:
@cootheadMar 09.2012 — Hi there Rain Lover,

if you check the table [i]offsetWidth[/i] with javascript, you will see that it has a width of 3022px.

Setting the div container width to 100&#37; is pointless as that is it's default width.

It must be set to the table width.
[color=navy]&lt;!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd"&gt;
&lt;html&gt;
&lt;head&gt;
&lt;title&gt;Sample Page&lt;/title&gt;
&lt;style type="text/css"&gt;[color=red]
div {width:3022px;}[/color]
table, td {border:1px solid #000;}
td {width:1000px;}
&lt;/style&gt;
&lt;script type="text/javascript"&gt;


function init(){
alert('overall table width='
+document.getElementsByTagName('table')[0].offsetWidth+'px');
}
window.addEventListener?
window.addEventListener('load',init,false):
window.attachEvent('onload',init);
&lt;/script&gt;

&lt;/head&gt;
&lt;body&gt;
&lt;div&gt;
&lt;table&gt;
&lt;tr&gt;
&lt;td&gt;First cell&lt;/td&gt;
&lt;td&gt;Second cell&lt;/td&gt;
&lt;td&gt;Third cell&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Forth cell&lt;/td&gt;
&lt;td&gt;Fifth cell&lt;/td&gt;
&lt;td&gt;Sixth cell&lt;/td&gt;
&lt;/tr&gt;
&lt;/table&gt;
&lt;/div&gt;
&lt;/body&gt;
&lt;/html&gt;
[/color]

[i]coothead[/i]
×

Success!

Help @Rain_Lover spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.17,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...