I've a database driven site, i want so creat nice borders around a big table.
I need cellspacing but can't put any class code to that part of the site.
I only have the table, tr and td tags to work with.
Unfortunately, not all browsers respond reliably, so you still ultimately need to include the table attributes. Anyone want to guess which modern browser still doesn't support border-spacing? :)
Netscape 4 can't handle this code, so you'd need to use the correct css @import rule to deliver unstyled content to non CSS supporting browsers.
border-collapse:collapse; is equal to cellspacing="0".
the cell padding creates the separation you need, the border would if required be the cell separator, if you don't want it there just delete it, and the table border adds a border only around the table, not like in <table border=2> where that adds borders around each cell.
You can add other things like text-align:left, center or right, but it will apply to all td in the table of course.
Once you use CSS most of the default table stylings are eliminated and you have to explicitly state all of them, different browsers will forget different ones.
While it's true that you can't create positive cellspacing with css, you can create something that would work fine:
I guess that depends on your definition of works fine, Lizardz. If the goal is simply borders "around" a table, then yes, your solution will work, though it will also likely require unnecessary table nesting (better to put a DIV around the table and manipulate the borders and padding of that).
However, correct implementation of cellspacing should do more than affect the outside borders of the table. Here's a quick snippet of a form being designed for a current project. Look at it in IE and then in any other modern browser and the cellspacing, as set in the style sheet, should be very evident. To achieve what you see in Firefox or Opera using your method would require a LOT of nested tables and a huge increase in code. Even filling each padded TD with a DIV, which I think is a better way to get the same look, would greatly increase code size.
My solution is to set the cellspacing attribute of the TABLE tag, after which the table looks the same in all modern browsers. Were that not possible, I suspect I would choose to simply ignore IE's deficiencies on this since it's clearly just an ascetic issue and doesn't impact functionality. I honestly can't imagine a situation where I would willingly double or triple the size of the code for something like this, though.
Oh, I think you misunderstand what I'm saying. First of all, I don't use or develop techniques that don't work reasonably well on most modern browsers. I go by market share, so I support in CSS what I expect to see on the site, which will be this:
IE 6
IE 5.x
Mozilla/Firefox
Safari
IE 4x [if required]
then if I'm feeling nice:
Konqueror
and then if I'm feeling really nice:
Opera.
That's commercially, on my own stuff I do what I feel like, but even there it all works pretty much the way I want, on all browsers, except the ones I deliberately stopped supporting [I used to make full css sites that worked in netscape 4!!].
I am not a fan of techniques that are technically interesting but only supported by around 10% of site browsers. That's the a list apart school of CSS that is.
So I don't use methods that don't work in IE, although I use proprietary Mozilla methods which other browsers just ignore. Sometimes I'll use the IE conditionals for some fine tuning.
I'm not at all clear where you got the idea that I'm suggesting nesting tables. The guy asked about a specific issue, which is having no control over the output tags, table/tr/td. Obviously you can't nest tables, divs, or anything else in that situation. You can only apply styles to the table and td tags. With that limitation, the person asked what could be done re cellspacing. Since nothing can be done re cellspacing in that exact circumstance, you have to make the best of it, and create the closest result aesthetically that those restrictions allow. Which would be css controlled cellpadding, css controlled table borders, and if desired, css controlled td borders, which incidentally can be made to look like cell spacing by simply making them lighter color than the td background.
How you read this to be suggesting nesting tables and divs is beyond me.
If this is still not clear, let me know and I'll try to clarify it some more.
Since nothing can be done re cellspacing in that exact circumstance, you have to make the best of it ...
We're saying the same thing.
The only difference being I don't think your proposed solution qualifies as "something that would work fine," but more like something that is "making the best of it." It cannot (without nesting tables or DIVs) simulate the effect I demonstrated, or even come very close, but remains a poor compromise. Without controlling the table attributes, cellspacing is going to remain elusive in IE, with no easy fixes.
Yes, if you really need that specific affect of cell spacing, but I have to admit I don't like or use that ever, all that'e required is some way to separate the cells, borders are fine for that, like on this forum page. To me cell spacing has a very dated look to it, I don't use it anymore.
I'm still not clear why using simple borders isn't something that 'would work fine'. It does work fine, it separates the data cells clearly, it's easy to implement, and it works fine.
Re IE lack of support, IE 6 now has the dubious honor of being this browser generation's Netscape 4x browser, the browser with too much market share to ignore, but that still holds back all real development and advance do to its poor support of advanced CSS.
Sadly IE 6 is going to be with us as long or longer than Netscape 4 was. I only stopped supporting netscape 4 last year. So I focus on techniques that work cross browser and just ignore the slick but useless css stuff that won't run on IE, unless it not running presents only a cosmetic absence.
You are not permitted to post messages in this forum or topic, because of one or more of the following reasons:
You have not yet logged in, or registered properly as a member
You are a member, but no longer have posting rights.
This is a private forum, for which you do not have permissions.
If you are a recent member, it's possible that you simply have not yet confirmed your account. Please
check your email for a message entitled 'JimWorld Forums: Confirm Your Account' and follow the instructions
contained within.
If you are still experiencing problem, please read the
Login Assistance
Article for some advice on what may be causing your login not to work properly.