Seven things still missing from CSS

Seven things still missing from CSS

CSS has come a long way but it's not perfect (yet). Molly Holzschlag, passionate standardista and open web evangelist, quizzed her peers to find out what they see as the most frustrating aspects of CSS

The first passionate cry for CSS hearkens back to 1994. That’s the same year the W3C formed, which is almost two decades ago! How on earth did a technology we’ve come to rely on as one does family; love to the point of tears; extend to the point of breaking; end up hating and ultimately waging full-out web war for missing critical pieces along the way?

In order to uncover what mischief these flaws in CSS have caused, I went on a mission that revealed what many working web folk find particularly shameful about CSS in its current state. So, whether a result of action or inaction on the part of the W3C, browser and tool implementations, or our own misconduct, here are seven scandalous sagas from the world of CSS.

1. Fear of height

Perhaps if we’d named it the “World High Web” we’d be more concerned with managing height in design. Width we can do, and pretty darned well, but even when it comes to the simplest use of the height property, we find ourselves teetering on the edge. Some of the challenges we face:

  • Consistent height handling across browsers
  • Equal height columns in floats and positioned elements
  • CSS Animations not applying to elements with a height value in browsers

There are countless use cases where height is critical to a design, and this is easily achieved in static media. However, it’s extremely difficult in a variable, vertically scrolled medium such as the web. Width is enforced by the physical limitation of the device at hand, the limitation of software limitations in operating systems and user agents, and finally by convention: The horizontal scroll is a known user experience and accessibility problem, so we tend to avoid it.  Vertical scrolling however is an expectation with an online experience.

CSS media queries can help with the height issue by allowing us to provide a style sheet to viewport widths and heights. While extremely helpful in multi-modal design, it’s a far cry from a real solution. Other areas where height control is improving is in paged media, Generated Content for Paged Media (GCPM), multicolumn layout and other layout modules.

Height control in CSS3 Generated Content for Paged Media

2. Clear My Fix

Floating. Away from CSS the word brings to mind lazy summer afternoons, white puffy clouds and a sense of freedom. Why then have floats been exactly the opposite of free, and most importantly, how do we, once and for all, clear them properly?

Float clearing wasn’t a concern in terms of layout because floats were not originally intended to create columns, which is how we now use them in contemporary CSS design. Originally, floating was simply meant to provide a means to have text flow around an element to the right, to the left, or to clear both right and left. Who remembers this syntax?

  1. <img src="images/myCoolPicture.gif" width="200" height="100" align="right" hspace="10" vspace="10" alt="picture of ME!">

You know, I actually got a little nauseated typing that, as it seems so clunky in retrospect. Yet this is the heart of floating, not creating columns within a layout. So, we have to deal with the legacy behaviour as we’ve morphed floats from their original use into creating columns. Floats are not in the “normal flow” (the way text content flows in the document when no floats or positioning are applied) – everything has to flow around the float – an “island in the middle of the stream” as my colleague Kevin Lawver likes to say. This is why clearing is hard.

The best way, in my opinion, is to use the overflow: auto approach. This works brilliantly, with a few caveats:

  • A width or height value might be necessary for browser compatibility
  • If content goes beyond a specified width, the browser may show scrollbars

So test, test, test! Another argument can be made that the technique of creating a class .clearfix {clear: both;} applied to a <br> element (NOT a <div>) is not outside the realm of reason, because this technique is based on the original float model, where a break with a clear of “all” is how we managed clearing in the past. However, most designers and developers prefer avoiding anything that seems presentational and opt for CSS solutions, of which overflow: auto is considered most appropriate in contemporary standards-based design.

Multicolumn, responsive design at two columns
Multicolumn, responsive design at two columns

3. The !importance of being earnest

Perhaps the most misunderstood bit of CSS syntax is the “Bang Important” keyword. I’m still asking at the W3C who was responsible for the insanity that !important has brought us, but no one wants to ‘fess up, probably fearing for their well-being.

There are two serious errors that were made surrounding !important that have resulted in widespread lack of understanding and misuse of both the term and the keyword itself.

  1. CSS 1.0 states “Sort by origin: the author's style sheets override the reader's style sheet which override the UA's default values.” This, to me, seems backwards, as reader (aka user) style sheets are mostly meant for accessibility, and my own logic says that a user style sheet should by default override the author’s sheet! So !important provides a means for those creating user style sheets to ensure the override. As such, I worry about use of !important in your author styles. If everything is important, nothing is important! So my advice is avoid !important in all deployed style sheets. It’s very useful in author style sheets when you’re debugging, particularly in cases of specificity problems. However, I suggest repairing the specificity issue, and not using !important as the stop-gap.
  2. It might just seem to be an annoyance that the “bang” itself represents NOT to many programmers, who first look at !important and think “not important” rather than “really, really, really important” which is what !important actually means, at least in CSS. Not so much a small annoyance when you’re trying to educate a programmer who has held the idea that “!” = “not” in their head for 20 years.

At this point, !important is CSS’s bastard child, and no matter our feelings about how it came to be or what it looks like, it’s part of the family now and we need to understand how to cope.

4. Relative Trouble

You know we all have relative problems. But CSS positioning as it is currently implemented is as confounding and weird as float problems. Semantic ped-antics have been shouting about clean markup for years, for good reason. Why then do we have to use extra <divs> and muck about with relative positioning in order to create fairly simple layouts?

I blame the entire issue on naming. Relative? TO WHAT? Not many of us were clear that meant “an element remaining in the normal flow positioned in relation to a positioned ancestor or the document’s root element.” I often ask the CSS Working Group “Who on earth thought it was a good idea to use the word ‘relative’ to mean that?” Blank faces. I could go look it up in the mail archives but I figure why ruin the mystery? Instead, it provides us with something else to bitch about and keeps us writer and educator types employed.

The hard, cold truth is that CSS has no surefire method for layout, and we’ve kludged together the technology to make it do what we need it to do, disregarding what an element was originally meant to do. That is downright hackish, but until there are other solutions, we do what we must, which means the occasional extra div or relative positioning and element without offsets in order to create containers for floats-as-columns, which are also hackish.

Fortunately, multicol, the Flexible Box Model (flexbox), Template Layout Module, Grids, Paged Media, GCPM and the very exciting CSS3 regions are moving forward both in the Working Group and implementations, so we should begin to see some major changes in the next few years about how we go about laying out our designs.

Multicolumn, responsive design in single column view
Multicolumn, responsive design in single column view

5. A Font of Folly

Oh, we are all so very happy that @font-face is here, alive and well and giving us great opportunity to improve the literal face of web typography. It’s taken years to get us this far with fonts, in part due to licensing issues for embedded fonts in browsers, and only now are we seeing fonts really take off on the web. This is especially true with the growth of open source fonts and tools such as Typekit. However, certain problems still exist with fonts, even with the advances made in the past few years.

  1. Internationalization (i18n) concerns such as vertical text layout are still in early proposal stages. This means that for those of us using horizontal text, we have some control. Languages that have vertical text, however, such as Japanese (which uses both horizontal and vertical text layout), do not enjoy the advantages we have with English and other horizontal-only languages.
  2. Fine control remains elusive – kerning, character spacing – controlling these aspects are both difficult to specify for numerous reasons. This is frustrating to designers who love typography and want to have that finer control.

Certainly, we’ve come a long way, considering embedded fonts was proposed in the mid-90s, and work for finer controls in the specifications marches on.

Real fonts for the Web!
Real fonts for the Web!

6. Of Central Intelligence

Math, calculations, regular expressions. In order to centralise style and be able to apply it in a variety of ways, developers have long been clamoring for these features despite dramatic disagreement with certain members of the CSS Working Group.

This has caused developers to do what they often do best: Solve the problems themselves. This is laudable in theory, practical in a flawed environment and can cause irreparable rents in the Web’s fabric. As a result, we end up with JavaScript polyfills, CSS and JavaScript frameworks, and techniques such as OOCSS, SaSS and SCSS.

Surely such frameworks and techniques have brought us new knowledge, and empower us to do work today. But taken in the greater view of an Open Web, consistency is imperative for true interoperability. The specs are where these issues are best resolved for long-term sustenance and evolution on a stable Open Web platform. Ah, what dreams may come!

Fortunately, the CSS Working Group is growing and changing and we now are seeing CSS beginning to offer such features. While generally speaking implementors dislike RegEx because it's complicated to engineer. Fear not! You will be getting more calculation features and a bit of RegEx here and there in CSS3.

7. Ancestral Selection

I was originally going to leave this out for another article, but I feared your wrath! One of the most asked questions for those of us teaching and advocating CSS, this issue is a frustrating one, so I had to cover it at least in brief.

Just as we can’t choose our ancestors in real life, we can’t select elements from a descendent and travel up the tree in HTML. Other technologies, such as xPath, provide a way to do this, so it's not an impossibility to eventually imagine such a feature.

Bottom line? It’s an extremely difficult problem to specify and implement. Many devs have asked for it, but I doubt this is a feature we’ll be seeing anytime soon in CSS itself. I’ll be taking a longer look at this issue, with insight direct from browser developers, in a future article.

Only Seven?

Okay, so you know as well as I do that these tales of CSS woe are only a mere sampling of the things we want. But rest assured, there’s a lot of cool stuff going on with CSS. We see better and faster implementations, more community involvement in the W3C process and less drama between competitors when it comes to standards implementation. We’re leaving the dramas of our teenaged past behind. I hope we’re all ready for a new generation of sagas and scandals to come!

24 comments

Comment: 1

Though I have never needed an !important, always can clear a float in a div and never written a piece of browser specific CSS I agree with most of what is a very well written article, so thank you for your piece :)

One note though that needs to be mentioned wherever people espouse the benefits of the @font-face ...
Anyone who uses this should be aware of the accessibility issue that goes along with it as more and more websites are (and will) be required to become compliant with these standards in the future.

When you download a non-standard font into a a website, the browser cannot read the font to someone using assistive technologies as words, but only as letters, so you are forcing those users to hear every word spelled out.

So? Don't think it matters.. well keep in mind the people with the most money right now are the baby boomer generation and the number one physical challenge they face as they get older is sight.

Also, the accessibility market is a 13 billion dollar untapped market.. so before you let your designers get too creative just keep in mind that even if this only effects 5% of your users, if you have 100,000 users a month this is 5,000 users. Etc etc you know the rest.. So if you do use it, is best used judiciously.

Ok of soapbox! :)

Again great article.. thanks!! :)

Comment: 2

The layout enhancements are the most exciting thing IMO. I've lost count of the number of times I've argued with developers who dismiss CSS, and web development in general, simply because of the pain of creating layouts using traditional methods. I try to persuade them that float and positioning based layouts aren't so bad, but let's face it: they've never been more than a rather painful hack that we've learned to live with. Having the ability to layout using grids and regions, and the tooling that will come along with it, is going to make an incredible difference.

Comment: 3

schachin: Do you have a source for that @font-face problem? I've never heard that, and can't find anything on Google to support it. I don't understand why browsers, which have access to the raw text bytes within the HTML, would have any problem reading out words regardless of them using a custom font, as fonts should only affect how the text is rendered to the screen.

Comment: 4

Really great blog, i found this an interesting read. I do agree there are things still missing from CSS however i do believe that with the arrival of CSS 3 it really has wiped out the majority of problems which we may of once faced when styling a website. I do agree font-face is a great tool, and is helping us designers have better typography on our websites, however as you stated there are still improvements which need to be made.

Comment: 5

I'd like to see beveled and chamfered corners, make it into the spec. Chamfered would be easy, they just need to allow for a negative value for border-radius.

Variables, Font stroke, Bluring, Tinting would be nice as well.

Comment: 7

I cannot think of anything worse than putting math into CSS, and thankfully, I doubt it will ever happen.

Comment: 9

For those that want a good font-face site go to http://www.fontsquirrel.com/fontface. I use the ready made font-face kits a lot and even used the font-face generator. No I do not work for them I just enjoy what they offer to web gurus.

Comment: 10

Have you tried Treesaver http://treesaver.net ? We do a lot of the pagination and column based stuff using javascript. It acts similar to Opera's reader but has many more layout and user interface functionality built in.

+1 for Sass on point 6! Would be nice to have that built into CSS but it's going to be a while until we can all use it without worrying about legacy browsers.

Comment: 12

I have to agree somewhat with brightonmike, math and such "dynamic" functionality may be better being kept separate from the CSS standard. One of the main ideas of CSS is that it is the abstraction of presentation - there is no programming style behaviour... If its wanted folks can use some of the good techniques like SCSS. I dont like to use these myself, but others do.... its down to the user and seems to be more part of the workflow of creating a style rather than a part of the style(sheet) itself.

Comment: 13

Hi all, thanks for the great comments and resources!

A quick comment regarding Brightonmike and Toby's concerns - while I personally see the value and understand the long-living argument of keeping math and calculations out of an abstract presentation layer makes sense from spec purity. Absolutely. And this is why it's taking as long as it is to get these things. For whether the purists among us want it or not, CSS is becoming more and more programmatic in nature, just as HTML5 (APIs specifically) has become.

Is this a good thing for the Web? I don't know. What I do know is that it's better spec'd than kludged. At least if spec'd, there are implementation processes that ensure some level of interoperability and long-term sustenance as a result. It's the non-standard fixes I worry about.

Ironically, while JavaScript solves so many of the problems we're discussing (thanks Mr for the treesaver resource) the point in CSS is to achieve the pagination, height, font and related features in CSS, not JavaScript.

Thanks again for all the feedback, interest and useful resources!

Mols :)

Comment: 14

Besides these (although math on CSS? No, thank you!), what I most want:

* This, without clever javascript. http://masonry.desandro.com/
* A way to align things to the BOTTOM or TOP without taking the element out of the flow (i.e. absolute-positioning it).
* Overall, better "layout" capabilities. Floats are good, but far from ideal. Multi-coumns are a pain (specially if we need equal columns on all of them) and most things layout SHOULD and CAN be simpler than how they've been done so far.

Comment: 15

I will say that !important does have its uses. It is especially useful if you're pulling external libraries and you need a style to override those without having to know every last facet of those libraries to rewrite their rules.

However, it should NOT override user style sheets. That's where things went wrong

Things Missing #8 - faster standardization procedures. How can we expect browsers to support progress if the overseers won't codify it?

Comment: 16

I really wish border had margin so you could use border for interesting outlines.

Comment: 17

I would love it if CSS could inherit styles from one element into another within the same style sheet (similar to variables, nestings, and mixins with Sass). Wouldn’t it be nice to not have to learn another style of coding and not have to add several CSS classes to one element to achieve the same effect?

Comment: 18

Couldn't agree more about the use of !important. Whenever I see it in a stylesheet I just know I'm going to be in a world of pain.

If only more CSS authors would take the 'mobile-first' approach and create generic styles first and build greater specificity in where required as the design increases in detail for larger displays, then I think we would find that the !important statement would rarely be required, if at all.

Comment: 19

If you look at the following blog [1] post by Dr. Axel, concerning CSS4, the first point there is about determining the subject of a selector, which is basically the same as the 7th point in post above.

[1] http://www.2ality.com/2011/12/css4-selectors.html

Comment: 20

On the topic of clearfixes, you don't mention this option which I've seen (in various variations) a number of places:

.group:after{
content: ".";
dislplay: block;
height: 0;
clear: both;
visibility: hidden;
}

(it's usually .clearfix, but i find that rather not semantic)

is it out of vogue these days? too hackish?

Comment: 22

> On the topic of clearfixes, you don't mention this option which I've seen (in various variations) a number of places:

> .group:after{
> ...
> }

> is it out of vogue these days? too hackish?

That's a very old clearing technique that should be out of use at this point. Depending on whether you care about supporting IE6 or not, you can now simply use:

{ overflow:hidden }
or
{ overflow:hidden ; zoom:1 }

The second option has no real-world downside, though it's technically not valid. For primarily North American audiences, overflow by itself will be sufficient. In some AP countries, IE6 still has a significant footprint.

Comment: 23

The height issues are definitely a huge problem. 90% of arguments with the design team come down to either un-even heights or crappy fonts.

I also always find it funny when developers freak out over math in CSS. A few years ago, it was common to have these insane levels of nested em styles to ensure that size ratios stayed consistent when users zoomed in on content. These problems would have been incredibly easy to solve with very simple math and variable implementations, but instead CSS purists preferred the far more confusion em method. Even now, many height issues could probably be tackled with some basic variables.

Math in CSS might seem like a bad idea if you're in a role where you can hand craft every page, but when you're building 1,000 page CMS powered monsters or large applications, variables could be a great way to adhere to DRY coding standards and write more flexible styles.

Comment: 24

I like using Treesaver when possible for paging and it works very well, as long as you don't mind your images larger then one column floating around. Another possible solution is Zurb Foundation. its great at readjusting for screen sizes and with a little css you can have only the sections show one at a time. Granted both those solutions use javascript. But what you gonna do. Here is a video example of using Zurb this way. I also included the source files in dropbox for others to play with. http://www.youtube.com/watch?v=aCGXm2N9XrE
July issue on sale now!

The Week in Web Design

Sign up to our 'Week in Web Design' newsletter!

Hosting Directory
.net digital edition
Treat yourself to our geeky merchandise!
site stat collection