CSS Lesson #5
"Tackling Tableless Design"
Designing without the use of HTML tables. It's a relatively new concept, actually, but one that's very interesting and allows for a lot more design freedom. I won't lie to you, it can be pretty complicated and confusing. My first tableless design was the waterworld2 skin used for The Dragon Ball Fanfiction Library. I had upgraded the script running the fanfiction archive to 2.0 and the new templates were written using layers. I'd just finished reading The Zen of CSS Design (highly recommended) and figured that it was a good time to try out what I'd learned.
Two weeks later I had something passable but I didn't get around to refining it until three or four months later. By that time I'd done several eFiction skins using CSS and felt confident enough to tackle the project. I personally like this method of design as it challenges me. I hardly even use HTML tags anymore except for what's required to make a webpage and the <div>, <p>, <span>, <ul>, <li>, <strong>, and <i> tags. Sometimes tables are necessary, though. They're best for creating neat charts of information or for creating a design with strict columns or rows.
Facts About Layers:
1. You can nest them. Nesting is a term used for when you place a set of tags within another set. This is a common practice and is practically unavoidable. A good example is this: you have created a paragraph using a set of <p> tags and now you want to make a word inside of this paragraph bold. So you place <b> tags around it. Congratuations, you've just nested. Have you ever seen those Russian nesting dolls? You start of with one large doll and eventually get to a small inner doll by separating the two halves of the doll to reveal a smaller one inside. In the case of layers, the largest, or the outermost, is more general (such as a section or the entire page) while the smallest, or the innermost, is the most specific (such as a single word).
2. Just about any kind of visual CSS will work on them... as long as you have within the accompanying elements that the property was designed for. Backgrounds, borders, font styles, margins, padding, floats, positioning... you name it, it'll probably work on it.
3. You can shape these just about any way you desire. Of course if you want something that isn't square you'll need the accompanying imagery, but the very fact that you can make these overlap is a neat thing.
4. Floated layers alter the behavior of non-floated layers. If it has no descendant floats a layer will be as wide and as high as the widest and highest child within. With descendant floats, the layer will now only be as wide or as high as any non-floated content within. This can result in the parent element being barely visible. If you don't have a background or a border on the parent then you (or your visitors) won't notice, but if you do you'll have to do something special to fix this (unless you want it this way, of course). I talk about this issue in Miscellaneous Tutorial #3 and the topic is called "Drawing A Border Around Your Entire Content When Using Floats". IE enthusiasts won't have this problem because layers always expand to fit the content, which is not how things are supposed to work.
<div style="background-color:#406480; width:150px; padding:3px; color:#FFF; border:1px solid #000;">
<div style="background-color:#FFF; width:60px; height:50px; color:#000; float:left; border:1px solid #000;">float #1</div>
<div style="background-color:#FFF; width:60px; height:50px; color:#000; float:right; border:1px solid #000;">float #2</div>
</div>
Facts About IDs and Classes:
1. According to XHTML specifications you can only have one instance of an ID per page. In reality, you can reuse the same ID over and over again without any adverse effects but don't count on your code validating. IDs are designed for layers you'll only need to use once per page such as headers and footers. To define an ID just apply the attribute "id" to the tag. To use it in a header or external stylesheet use the pound (#) sign followed by the name of your ID. Example: <div id="header"> ---> #header {width:90%;}
2. You can use a class over and over again. It's good for things like title headings and background colors if applying the same properties to multiple elements. To define a class, add the attribute "class" to the tag. To use it in a header or external stylesheet use a period (.) followed by the name of your class. Example: <div class="heading"> ---> .heading {font-size:12pt; font-weight:bold;}
back to the top
- The Container: The main container is a layer that "contains" your webpage content just as the <html> tag contains the webpage itself. It's nested inside of the <body> just like ordinary content. The main container allows you to control the foreground elements, or the content that's on top of the background. You can also use these to place a border around all of your content. There are more containers. In fact, elements are always considered to be containers as long as they "contain" at least one descendant element within them.
<html><body>
<div id="container">
insert content here
</div>
</body></html>
-
<div> and <p> Harmony: Paragraph tags play very nicely with division tags. If you enclose each section of content within a parapraph tag (these will be within a set of division tags) you can style each section differently if you want (using IDs or classes wouldn't be a bad idea, either). The bad thing about paragraph tags is that you can't nest them and they come with auto top and bottom margins that you may have to alter. If you want to style even further you have to use either a span tag or an appropriate formatting tag such as <b> or <i>.
<div><p>paragraph #1</p> <p>paragraph #2</p></div>
-
A Layer For Every Player: Every major section should be encased within a layer (and encased within a main container) and probably given its own ID. The "usual suspects" are the header, the footer, the navigation, and the page content.
back to the top
- Type Selector: These select any matching HTML tag of the same type. Example: hr {color:#00F;}. This will turn all horizontal rules bright blue unless it's different in a later declaration.
- Descendant Selector: These match a specific descendant, very useful for pinpointing only a specific ID, class, or element. You can go as deep as you need to go. Example #1: #container #navigation {text-align:center;} or Example #2: #header div img {margin-bottom:10px;}.
- Child Selector: Selects the direct child of an element. These do not work with IE6 or older, but are very useful for hiding properties that IE doesn't process well. I talk more about these in Miscellaneous Tutorial #2. Example: html>body>#container>#header {margin-top:-25px;}
- Class Selector: Selects elements with classes.
* .name: Selects any matching class. Example: .heading {font-weight:bold;}
* element.name: Selects the class of a certain element. Example: p.content {background-color:red;}
* element.name1.name2: Selects the class of a certain element whose values match. Any number of words can be put together. Example: p.florida.miami.beach {font-size:9pt;} will match <p class="florida"> and <p class="florida miami"> and <p class="florida miami beach">.
- ID Selector: Selects elements with IDs. It's pretty much the same as the class selector except you can't use "element.name1.name2" because you can only use an ID once per page.
back to the top
A Few Things to Keep In Mind:
1. Divisions aren't tables so don't treat them like they are. This is definitely rule number one. Rigid layouts don't work well when using CSS unless you use fixed widths. Be careful with that, though, because people use different monitor resolutions.
2. Become familiar with floats because you will be using them. A lot.
3. Sub-divisions are useful to organize groups within a group. Don't underestimate the power of these. When you have a buggy layout and you need to figure out what's going wrong, you don't want to spend half an hour staring blankly at your code.
4. Layers are rendered from top to bottom unless you tell them otherwise. This means that content should be in order from top to bottom. I'm not at all good at moving things out of their normal document flow so I haven't yet written a tutorial on it. CSS Zen Garden promotes this type of design so you can view just about any of the designs in their archive for examples.
back to the top
- Atlantis: The header immediately draws your eye and its balanced by simple section headers and a nice font face.
- Japanese Garden: Simple and perfectly Japanese.
- CS(S) Monk: The images are perfect with the background and I like how they extend beyond their container.
- Table Layout Assassination!: I love just about anything Asian-themed and this one is no exception. I like the assassin theme and the simple GIF-type images that are used.
- Like the Sea: The soft, gentle feel of this theme is nice as well as the semi-transparent backgrounds.
- Odyssey: The Roman feel of this is amazing and so is the level of detail.
- Bonsai Sky: I love the fixed border effect (sorry, IE users, you can't see it) and the carved browser logos in the rockface.
- Stormweather: Dave Shea, the man who runs CSS Zen Garden, did this design. It's simple and elegant.
- eFiction: It's pleasing to the eye in every color version. I still can't figure out how these borders are done, though.
- Edo and Tokyo: It's busy but everything comes together well.
- Museum: It's monochrome yet creative. Proof that you don't need a riot of color to make a good design.
back to the top