Tutorial :What can't be done using CSS



Question:

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


Solution:1

  • 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.


Solution:2

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.


Solution:3

"... 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.

;)


Solution:4

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.


Solution:5

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.


Solution:6

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|   ---   ---   ---  


Solution:7

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


Solution:8

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


Solution:9

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.


Solution:10

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.


Solution:11

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).


Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Previous
Next Post »