Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Mixing % and pixels in table elements

Status
Not open for further replies.

starway

Programmer
Jan 15, 2002
1,010
UA
It was a recent discussion in this forum about whether it's good or bad to mix percentage and pixel values in table elements dimentions. I was rather surprised by posts about it, and think that I should clarify the case.

I state that it's not bad at all.
It is widely spread technique that can be useful for different tasks. For example, if you want to create a feel that the page layout covers entire window, while it actually consists of some fixed-width colomns with content and additional colomn with 100% width with some background.
----------------------
| 200px | 100% |
----------------------
This is just one example, but not the only one existing.

There are no any browser compatibility problems here. It never cause any problems in IE, Opera, old Netscape 4.x or new Mozilla. I personally used this method for years.

Of course - I tell this again - this should be done correctly. Use your knowledge and common sence. As you always should do.

As a proof of my words, here's an example: (don't go to the home page - they have some huge image there)
I usually never point to "live" projects I was involved in. This is an exception to the rule, because it illustrates the case and I think it can be helpful for you.

(Please note that the project was lauched about a year ago and I'm no longer involved in it. All the bugs you may found in page display in Mozilla or some weird formatting code, including huge ugly Dreamweaver preloader script - all this was done by those who support the project now.)

I don't say that what I show there is the only right way. It's just one of the possible implementations of this technique.
All I want to say is this: there are no methods defined as "good" or "bad" absolutely. Each method (if used properly) that helps you to achieve the goal is good - if it doesn't break the accepted rules, of course.

The method of using % and pixels in the same table does not break any HTML rule. Every professional will laugh in your face if you tell this. Don't think that it's not a valid way just because you never thought about it or didn't try to understand it.

Hope this is helpful.
Good luck to you.
 
starway I agree with you here. I think mixing both is not a bad idea per say but like frames and JavaScript you always have to consider certain things. The example you give is a good use of HTML in my opinion. Gary Haran
 
I, too, agree with starway & xutopia.

Percentages for table widths are the only way to assure that your pages will fit the users screen completely without having to write code to detect screen resolution.

As noted however, you have to put a lot of thought into what you're doing before mixing width parameters. An example of what can happen:

<table width=&quot;100%&quot; border=&quot;1&quot; bgcolor=&quot;green&quot;>
<tr><td><img src=&quot;images/someimg.gif&quot; width=&quot;760&quot; height=&quot;100&quot; border=&quot;0&quot;></td></tr>
</table>

Most will see that the table will fill the screen width completely as will the image - at 800x600 resolution. But at 1024x768 resolution, the image in the first cell will be left oriented and have a huge green space to the right!

Likewise, if we used a fixed width for the table:

<table width=&quot;760&quot; border=&quot;1&quot; bgcolor=&quot;green&quot;>
<tr><td><img src=&quot;images/someimg.gif&quot; width=&quot;760&quot; height=&quot;100&quot; border=&quot;0&quot;></td></tr>
</table>

Again, the table fills the screen width at 800x600 but leaves a large white area (or whatever the <body> background color may be) to the right of the table at 1024x768.

One last comment and I'll go away... like many of you, I've been programming of years. Starway put it nicely &quot;Don't think that it's not a valid way just because you never thought about it or didn't try to understand it.&quot; No truer words were ever spoken about computer programming. With little exception, there is no one correct way to write a script or program (I don't care what Bill Gates says!). I tell my students that if you ask 50 programmers to write a program to solve a problem, you'll get 50 different programs all reaching the same solution. There's always a better way...
 
One thing. If its against W3C compliancy, then its one thing you should not get comfortable in using.
 
It's the first time I hear about this.
Can you point me WizyWyg to any W3C document specifying this?
(Side comment: even if it's true, this is not a reason for not usign it)
 
If it is true then it is absolutely a reason not to use it. Standards are there for a reason.

But no need to jump the gun until a link is posted where this is stated by the w3c. -- cut here --
 
hey guys! :)

Just to clear something out. The w3c states that you can use any means of measuring in each item you have on your page. To me that clears something out. The w3c does not force anyone to use only percentage or only fixed width.

You can use any mix you want.

My favorite is em! :)

On another note :


How you can make tables without tables anymore! :) speeds up rendering and is cleaner code as well! :)

Gary Haran
 
W3C is not a governing agency but rather a standards agency. I don't think that any one browser does everything put forth by W3C and we all know that no two browsers render pages the exact same way even when using the same tags!

If all browsers did what W3C prescribed than there would be little point in having more than one browser. Just as there are about a hundred flavors of Linux that all follow a &quot;standard&quot;, there's nothing stopping any of them from improving or adding to the functionality of their products. So too, with browsers and W3C. There's always a better way...
 
&quot;If all browsers did what W3C prescribed than there would be little point in having more than one browser. Just as there are about a hundred flavors of Linux that all follow a &quot;standard&quot;, there's nothing stopping any of them from improving or adding to the functionality of their products. So too, with browsers and W3C. &quot;



I disagree with this. All browsers ever made can be compliant to W3C standards, but we dont want to be stuck with the same old browsers on every computer. For one, linux users dont use IE , and prefer Konqueror. I use them all. FreeBsd users dont have Netscape available to them....

etc
 
I think tviman's comment about having only one browser relates to testing. I remember way back when I had 7 different browsers to do testing with. Now I have only two! :) Mozilla and IE! :) Gary Haran
 
&quot;I think tviman's comment about having only one browser relates to testing. I remember way back when I had 7 different browsers to do testing with. Now I have only two! :) Mozilla and IE! :)&quot;


Hm...I test on at least 5 different browsers and for my
WAP/WML site, on 4 different phones....If you want compliancy, I have major gripe about mobile phone manufacturers and their &quot;non-standard&quot; freaking phone displays.
 
yeah WAP is a totally different story. Aren't there emulators for the major brands so you can test directly on your computer? Gary Haran
 
xutopia, yes there are, but not all brands and models are included. Nokia has their own, Siemens has their own, Motorola has their own, and Sprint has nothing (considering with their new PCVision phones, they'd actually make something). The Samsung phones are the worst to try and make content for.
 
xutopia ,

developing for our company to provide downloadable games for Sprint PCS Vision customers. Still in the &quot;what the heck is WAP/WML&quot; stage. Just crashed course on programming WML and WMLScript. Samsung still sucks.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top