Structure Stylesheet
This is the guts of the new Medieval scroll template. A lot of it is replicating things I did in the Earth Chronicle stylesheets but those have been cobbled together over the years. This gives me a chance to start fresh, refactor from scratch and find cleaner ways to work things out using full CSS2.1. Doing so allowed me to accomplish some things I had trouble with before including the <code> tags for marking up computer code more semantically. I'm not even sure why it works now... or more likely why it didn't work before! Apparently stuff lying around in the main style sheets prevented it from working, and since these stylesheets are streamlined and refactored, it's no longer an issue. Woo Hoo!
/* /////////////////////////////////////////// */
/* /////////////////////////////////////////// */
/* ///
/* /// Medieval Scroll 02 Initial Layout CSS
/* /// Structure
/* ///
/* /////////////////////////////////////////// */
/* /////////////////////////////////////////// */
/*
This file adds the CSS driven structure and positioning of the page.
*/
/* CSS Shorthand */
/*
2 numbers - Top&Bottom Left&Right;
3 numbers - Top Left&Right Bottom;
4 numbers - Top Right Bottom Left;
*/
The header for my file is loaded with comments, first describing the file, then including a cheat sheet for CSS shorthand. When I'm working on a design it becomes second nature, but during maintenance this is handy to have around.
/* ////////////////////////////////// */
/*
/* General Structure
/*
/* ////////////////////////////////// */
/* Basics */
* {
margin: 0;
padding: 0;
}
body {
margin: 2em 1em 0 2em;
}
p, ul, ol { /* Page Width */
width: 85%;
max-width: 1150px;
}
p {
margin: 0.5em 0;
padding: 0.1em;
text-indent: 2.5em;
}
Next I have a nice fat comment block indicating a major section. It's also the most general section so that major and important style rules are near the top with more specific items coming lower down. The first item is three lines of whitespace followed by the "/* Basics */" heading to indicate the topic of these particular styles rules. Organization and whitespace are critical to being able to understand a stylesheet quickly. If you are building a website on your own for fun, this may not be important, but if you're managing and maintaining multiple websites it is critical.
The first and most important style rule in any sheet is the * rule. The number one browser compatibility issue that destroys designs is the different default margins and paddings that each browser applies to every element. This style rule annihilates all margins and paddings so that only the ones you specifically apply take effect in any browser. I apply some margin and / or padding to the main XHTML elements: body and p.
I also define the width of the webpage with a combination of width and max-width properties. Width keeps the content from moving all the way across the browser window, ie it adds whitespace along the right. This prevents text from running across excessively long lines for users with high-resolution monitors, though IE6 doesn't respect max-width. Note that I've applied this width only to content elements - paragraphs and lists - so that I can use the full width of the page for elements that relate to the interface. This is also the first instance in the stylesheet of what I call "Object Oriented CSS". I've grouped all these elements together for this style rule, because they are part of a larger concept (referred to as an object in programming). p, ol, and ul elements are all content items. So even though there is a style rule for p tags right next to it, that is not where I specify the width and max-width for paragraphs. That style rule contains properties that affect paragraphs, while page content (p, ol, and ul elements) have their width defined in a separate style rule. This is Critical for maintainable / reusable style sheets. By grouping the style rules for particular concepts / objects together, I can redefine the page width at a stroke without having to hunt down multiple style rules which are probably spread throughout several style sheets.
I will try not to go into excessive detail. Most elements of the stylesheet are fairly obvious if you crack them open and take a look at them, which I encourage you to do. I've read books and studied websites on CSS, and while that was important groundwork, looking at other people's designs and stylesheets and building your own is really how you learn to use CSS. There's lots of margin and padding style rules to create reasonable whitespace; without them the page would not be readable and it also visually groups semantically related elements. Lots of positioning using text-align and clear properties and even a few displays to change the way that certain elements behave; for example, the recommended page links are each block-level list items. However, I've changed their appearance using a display: inline; declaration to give them the look that I want. Now let's take a look at the forward and back links.
/* Navigation: Forward and Back */
.pageBack {
float: left;
}
.pageForward {
float: right;
}
.jumpBack {
clear:both;
float: left;
}
Given the kind of squirrely way that they behave in the current stylesheets, I was shocked that this was all I needed to do to make the forward and back links work. The problem is IE 6. I've included some additional comments to go into the IE specific stylesheet if I'm not able to work this out as we go. I'm not going to panic at this point though. I believe it was trying to fix IE 6 in the main stylesheet that caused these elements to act strangely. Creating standards compliant code exclusively is saving me significant headaches. This was the step that convinced me to apply a separate stylesheet for IE 6 in the first place, if needed.
/* Page Info Section */
#authorship, #postingDates {
width: 45%;
}
#authorship {
float: left;
}
#postingDates {
margin-top: -1.1em; /* Postion postingDates alongside authorship vertically */
float: right;
}
#pageInfo .spacer { /* Postion postingDates alongside authorship horizontally */
clear:none;
}
This was another shocker for me. I've had trouble off and on struggling with ways to make the authorship and postingDates sections behave. While there are still some things I'm working on, it was just this easy to get the postingDates to align to the right of authorship section with proper vertical and horizontal positioning. I'd set a new clear:both; on the spacers so I had clear it to allow it to fall in line to the right of the authorship. Apparently something in the old stylesheets was creating difficulties, because adjusting the top-margin up was all it took to align it vertically so the tops are even. In the old version, I tried numerous options and hours of alternatives, but couldn't stop the postingDates from displaying one or two pixel lower than the authorship section.
/* Computer Code */
code.computerCode, .computerCode code { /* Create block structure for code blocks */
display:block;
}
.computerCode {
margin: 0.5em 3em;
}
.codeNewIndent {
text-indent: -2em;
margin-left: 3em;
}
.codeNewBlock {
margin-top: 1em;
}
I already mentioned this surprise. Previously, I'd spent about an hour fruitlessly working in the current Beta website stylesheets to get the codeNewBlock class to work with the inline element <code>. Here everything worked beautifully out of the gate. I reset the <code> element to appear with block-level characteristics when used with the computerCode class; this way it behaves normally unless computerCode is specifically invoked. The codeNewBlock works, and I even redid the codeNewIndent class so that the first line is indented by 1em while the others are indented by 3 to make it easier to discern when lines wrap in the code samples.
This worked on some of these short pieces but was not robust enough. I had to wrap every line in it's own div to make this work, which is semantically ridiculous. So I reset .codeNewIndent {margin-left: 1em;} and it no longer distinguishes wrapped lines but at least displays consistent behavior. Hopefully, I will figure out a way to style this so that line wraps distinguish better.
[chroniclemaster1, 2009/06/18]
#contactForm fieldset {
padding-left: 1em;
}
#contactForm input, #contactForm textarea {
margin: 0.1em 0.5em;
padding: 0.2em;
}
#contactForm ol {
list-style-type: none;
}
As you can see I've applied only the most basic of form styling. I won't lie, I played a little, but having spent six webpages trying to work out the contact form the first time, I was prepared for the nightmare that is CSS-based form styling. Accessible form design is not a risk issue, it's just a pain in the @$$. This will probably wind up being a page unto itself at some point, and to be quite honest, I'm postponing the pain for now. I'm also postponing the navbar for now because that will have a lot of CSS on it. It's highly mission critical so I want to explain it in detail, and this page is already heavy enough.
Skip to Main Points