jwz - CSS is BS [entries|archive|friends|userinfo]
jwz

  www.jwz.org
  userinfo
  archive
  rss

Links
[»| DNA (Log) (iCal) WebCollage (LJ) Mixtapes ]

CSS is BS [Wed, 30-Apr-2003 2:43 AM]
Previous Entry Add to Memories Tell a Friend Next Entry
[Tags|, , , , ]
[music |Throwing Muses -- Hate My Way]

So today I noticed that someone at the office has been printing out the calendar pages and taking notes on them. I never use paper, but I've long since gotten used to the fact that other people do; but this was just incredibly bothersome because it's extra wasteful: there's that menu on the left, and the text all comes out as gray on white, and is pretty unreadable.

I know that if you've drunk the CSS kool-aid, it's possible to make things print sanely: change colors, leave certain items off the page, etc. So I started poking around with using CSS on the DNA pages.

I thought I'd start off with something simple: instead of using tables to do my headings, like

Contacting Us

I should be able to just do

<H1>Contacting Us</H1>

and have it look the same once an appropriate style sheet was in place, right? "Here is how we render H1."

Wrong. As far as I can tell, that can't be done with CSS. The closest you can get is this:

Contacting Us

with the box going all the way to the edges of the page. As far as I can tell, there's no way to tell the size of the box to be based on the size of the text. You can tell it to be exactly 30% of the page width -- but that's not the same. The only way to do it is to wrap the H1 inside a TABLE!

Contacting Us

So I can replace my table-based layout with... table-based layout?

I have learned (or in some cases reconfirmed) a few other things about CSS, too:

  • Web designers, and especially blogging web designers, are self-important fuckheads. This might be tolerable if they were right, but by and large they're also dumbasses.

  • Everybody who fancies themself a CSS expert uses pixel-based layout for everything. Their shining examples of elegance always include boxes that are exactly 400 pixels wide, and that specify font sizes in pixels (not even points!) This is better than auto-flowing auto-sizing table layout... why?

  • Most of the time, these examples look like ass on my screen, presumably because I'm not running Windows and don't have the same fonts that they do. Or maybe because they're all using 50-inch monitors and sit with their noses on the glass, the only way those miniscule fonts could actually look readable to someone.

  • They never measure in "em" units, so that their boxes might have at least some relation to the size of the text inside them.

  • This may or may not be because "em" doesn't work consistently across various browsers.

  • Oh, "em", a term from the world of physical typesetting, is supposed to be the width of a capital letter M, and used only for horizontal measure; the vertical measures are ascent, descent, leading, and sometimes "ex" (height of a lower case "x".) CSS defines "em" as being the height of an M instead (making it synonymous with "ascent"), which makes it generally about twice as big as you'd expect if you know anything about this stuff. Nice. That's like redefining "centimeter" because it seemed more convenient at the time. (Except sillier, since "em" is an older unit of measure than centimeter is.)

Really what I'd like to do is just leave my pages as-is, but insert something that says, "oh, if you're printing, change all the colors like so, and leave the menu out." But I'm not sure that's possible without going whole-hog into the CSS madness, or at least starting to tumble down that slippery slope.

And a slippery slope it is. Here's a great example: once you start doing anything with CSS font sizes, you can't ever use the FONT tag again.

Have you noticed that when you post to LiveJournal and do <FONT SIZE="-1">, the font actually gets bigger? Feel the love as the Mozilla people mark my bug report Resolved Invalid. This is because the FONT tag, when used to request a font "one tick smaller than the current size" has no knowlege of what the current CSS font size is -- and they claim this is the right and sensible thing! Like, HTML thinks the font size is "3" and then it sets it to "2", instead of noting that the font size is "14px" and then setting it to "12px". You get screwed if, as is often the case with LiveJournal, your "2" font is still bigger than whatever the font specified in the style sheet is.

Let me say that again, because I still can't really fathom it: they think that the current behavior, of asking for a smaller font and getting a bigger font, is the correct behavior.

This kind of crap, among other reasons, is why web sites should never, ever specify the font family or size of their default text. Just use the default, always. Web browsers let users pick their default font families and sizes for a reason. Are you listening, [info]brad?



Update: scroll down...

linkReply

Comments:
[User Picture]From: [info]mattlazycat
Wed, 30-Apr-2003 3:45 AM (UTC)

(Link)

This kind of crap, among other reasons, is why web sites should never, ever specify the font family or size of their default text. Just use the default, always. Web browsers let users pick their default font families and sizes for a reason. Are you listening, brad?
Amen. Especially since Internet Explorer 6's "text size" menu options don't work if you specify absolute font sizes with CSS. This also is "correct" behaviour. It is also cock. Tiny shrivelled lazy-stupid-programmer cock. This is what happens when you design by committee. There's always a posse of sharpnosed little nerds at the back who treat software design-to-spec like they were running a D&D game.

I do everything in CSS now, but it has some major drawbacks, especially with positioning. My life hasn't become magically easier now that I don't have to wrestle with tables. There's no way in CSS, for example to have two columns be the same height, unless that height is the height of the browser window. And vertical align doesn't work. The H1 problem you had is also insanely boneheaded. You might be able to get around it by setting "auto" as the left and right margin width, but then IE5 doesn't do auto margins, and it looks like cock again. (Then again, to be fair, making all headers the same width is probably better, design-wise, but that's not the point is it? The point is that CSS won't let you do what you want.)

The huge sense of self importance you detect in most CSS/XHTML evangelists stems from their utter elation at finally pummelling their design expectations and wrestling with buggy CSS implementations until they finally compromise in some Israel/Palestine sense of the word. They become one of the few, and enjoy rubbing our noses in it. "Well I did it, so you must be able to! Unless you're stupid, that is.. you're not stupid</i>, are you?"</i>

What they forget is that either as designers, they're awful and unambitious, or as people, they suffer from short term memory loss and have forgotten both the hours of fucking around with a style-sheet that they just suffered through, and that the end result is nothing like their original aim. To them, tinkering with a style-sheet is like fucking around in /etc/ for days at a time... for fun.
[User Picture]From: [info]jwz
Wed, 30-Apr-2003 2:02 PM (UTC)

(Link)

I thought you might be amused by what your use of the &ldquo; entity turned into once Mozilla 1.3 got its hands on it:

Are we living in the future yet?

[User Picture]From: [info]adcott
Wed, 30-Apr-2003 4:33 AM (UTC)

(Link)

This comment probably confirms your self-important fuckhead theory, but what you are attempting is actually possible (well, it worked in Opera7 and IE6 when I tested it)
<style type="text/css">
h1 {
  text-align: center;
  font-size: 1em;
  }
h1 span {
  color: #0F0;
  font-size: large;
  background: #040;
  padding: 6px;
  border: solid 1px #0E0;
  }
</style>

<h1><span>Contacting Us</span></h1>

Contacting Us



and for this...

Really what I'd like to do is just leave my pages as-is, but insert something that says, "oh, if you're printing, change all the colors like so, and leave the menu out." But I'm not sure that's possible without going whole-hog into the CSS madness, or at least starting to tumble down that slippery slope.

I'm not sure if this constitutes as madness or not:
<style type="text/css">
@media print {
* {
  background: transparent !important;
  color: #000 !important;
  }
#menu {
  display: none !important;
  }
}
</style>
[User Picture]From: [info]rpkrajewski
Wed, 30-Apr-2003 5:34 AM (UTC)

Bravo !

(Link)

Assuming it works, that is.

I think some of CSS can't be learned on demand; you actually have to a read an overview and internalize the model, which includes basic but almost invisible features such as !important and the display attribute.

[User Picture]From: [info]altamira16
Wed, 30-Apr-2003 6:23 AM (UTC)

Shock and Awe

(Link)

I stumble through CSS, and you have done several things that I did not know were possible.

I did not know that you could do

h1 span{
blah
}

I thought you had to use each tag seperately.
I also did not know you could use the
@ symbol anywhere in CSS.
[User Picture]From: [info]blackirisdancer
Wed, 30-Apr-2003 7:53 AM (UTC)

(Link)

That works, but the <span> tag is really ugly (also, totally content-free). There is a better way:

h1 {
  display: table;
  margin-left: auto;
  margin-right: auto;
  
  color: #0F0;
  font-size: large;
  background: #040;
  padding: 6px;
  border: solid 1px #0E0;
}

The display: table causes the block to wrap itself to the text (shockingly, like a table). The auto margins cause the table to be centered.

[User Picture]From: [info]injector
Wed, 30-Apr-2003 8:33 AM (UTC)

(Link)

How about if you just changed the "display" of h1, to "inline"?

h1 {
  text-align: center;
  color: #0F0;
  font-size: large;
  background: #040;
  padding: 6px;
  border: solid 1px #0E0;
  display: inline;
}


Contacting Us

[User Picture]From: [info]jwz
Wed, 30-Apr-2003 1:44 PM (UTC)

(Link)

Really what I'd like to do is just leave my pages as-is, but insert something that says, "oh, if you're printing, change all the colors like so, and leave the menu out." But I'm not sure that's possible without going whole-hog into the CSS madness, or at least starting to tumble down that slippery slope.

I'm not sure if this constitutes as madness or not:

<style type="text/css">
@media print {

See, that's the slippery slope I was talking about. I can't just add that to my pages, because <BODY BGCOLOR="..."> has precedence over style-sheet backgrounds, even with !important. So I'd at least have to replace all my body tags with CSS fu. And, though I'm not sure, I fully expect that once I've gone that far, I'll have to go farther, and farther, and farther... I'll discover new things about TABLE and FONT that start malfunctioning once you've got CSS in your life, and I'll have to convert more and more just to catch up with yesterday.

Which would be fine, if CSS actually worked as well as what I used in 1995, but I don't really see evidence that it does.

(And dammit, [info]brad, why is your HTML cleaner stripping out my <NOBR> tags?)

[User Picture]From: [info]brianenigma
Wed, 30-Apr-2003 8:19 AM (UTC)

CSS in Moderation

(Link)

I have found that you can reach a happy medium between exclusively using CSS and not using it at all. Of course, I am not "a web designer," but a programmer who occassionally has to (or wants to) make a web site. Nothing I have done has, or needs, pixel-perfect positioning. Why do all these so-called web developers need to position a floating table 30 pixels to the left and z-ordered under their crazy JavaScript animated menu bars that never work outside of IE? Nice looking pages can still be designed without that stuff, often have less HTML bloat, and are easier to come back to and edit/maintain (without Frontpage/Dreamweaver/MS-Word, or any other so-called HTML editor).

Generally, I stick strictly to colors in my style definitions: font colors and table background colors. A good alternative to the FONT tag with +/- sizes is to use a percentage. The SPAN tag with a "font-size" style of 80% or 125% tends to work pretty well. Of course, that takes a few more bytes than the FONT tag (even if you define it up in a stylesheet), but the proportionality means it works even if the user has their browser's default font jacked up to 48pt.

...just my $0.02. Again, I am no web designer, I just play one on the internet.
[User Picture]From: [info]jwz
Wed, 30-Apr-2003 1:20 PM (UTC)

Re: CSS in Moderation

(Link)

Why do all these so-called web developers need to position a floating table 30 pixels to the left and z-ordered under their crazy JavaScript animated menu bars that never work outside of IE?

Yeah, and I knew I was in shark-infested waters when, after 20+ minutes of googling for "css examples" and the like, more than half of the pages I came across had their left-side menu-boxes positioned such that no matter how you resized the window, they always occluded some of the body text! Wow, what a great feature that you can make the first six characters of every line always be hidden.

It's always a great big warning sign when such a large percentage of the people who are trying to explain how to do things so clearly don't have a clue themselves. This says "something is fundamentally wrong with the system." Possibly only that it's too complex; but in this case I suspect the breakage is more fundamental than that.

[User Picture]From: [info]teleject
Wed, 30-Apr-2003 10:00 AM (UTC)

(Link)

H2 are block level elements. You will need to wrap a span or an element around the actual text of the headline and then stylize that to get the effect you want. E.g.,

<h2><a name="contactingo">Contacting Us</a></h2>


In a weird sense of timing, I've recently posted a
50+ CSS Heading examples. Hopefully this will get some ideas on how CSS can be used to add style to your documents.

If you need pointers on printing with CSS, let me know--and yes, my book on CSS has a chapter that deals with it.
[User Picture]From: [info]jwz
Wed, 30-Apr-2003 1:49 PM (UTC)

(Link)

So, your examples seem to say that to do what I want to do, you believe I need to use both H1 and SPAN, one inside the other.

It seems to me that if I have to do that, then what's the point? If I have to have magical tag-ordering in the body to make it display the way I want, then I'm still encoding presentation into the body text! If I can't say, simply, H1 with nothing else around it (doing all the magic in the style sheet itself) then I'm not doing semantic markup, I'm still doing presentational markup.

And if I'm gonna do that, then why not just keep doing it with tables, which work in way, way, way more web browsers?
[User Picture]From: [info]malokai
Wed, 30-Apr-2003 11:00 AM (UTC)

(Link)

This is why I don't trust anyone who's job was created after 1990.
[User Picture]From: [info]jwz
Wed, 30-Apr-2003 1:32 PM (UTC)

(Link)

A fucking men.

I haven't heard that stated quite so concisely before.
[User Picture]From: [info]jwz
Thu, 1-May-2003 1:40 AM (UTC)

Update...

(Link)

I ended up doing the minimal thing, and added this to the HEAD of every page:

  <STYLE TYPE="text/css">
<!--
@media print {
* { color: black !important;
border-color: black !important;
background: white !important; }
.noprint { display: none !important; }
}
-->
</STYLE>

And in addition, for the various TD elements that I don't want to bother printing out, I added CLASS="noprint". This was easy, since (almost) all of my pages are generated by script (statically.) I did it this way instead of adding an external style-sheet URL because I figured it was more efficient to add another couple hundred bytes to each file than to add another connect() for each page.

Everything else stayed the same: colors specified in the BODY tag, etc. Seems to work ok in the browsers various people have tried. NS4 doesn't understand display: none, but gets the colors right. Apparently Safari crashes in Print Preview, but hey, bummer.

[User Picture]From: [info]forthdude
Thu, 1-May-2003 1:24 PM (UTC)

Re: Update...

(Link)

Worked fine in Safari for me.

safari 1.0 Beta 2 (v73)
os x 10.2.5
[User Picture]From: [info]chronicfreetime
Sun, 4-May-2003 1:37 PM (UTC)

Re: Update...

(Link)

The included style sheet can be retrieved once and then cached. Also, in the wonderful world of HTTP/1.1, we are supposed to have connection reuse and pipelining.
[User Picture]From: [info]agrumer
Thu, 1-May-2003 10:24 AM (UTC)

Em

(Link)

You're right about em being a unit from traditional typesetting, but wrong about what it means. An em is the size of an em quad -- a square of type material the size of the type to which it belongs, and generally used for indenting paragraphs. An em quad in a case of 12-point type was 12 points high and wide. Its name does derive from the fact that in many early type designs a capital M was approximately square, but if you look at actual fonts the em generally has nothing to do with the size of the capital M.
From: aad
Sat, 3-May-2003 8:56 PM (UTC)

(Link)

I spent about a week trying to coerce CSS layout into replicating the trusty:

<table>
<tr><td colspan=2>site header</td></tr>
<tr><td width=66%>content</td><td width=*>menu</td></tr>
<tr><td>site footer</td></tr>
</table>

Even at the end it only worked "mostly" right in most browsers, and any given display glitch report was answered by browser authors/vendors/support with "we're standards compliant, everyone else has a bug".

I gave up.

The impression I came away with is that whoever created CSS layout knew that a lot of ass hole designers had done some pretty heinous things with HTML to get around its limitations, and the CSS creators decided to aavoid this problem by not consulting designers. This is obviously the wrong approach, but it's the only one I can fathom, because CSS layout makes it difficult to do all but about half of the really simple things people want to do. You read that right. The standards are so nebulous that every browser interprets them differently, and while things are converging, it's a dramatically worse "standards" situation than even tables were in six years ago. (And the "that's easy, just try [non obvious, not particularly well documented feature]" comments above and elsewhere on the web prove my point, not the opposite.)

Meanwhile, a lot of designers have hopped on the CSS layout bandwagon, seeing that it solves a lot of problems they ran into before. What they don't see is that they've changed the sorts of design they produce. But it's obvious: most CSS layout based sites look different from most table based layout sites because CSS layout makes it too difficult to do the sorts of things most people do with table based layout. Meanwhile, the most zealous of converts rant about "standards" in a way which has nothing to do with anything. Tables are in the standard, but they're also interpreted pretty much the same by all browsers. CSS has a standard so big that on Thursdays the entire W3C staff simultaneously stands up and yells "hey, standardize this!", but that doesn't mean that any two browsers interpret this "standard" in a standard fashion.

Zeldman has 5 pages on how to do a two column layout (without a footer), and another site refers to a three column layout as "the holy grail". Last I checked, the holy grail was a legendary and powerful artifact, a label not rightfully applied to a layout any idiot could learn to make with tables in 3 minutes of reading the docs. The three column layout isn't considered impressive because it should be, it's considered impressive because CSS layout makes it hard and the people who use it have the lowest of ambitions.

CSS is a nice idea, but it needs to be extended to support simple layout, and the layout issues within in it need to be standardized before anyone will be able to use it for much.
[User Picture]From: [info]chronicfreetime
Sun, 4-May-2003 2:21 PM (UTC)

(Link)

Personally I use CSS and tables together... CSS to centralize appearance markup, and good old-fashioned tables for layout more complicated than simple flow with the occasional block-level element. I have found some simple-yet-useful layout effects only possible with CSS, but the results are often not sufficiently portable, even assuming NS4 is not a target.

CSS isn't a complete system for mapping text to images. Whether I want my web browser to contain such a system is an interesting question... between Javascript and SVG I'm not sure I will have a choice soon. Certainly there have been moments where I was trying to do something in HTML and wishing for Display Postscript, but often that is a hint to the designer that they should let the content speak for itself and get out of the reader's way.

About the pixel-based layout thing... surely you know that pixels are not pixels in CSS?
[User Picture]From: [info]jwz
Sun, 4-May-2003 2:29 PM (UTC)

Re:

(Link)

surely you know that pixels are not pixels in CSS?

OH. MY. GOD.

So they've now guarenteed that "px" will have all the problems that "point" has historically had! Do they also have a requirement that images be auto-resized to the same scale?

[User Picture]From: [info]firelegend
Mon, 5-May-2003 7:59 AM (UTC)

(Link)

look what you started :)

- brandy AKA firelegend (mediadiva.net)
From: (Anonymous)
Mon, 5-May-2003 9:49 PM (UTC)

Possible Solution

(Link)

A possible solution is demonstrated in the following code:

<!DOCTYPE html PUBLIC "-//W3C//DTD 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>Test</title>
<style type="text/css">
<!--
h1 {
	text-align: center;
}
h1 span.txt {
	background: #040;
	border: solid 1px #0E0;
	color: #0F0;
	margin: 0px;
	padding: 6px;
}
-->
</style>
</head>
<body>
<h1>This is a heading</h1>
<p>This is a paragraph. This is a paragraph. This is a paragraph. This is a paragraph.</p>
<h1>This is a heading</h1>
<p>This is a paragraph. This is a paragraph. This is a paragraph. This is a paragraph.</p>
<script type="text/javascript" language="javascript">
<!--
var h1 = document.getElementsByTagName('h1');
for (var i = h1.length-1; i >= 0; i--) {
	with (h1[i]) {
		innerHTML = '<span class="txt">' + innerHTML + '</span>';
	}
}
-->
</script>
</body>
</html>

I used a style sheet to format to format both the headings and the marked-up text. A bit of JavaScript at the end is also used to transform the non-marked-up text children of the headings into markup-up text. In the future, I plan on adding a text mark-up rule to the XSLT that I use to write web pages (so this quirk of CSS doesn't bother me again).

-Jimmy Cerra (mailto:jimbobbs@hotmail.com)
[User Picture]From: [info]darkcryst
Wed, 20-Aug-2003 6:10 AM (UTC)

(Link)

hey, I knwo this is an old post, but I followed a link here as was moved to comment.

I think the problem with CSS isn't that it can't do what people want, its that people are reluctant to change their methods of coding to suit CSS.

Also the annoying people that evangalise CSS are just as annoying as the people that claim its all BS. The truth is somewhre inbetween atm.

CSS for the most part is implemented badly by designers. Using a correct doctype in your code eliminates 95% of all problems in browsers, yet some sites are still crap.

CSS won't make a bad designer any better, but it will allow him to make a more flexable bad design that downloads quicker.

Designers aren't coders, and coders aren't designers (generally speaking that is) so deigners rarely want to learn a new language - which is what CSS is. The examples you gave are really easy to achive across browsers. IT just requires more knowledge of CSS than you have.

That isn't a slight to you, just fact.

Another problem is that many people are idiots when it comes to upgradein their browser. They wouldn't complain if a 286 didn't run win98, but they will complain if a 6 year old browser doesn't work on all websites. CSS helps here by seperating the presentation from the content so - as long as the deisgner is a good one - even people that can't see styles will be able to read the content without a problem.

Its about flexability and accessability in design and code. Two things that have been neglected, and now don't have to be. In fact legally might have to be concidered now.

I hope you have more luck with CSS, try checking out this comprehesive and well organised resource if you'd like a good reference on what can and can't be done, as well as how.
From: [info]sheala23
Thu, 18-Dec-2003 1:08 AM (UTC)

(Link)

"and that specify font sizes in pixels (not even points!) This is better than auto-flowing auto-sizing table layout... why? "

It's because the Mac OS displays points differently, which makes the page render differently then what you'd expect. With specific pixel specification, you can have the same page completely cross platform. Yeah, it's pretty anal.