tags:

views:

647

answers:

11

I've seen quite a few answers on this site which advocate using tables for a design because it can't be done using CSS and Divs... when in actual fact it can be done with a bit of ingenuity.

What are examples of things that genuinely can't be done?

The only one I've ever come across is vertically aligning a box within another box.

*edit: I suppose I'm mostly interested in unachievable layouts using CSS2

+1  A: 

Alternate row colors in a table without manually (or with the aid of a script) assigning alternate styles to each row.

Determine one element's position relative to another. For example you can't use CSS to determine which position one box is in a bunch of floated boxes using the same class. Would be nice to for example know if one box is the first box floated, or the second, or the last.

Handle widows. A widow is a word that dangles off the end of a paragraph, that is a single word starts the last line on a paragraph. It's a big nono on print design, but in the world of web it's hard to control.

apphacker
Can be done with CSS 3 selectors: http://www.w3.org/TR/css3-selectors/#nth-child-pseudo
Greg
Is this something that can be done automatically using only tables? Or are Javascript and by hand the only ways that this can be done?
Mike Cooper
I added some other stuff. That css3 stuff is nice. Can't wait for it to happen.
apphacker
Don't really understand what you mean by the second example, but sounds interesting if you could elaborate
wheresrhys
wheresrhys: have special styles for some floated boxes depending on where they are. This could lead to having uniform columns with floats.
apphacker
A: 

An image cannot placed in exact center of a cell with align attribute.It can be done with some brute force .

Warrior
A: 

There is absolutely nothing tables can do that CSS can't.

There seems to be a common misconception that HTML & CSS should be easy. It isn't. If you find yourself wanting to use tables then its your CSS skills that need improving not the technology (although the technology does obviously have plenty of holes that could do with improving).

roryf
Your answer is worthless without addressing the other answers which do describe counter-examples.
That answer is to be heard from someone who hasn't tried to make a complex professional design for enterprise sites. CSS just stays away.
User
@Mastermind I am a professional. I've built several large websites using entirely CSS. What an 'enterprise' site is I have no idea. Some day you will learn.
roryf
@Iraimbilanja I take your point, but a lot of the answers don't give examples that tables will solve either.
roryf
Would love to know who upvoted this and why. Pity upvote? Sorry but this answer deserves eveyr downvote it gets and then some.
cletus
Apologies if I offended anyone but I stand by the statement, I maybe just could have presented it better.
roryf
Still patently wrong.
cletus
+4  A: 

The answer to this question depends on a number of things:

  • How backwards compatible do you need to be? Including IE6 will decrease the capacity of pure CSS; and
  • How much of your site is fixed-width and/or fixed-height. There are certain things in CSS that become hard if not impossible in variable width and/or height situations.

Side-by-side content is a problem for CSS. You can use floats for this but if the sum of widths exceeds the width of the container, the tail end floats will fall down below. Tables are more capable in this regard as they will squeeze columns where possible to make things fit and cells will never be split onto new rows.

Vertical centering you mentioned. Its trivial with tables and hard or impossible (depending on compatibility and fixed or variable heights of the container and the item) in pure CSS.

You may also be referring to hover content. IE6 only supports the :hover pseudo element on anchors. Javascript is required for that browser for :hover-like behaviour.

Basically if what you need to do can be done fairly trivially with pure CSS then do it. If not, don't feel bad if you have to use tables despite all the anti-table fanatics (and they are fanatics) jumping up and down in horror.

If you want a relatively simple exmaple of this check out Can you do this HTML layout without using tables?. This is a conceptually simple layout problem that is trivial with tables and noone has yet posted a solution meeting the requirements with pure CSS.

cletus
+1 for vertical centering. so annoying!
Dead account
I would argue that it shoudl be thought of the other way around: If a relatively trivial design feature needs tables to make it work then change the design slightly. Most of your users won't even notice. But if you use tables a significant minority of users - screen reader users - will be confused.
wheresrhys
I disagree. The argument is made "tables are for content not layout". Unfortunately deficiencies in both CSS and its support in browsers don't make that quite true so favour CSS for layout but don't pull your hair out trying to avoid using a table if it all becomees too hard.
cletus
If your website wants to attract visually impaired users (roughly 9% of users) then there is definitely a case to rule out using tables for layout as it puts them off using your site. Using tables, quite appart from being unfair to VI users, could cost you money by alienating potential customers.
wheresrhys
9% of users use screenreaders? No way.
cletus
not sure to be honest. Pretty much impossible to find reliable stats on it. Just found 9% mentioned on a handful of sites.
wheresrhys
A: 

Sounds obvious but you can't change content with CSS, it can only be used for styling.

Jeremy French
It's a stylesheet. That's what HTML is for. Also you can put in content http://www.w3schools.com/Css/pr_gen_content.asp
Dead account
Technically, you can use the :after pseudoelement to insert an image or text. You are not changing the DOM tree, but it acts like you did. Please correct me if I'm wrong.
Stefano Borini
you can use content with pseudoelements to change how things look on the page, but you are changing the look, not the content.
Jeremy French
+1  A: 

Floating elements in multiple columns, where text in each cell can expand the height of the element, but the entire row below must be pushed down if this happens.

 ---   ---   --- 
|AAA| |BBB| |CCC|
 ---   ---   --- 
 ---   ---   --- 
|AAA| |BBB| |CCC|
|   | |BBB| |   |
 ---   ---   --- 
 ---   ---   ---
|AAA| |BBB| |CCC|
 ---   ---   ---
Kamiel Wanrooij
+1 About the only example here that really is something tables do that CSS doesn't. Of course, CSS3 changes that...
roryf
depending on the styling of your boxes this can be achieved using a clearing div and the faux columns technique... I think
wheresrhys
yes, but not any amount of columns or styles, like tables can do easily.
Kamiel Wanrooij
This can be done with CSS2's display:table and friends. Oh, you're using IE6 or IE7? Now you have two problems ;)
insin
+2  A: 

"... when in actual fact it can be done with a bit of ingenuity."

How about 'avoiding the need for ingenuity' as a thing that's hard to do in CSS.

;)

izb
I don't believe in upvoting things for being funny, but if there was a "made me chuckle" button I'd click it
wheresrhys
I think it's a perfectly valid point. Although I'm not a website developer, even trivial things need a lot of thought and experimentation with css. Tables tend to be a lot more forgiving.
Jim T
+2  A: 

tables should be used for tabular data! We should always try to use the correct HTML for the given content in which to markup. So not just div's (span, ul, li, dl, strong, em ... etc) This ensures that the content is not just looking right but is right (for SEO and accesibile reasons)

By not using tables it allows us to transform the content from one look and feel to the next without having to change the HTML, see Zen Garden

For now though with current browsers CSS table like layouts can be done but are tricky. there are techniques to get round many of the issues, weather they are done though global wrappers with background images, or positioning fixes... where both articles also refer to using Javascript to progressively enhance a page to get those additional classes you may require.

or of course you could use some XSL as a middle ware to help do formating if processing from a CMS.

nickmorss
Yes, but tables are harder to get looking right, and at the end of the day, that is the decisive factor in HTML.
CurtainDog
ZenGarden is ultimately primitive. Any more or less complex design will require reshuffling of all of your divs and consequently of the style sheet.
User
nickmorss
+3  A: 
  • Vertical alignment of blocks or text.

  • Having elastic containers that stretch to the width of their content.

  • Having several "rows" with the same structure where "cells" are synchronized in width throughout all rows.

  • Having several "columns" synchronize their height (up to the length of the longest text block).

These are quite basic designer needs that appear in even basic design concepts.

Cells/columns issues can possibly be solved with CSS if you take IE8 into account, but it will be many years until its wide spread (even IE7 in 2-3 years hasn't reached the desired market share).

As for "ingenuity", it is not that good thing in software development. Tricks that your colleagues and you yourself after a couple of months will not be able to understand usually build up that code base that everyone either is scared to touch or determined to refactor/rewrite completely.

Remember the KISS principle. The simpliest way you do this, the more reliably it will work.

User
Elastic containers can sort of be achieved by floating them and specifying width:auto, though if the content is text it won't wrap the text until the box is at its max width, so having elastic containers next to each other so that in total hey fill the width isn't possible
wheresrhys
Your third and fourth examples I think are possible, but only by adding extra divs and using the faux columns techniqe.The rows issue is a lot trickier than a table, but columns is not too bad
wheresrhys
Also, I agree with the ingenuity point and it's true that a) CSS2, particularly with cross-browser issues, requires far too much. b) there seems to be far less of a tradition of commenting CSS than other code files
wheresrhys
A: 

Rory, I think you're absolutely right. Vertical alignment can be done with line-height, and creating lay-outs in CSS really isn't that hard. In fact, it's far more flexible when using absolute/relative positioning and floats.

People still using tables for design should really brush up with the current standards.

Going on topic, with CSS3 coming up it's hard to think of stuff CSS can't do. Image manipulation, content manipulation, advanced selectors, it's all going to be possible. But if I had to name one thing, it's that with CSS you can't (and won't) be able to rotate elements.

SolidSmile
vertical alignment for blocks can't be done with line-height - believe me I've tried, and if you look through various other questions on stack overflow there's lots of other people who have tried and failed.CSS3 will be damn cool when it's widely supported!
wheresrhys
A: 

I was unable to use a transparency to create a variable-height text area across all pages. I believe it's impossible. I ultimately just wrote a quick javascript function to reset the height after the page load, to get the layout to work. See http://peterchristopher.com to see what I mean by transparency for the text area.