Skip to page content or skip to Accesskey List.
Search evolt.org
evolt.org login: or register

Work

Main Page Content

The Wrong Way to Use CSS in Page Layouts

Rated 4.23 (Ratings: 23) (Add your rating)

Log in to add a comment
(20 comments so far)

Want more?

 
Picture of aardvark

Adrian Roselli

Member info | Full bio

User since: December 13, 1998

Last login: September 01, 2006

Articles written: 48

Lately I've come across an ever-increasing amount of web sites that use absolute positioning with Cascading Style Sheets (CSS) to achieve some very specific layouts.

While this has been going on essentially since Macromedia Dreamweaver was released, allowing anybody comfortable with a WYSIWYG web layout package to build CSS-laden sites, recent pushes for accessibility and standards compliance in HTML has made CSS the new buzzword of the wanna-be-elite developer.

Unfortunately, many people are still using WYSIWYG packages to do their web development, and many of them are trying a table-free approach in their attempts to ride the wave of the CSS flood. What some of these developers tend to forget is that pixel-precise layouts are anything but, especially when you consider all the custom settings users may have on their systems.

For those who have read my article on liquid web design ("Liquid Design for the Web," DisplaySearch Monitor, August 30, 2001; also available here on evolt.org), you may be familiar with my simple mantra of building for the user and allowing the layout and design of the web page to adapt to nearly any conditions that users may throw your way. Lately, however, frustrated laptop users have been directed my way (partly due to my article) because sites they visit, or worse, sites for which they've paid, don't display properly on their systems.

At first, the symptoms were confusing. Blocks of text supposedly sat on top of other blocks of text, copy was unreadable as words stacked themselves atop one another, and sometimes text seemed to appear out of order. It took a little while to coax a screen capture out of anyone, but eventually I got one. A sample of what I saw is included in Figures 14 and 15. Please note that I've butchered a page on my own site as an example, since I think the affected parties would rather not have their sites shown.

Figure 1Figure 1: This screen capture shows just a minor overlap, but enough that some of the text is unreadable.


Figure 2Figure 2: This screen capture shows a more severe example of the reported issues. Text is more illegible, and it seems impossible to determine what text goes where.

So how did this happen?

In each of these cases, a developer using a WYSIWYG editor was the culprit. Having spent many of my years as a web developer cleaning code spit out by these editors, I've gotten used to recognizing much of the specific syntax and style that they use. I recognized most of these offenders as Macromedia Dreamweaver. Generally regarded as one of the better editors on the market, and deservedly so, it offers the ability for developers to create table-free layouts thanks to CSS positioning syntax. Developers who wanted to claim they were ditching tabled layouts for CSS-only layouts, something that organizations such as the Web Standards Project (WaSP) have been pushing for some time, could now do just that without having to learn a lick of CSS.

Unfortunately, Dreamweaver's approach to layouts powered by CSS is anything but ideal. It eschews structural and semantic HTML elements in favor of the most basic elements, the ones that imply nothing but act simply as containers — <div>s. Instead of wrapping headlines in headline tags (<h1> through <h6>) or blocks of text in paragraph tags (<p>), everything gets wrapped in a <div>, every paragraph, every headline, even every table. This can be overridden, and there are many talented developers who do just that, but they aren't the ones creating these problem pages.

Once a developer starts dragging paragraphs around the screen, each one is assigned an absolute x and y coordinate that it must occupy, as opposed to simply flowing one after another as in a word processor. And developers did just that, they dragged every block of text to just where they wanted it. With the WYSIWYG interface hiding the underlying code, these developers never saw the coordinate being assigned to each <div>, let alone the fact that each <div> was also assigned an absolute height and width, regardless of how much content it held. Figure 3 shows what the developer would have seen, a simple layout with paragraphs of copy flowing one after another.

It's worth noting that I have a bit of a bias against WYSIWYG editors, something you can read more about in the article "To Hell With Bad Editors".

Figure 3Figure 3: The developer sees nothing wrong. After all, he or she is developing on his or her own system, so it should look ideal there.

What made it break?

One problem with laying out blocks of text in very specific positions on the screen is that it doesn't take into account users who have their font sizes enlarged for any reason. It also doesn't take into account users on flat panel displays who often have the display set to something other than 72 or 96 pixels-per-inch (ppi). And it seemed there were enough of both of these kinds of users that the calls came in.

Blocks of text ended up being larger than accounted for by the designers for these users. So while the second paragraph may have been placed 175 pixels from the top of the page, at higher resolutions or larger font sizes, the end of the paragraph above it extended below that 175 pixel mark, causing the text to overlap. Of course, this was compounded as the page progressed, and sometimes a third paragraph would start before the first one had ended.

All three of the above images are screen captures from Netscape 6.02 on Windows 2000. The default size for text in Netscape 6 is 16 pixels at 96ppi. Figure 3 shows the default setting the developer would have used. Figure 1 shows how that same page looks if the default font size is set to 18 pixels, and Figure 2 shows it set to 20 pixels. If the user had extremely good eyesight and set the font sizes to 12 pixels (lower than the developer's settings), there would be very large gaps between the blocks of text.

Those users on laptops, for example, would see similar results if their display settings, not their browser settings, were modified. During more testing, general users of flat panel displays experienced these problems as well, owing to their tendency to run their displays at resolutions higher than 72 ppi — often 100 ppi, and even a few at 140 ppi for the group used for testing. These users were initially told by developers that the users simply had their font sizes set too large. This is regardless of the fact that if the developers were correct, users did that so they could actually read the text. And so users correctly responded that, for the most part, their font settings were at the default.

It occurred to some of the developers that people might come to the sites with larger fonts, but it was generally decided that these users could simply make their text smaller to see the page. Some of those developers, however, built their pages with type size units (pixels or points, for example) that could not be resized by the browser. It never occurred to any of the developers, however, that some users might be running at different pixel densities. So when developers had ordered their clients and their users to simply resize their fonts, and it didn't work, they were stumped. They hadn't gotten under the hood to see what was wrong with the code.

How did you fix this?

Correcting this problem was embarrassingly simple. By opening the pages in a plain text editor, I could immediately see the offending code. It was just a matter of replacing every positioned <div> with a more semantically correct <p> tag for paragraphs, and <h1>-<h6> tags for headings. With the removal of all positioning, the page would flow well for any user, regardless of their browser, screen settings, or font size settings. Clearly there could be exceptions, but none were encountered.

The solution was simply a case of under-engineering. Removing all the widgets resulted in an eminently usable page.

How can I tell if my site is broken?

Well, one of the simpler ways is to change your font sizes in your favorite browser. A slightly more complex method involves changing your display settings to something significantly higher than 96 ppi.

The simplest way, however, is to look at the code. It's one thing to absolutely position some elements on the page, such as logos, navigation, or other design elements, but it's another thing to do that with every paragraph of copy. If, in the source code, every paragraph is wrapped in a tag like the one below, you may want to run the other tests I mention above:

<div style="position:absolute;left:20px; top:175px; width:500px; height:50px; z-index:2">

The statement "position:absolute" is the first sign of trouble. The assignment of pixel values to "left" and "top" means the block is positioned a specific distance from the top left corner of the window. While a "width" attribute might not be bad, a "height" attribute could be an issue as well if the code is also set to hide text that doesn't fit within the specified dimensions (via a "clipping" attribute).

Compounded errors

Not directly related to this, but somewhat ironic given the attempts by these designers to make more accessible pages by using CSS, was how the pages read to screen readers. Many of the developers had entered text a paragraph at a time, and not in order. When the page itself was seen by screen readers, the paragraphs were all out of order in the code, making for a very confusing page. But the developers couldn't see this problem because every block of copy was placed on the page visually, without regard for the code beneath. This distance from the code ended up creating far more problems than intended.

Conclusion?

Clearly this article addresses some very specific cases that don't pop up too often, but they've popped up enough, and with increasing frequency, that it's worth watching out for them as a developer, user, or a buyer of web development. Web pages are anything but static, let the user push them around and you'll be ahead of the game.

About This Article

This article originally appeared in the March 15, 2002 issue of DisplaySearch Monitor, published by DisplaySearch, the worldwide leader in flat panel display market research and consulting.

A founder of evolt.org, Adrian Roselli (aardvark) is the Senior Usability Engineer at Algonquin Studios, located in Buffalo, New York.

Adrian has years of experience in graphic design, web design and multimedia design, as well as extensive experience in internet commerce and interface design and usability. He has been developing for the World Wide Web since its inception, and working the design field since 1993. Adrian is a founding member, board member, and writer to evolt.org. In addition, Adrian sits on the Digital Media Advisory Committee for a local SUNY college and a local private college, as well as the board for a local charter school.

You can see his personal portfolio at http://roselli.org/.

Adrian authored the usability case study for evolt.org in Usability: The Site Speaks for Itself, published by glasshaus. He has written three chapters for the book Professional Web Graphics for Non Designers, also published by glasshaus. Adrian also managed to get a couple chapters written (and published) for The Web Professional's Handbook before glasshaus went under. They were really quite good. You should have bought more of the books.

While you're reading, a friend of mine has just launched her site, and you should take a look. Kristen Kos, a lovely and talented actress, now has her own site with her acting resume and some new head shots.

Thanks!

Submitted by Oregon_Jim on March 16, 2002 - 21:36.

I had used Dreamweaver demo a couple of times and was stunned at the results when I uploaded the few pages I'd created to a server. One peek at the code and I yanked the Dreamweaver demo off of my machine. Not ready for prime time.

login or register to post comments

Time to WYSIWYG?

Submitted by mcombs on March 17, 2002 - 07:57.

I was around when the newsgroups were bursting with discussion about the pros and cons of using C compilers instead of hand-coding in assembly language. If you only used a compiler, you'd never get to truely understand the machine, or the underlying structures. Your code would be less efficient. It'd run more slowly, waste bytes, use memory when it could use registers... How could anyone waste a client's money by coding real applications in C instead of in assembly language?

The WYSIWYG tools will improve, computers and bandwidth will improve, libraries and standard ways of doing things will improve.

Dreamweaver isn't perfect, but use of high-level tools can make building a site more efficient and cost-effective for the customer. Hand-code the ONLY the stuff that needs it. Try to work fast where you can. A few extra bytes of inefficiency in the final page is worth it, if you can bring the project in at the budgeted price and schedule.

(I'm not defending Dreamweaver on this particular issue, I'm just defending the coming use of WYSIWYG tools for web design.)

Now, remember when publishing was only for publishers, and not just for anyone who could type and click "submit"? We need to discourage just anyone from publishing articles and comments (like this one) until they've been properly schooled in journalism.

login or register to post comments

If WYSIWYG continue to improve...

Submitted by chozsun on March 17, 2002 - 09:21.

... why has it taken more than 6 years and the tools are still not as good as handcoding?

I am not saying any software is perfect (Unix is 30 years old and almost there... Windows as a server has a long WAY to go but I digress) but I still get that sick feeling looking at code that has been spit up by WYSIWYG tools.

Even under a timeline, I still handcode all of my pages (albeit with Homesite... auto-completion is your friend). Even if I was to throw a site up with WYSIWYG tool, the end product looks nothing like what it did in the design portion. Now I have to do double duty fixing all the crap that the WYSIWYG put out when I could have just handcode it and get it right the first time. Dreamweaver now is just as bad as Netscape Composer six years.

I have yet to see an improvement.

login or register to post comments

ain't no WYSIWYGs here...

Submitted by aardvark on March 17, 2002 - 10:50.

Mcombs, this article isn't supposed to be an indictment of DreamWeaver or WYSIWYGs in general. I do note that I'm not a fan of WYSIWYGs (see link above third image) so people can assess my opinions more accurately, but this article was written to address a specific problem that I've seen pop up more and more lately. It's essentially a 'how-to' article on recovering from a relatively common issue, not an attack.

Given the two recent threads (Dreamweaver bitchfest and real men code by hand...) on the list, I can see that this article could be viewed as an extension of those, which it isn't.

login or register to post comments

Weaving the web of woe

Submitted by danfascia on March 17, 2002 - 11:20.

not forgetting my now infamous bitch at Macromedia's gem...

As already noted, the level of coding on the web mirrors more and more "real" programming everyday. The same rules apply in my opinion. More respect for an ASM coder than someone who knocks something out in VB... its a direct cmparison with HTML vs WYSIWG

login or register to post comments

McCombs - "The WYSIWYG tools will improve"

Submitted by Oregon_Jim on March 17, 2002 - 11:30.

Not until their customer base demand it and quite frankly the overwhelming number of Dreamweaver/Golive users are far more concerned on making sure that their web sites look really cool than any attempt to publish valid code.

Obviously Macromedia's goal is to sell you Dreamweaver, Fireworks, Flash, etc.

Adobe wants the Golive users to be buying Acrobat, Livemotion, ImageReady, After Effects, etc.

Glitz, bells, whistle, whirs, clangs, beeps, ad naseum.

Nothing wrong with what Adobe & Macromedia are trying to push. That's called capitalism. They're goal is to provide financial rewards to their investors. Their customers cling to the promise that anyone can be a web developer which obviously creates huge profits for WYWIWYG publishers.

The responsibility for much of the lousy work on the internet lies with the users of these so-called tools.

login or register to post comments

i reckon...

Submitted by jesteruk on March 17, 2002 - 17:30.

...everyone should know what they're coding. I've always hand-coded my pages, i can't use these editors, they produce horrible code, take up more space than needed, and look completely different when viewing the resulting page in different browsers.

Learn HTML, it just takes practice, once you get used to it, hand-coding isn't that much slower than using one of these editors. Especially if you use CSS correctly.

-J

login or register to post comments

Knowledge vs. tools

Submitted by timswan on March 18, 2002 - 07:51.

This whole issue is more about a lack of coding knowledge than about WYIWYG tools. If you know html and css you can use Dreamweaver to create code that's just as clean as with a text editor -- and with DW's code editor, integration with text-based editors, extensibility, and great search and replace features it's very easy to do. If you don't know html and css, then I agree that WYSIWYG tools can give people the false impression that they know what they're doing. Denigrating the myriad of other useful, timesaving features in a tool like DW because it requires a certain amount of knowledge seems like a silly waste of time.

login or register to post comments

Dreamweaver

Submitted by sehryan on March 18, 2002 - 10:02.

I think the problem is not the fact that someone uses Dreamweaver. Dreamweaver can be a great tool for putting out clean webpages quickly. The problem is that no one seems to want to properly QA/QC html. If you aren't testing and retesting your code before you upload it, then you deserve to have people leave your site because of incompatibilities. In the end, the tool isn't at fault, the methods are.

login or register to post comments

WYSIWYG abuse

Submitted by agianni on March 18, 2002 - 16:02.

I've been coding HTML since '94 and I used to be in the dev tool haters camp, but I sat down and made myself learn to use Dreamweaver about a year or so ago, and I have to admit that I really like it and I feel I can develop good solid pages faster with it. I dont want to debate usability of the tool because I feel that its about personal preference, but to address the issue of its ability to produce good code, let me repurpose an old clich:

Dreamweaver doesnt generate bad HTML, people using Dreamweaver generate bad HTML

The real key is that in order to use a tool like Dreamweaver and GoLive effectively you need to have a good core understanding of HTML. The problem is that a large percentage of people out there using these tools don't have 5 years (or even a couple months) to learn the intricacies of HTML and I dont think its fair to assume that they should have to (despite the current necessity). The real problem (IMHO) is that theres a gap between HTML and people based on two principles:

- HTML is being used for something it wasnt originally designed for, and squabbles over what it should be have hampered its ability to become a useful and usable standard, yet it is widely used.

- People developing sites (professional or not) want an interface theyre used to that reacts in a way they expect and that's simply not the case (because of the problem suggested above)

In the end, I can sum up my feelings about this aspect of Web development with this: Web development tools democratize Web publishing like the US political system supports our democracy. My point being that they both do and they both don't. I don't mean to get us into a political argument, I'm just using an anaogy and it's intended to be neutral exactly because it cuts both ways.

login or register to post comments

democratise?

Submitted by jesteruk on March 18, 2002 - 16:31.

Sheesh, that's going a bit far lol Web development tools such as DW just make it easier for people who can't be bothered to code by hand, fullstop (period). Every product has its ups and downs, no harm in debating them. I feel arguing about computer programs is like arguing about which food is best; we all have our preference. In my opinion "site builder" tools suck, i can't use them, i need to write it myself. If it makes it easier for any of you guys out there then good luck ;)

-J

login or register to post comments

yes, democratize

Submitted by agianni on March 18, 2002 - 17:21.

This is definitely getting a little off the topic of Aardvark's article, but what the heck. I should have started by giving some context to my comments. I work for a non-profit organization (ONE/Northwest) that helps the environmental organizations of the Pacific Northwest use technology more effectively. I'm in charge of all things Web and on a daily basis I'm dealing with how to help these groups use their limited resources (money and time) to develop and maintain a Web presence that represents their point of view.

Regardless of whether you are using the Web to sell services or promote your philosophy, giving non-technically-minded people the option of using a tool with an interface that's a little more intuative potentially gives them the ability to better express themselves. It just happens to be more evidant to me becasue resources are so limited in my work.

In the end, my point was that Web development tools don't really meet the promise of helping that lowest common denominator of Web developers, but they're the people that eat this up. Consensus around evolt seems to be that there are sucky things about development tools and people choose to use them or not. It's unfortunate that such a large percentage of those who use these tools don't really have the background to be able to use them effectively.

And as for the food analogy, it may be a matter of preference, but the nutritional difference between a twinkie and a bowl of minetrone soup is pretty real :)

login or register to post comments

Exactly...

Submitted by GlobalMind on March 18, 2002 - 18:57.

This is precisely the issue with the idea of full CSS in our HTML designs.

I personally do all my coding with just a text editor and am very comfortable with this method and get ( I believe) good results this way.

I am currently re-working my site and I know that full CSS is absolutely out of the question.

The problem I see is that it is likely we will never be able to fully exploit those tools which are at our disposal in the HTML specs simply because someone somewhere won't be able to use it correctly.

Unlike the desktop marketplace, it is seen as somewhat taboo to acutally ask a user to have a browser that is just slightly younger than dirt.

The same issue goes for compliance with text, something that folks contend you need to allow text browsers access to the site too.

Thus the entire issue of accessibility. The saga will continue forever I think...

K.

login or register to post comments

yup

Submitted by jesteruk on March 18, 2002 - 20:28.

They need to come up with some kind of standard, but saying that, people want to choose what they use to view web pages with, i know i do. Different browsers will always behave differently, making it difficult to write a site that'll be compatible to all users, we can only do our best, we can never be perfect. Perfect is like infinity, you can keep advancing but you'll never get there. Alot of people who critisise do so becuase something isn't perfect, you can always find something to pick at.

And yes agianni, dreamweaver is baby food, it looks sweet, it's not too bad when you try it, but you'll have the shits for weeks and regret it if you gobble it up, hehehe.

-J

login or register to post comments

to address the issue at hand

Submitted by agianni on March 19, 2002 - 01:35.

To actually address Adrian's article :) the principle I follow to avoid these kinds of problems (and it's not just CSS2) is that I don't hard code the size and position of anything unless it is a design element and I can use CSS positioning or px font sizes to avoid making an image that contains text. Actually, with the advent of Netscape 6.x, IE5 on the mac and their nasty habit of resizing absolute font sizes, I may even give in with that. So the key is to only use them when you know you have full control over the environment *and* you've browser checked it (I don't think it's ever possible to over emphasize that). I *never* apply absolute font sizes or position to content text. Big usability taboo.

Andrew

login or register to post comments

well..

Submitted by jesteruk on March 19, 2002 - 15:00.

When i was designing my layout i wanted a select form input in the top left corner, and a logo in the top right, i used position: absolute to do this, i figured it wouldn't cause any harm. It worked fine in IE, the select input was exactly where i wanted it, but when i tested it in NS 6 the select input was there, yet i coldnt click it, couldn't interact with it and pick an option, it was like it was the image of a select input or something, was weird. So instead of using the DIV tag and positioning them with CSS, i just used a good old table to put the select input on the left and the logo on the right. Position: absolute is a big no-no for me these days

-J

login or register to post comments

Dreamweaver for designers, Homesite for coders

Submitted by exasperator on March 20, 2002 - 23:08.

As a programmer I let our designer come up with what he thinks the site should look like, it is then my job to strip out all of the extraneous code and rework the site in clean HTML and CSS. He can't do it! And frankly he shouldn't have to do it. He makes it look nice, I make it work.

CSS and HTML aren't for most designers.

login or register to post comments

hmm....

Submitted by jesteruk on March 21, 2002 - 14:56.

Well, i'm sure that's true for you. I just don't regard HTML and CSS, or even Perl and PHP, as programming. A web designer should have some working knowledge of HTML and CSS, and more. I prefer to both design and script any site i make, but i design in a text editor, once you get used to coding, you can "see" the code, if you know what i mean.

Just my opinion.

-J

login or register to post comments

Faster, better...

Submitted by arnaud on March 26, 2002 - 09:58.

Well, I've made my first page with div's and css... It's much better. A lot faster for the browser, it permits a lot of things with Javascript, because all layers are independants, permits to do a CSS file specially for printing, which automatically hides menus, etc... and is more accessible for non-visual browsers. CSS and HTML are for most designers. ;-)

login or register to post comments

Any examples?

Submitted by viola on April 7, 2003 - 10:47.

"Please note that I've butchered a page on my own site as an example, since I think the affected parties would rather not have their sites shown." I would be grateful if anybody can point me in the direction of any real life examples on the web, because I can't seem to find any. Thanks

login or register to post comments

The access keys for this page are: ALT (Control on a Mac) plus:

evolt.orgEvolt.org is an all-volunteer resource for web developers made up of a discussion list, a browser archive, and member-submitted articles. This article is the property of its author, please do not redistribute or use elsewhere without checking with the author.