Web Standards Creativity: Innovations in Web Design with XHTML, CSS, and DOM Scripting

CYAN MAGENTA YELLOW BLACK Be inspired by 10 web design lessons from 10 of the world’s best web designers ~ Get creat...

32 downloads 972 Views 30MB Size Report

This content was uploaded by our users and we assume good faith they have the permission to share this book. If you own the copyright to this book and it is wrongfully on our website, we offer a simple DMCA procedure to remove your content from our site. Start by pressing the button below!

Report copyright / DMCA form

This presents fairly well in its raw, unstyled form when viewed in a browser, as shown in Figure 2-6. The order of content in an unstyled page is important, although not a top priority for this site, because the target audience uses modern browsers on regular PCs. However, all of the content is at least properly formatted without styling, so the site is accessible at a basic level, which is much more than was achieved by the original design.

Figure 2-6. The naked lunch . . . er, content

34

8032CH02.qxd

12/19/06

11:20 AM

Page 35

Notice that the “modules” in the sidebar (conveniently assigned the class .module) are empty. These are just containers, in which the actual CMS-generated content will be dropped shortly, so for now, we leave them alone. The important thing is that they exist, can be targeted individually thanks to their unique IDs, and their order within the document flow is interchangeable. While most of this markup should be fairly self-explanatory, I’ll discuss the handful of .clearfix classes in the next section. Later, in the “Spit and polish” section, I’ll review the technique I used to style the unordered list for the main navigation (the navigation wasn’t generated by the CMS).

I said that the CMS content templates didn’t include a list option, so what’s with that
    in the footer? Due to the time constraints on the project, I was able to convince the powers-that-be to add a list option to the content templates. This gave me the proper hooks needed to style the list and use more appropriate markup for that styling. It’s much better to clean up the markup and then work your CSS magic than to work with messy, crowded markup. That said, the look could also have mostly been re-created using the original nonlist markup, it just would have required much more CSS trickery to accomplish a similar result, which would have unnecessarily complicated the project and extended the timeline.

    chapter 2 Taming a Wild CMS with CSS, Flash, and JavaScript

    Ever find yourself getting lost in a sea of divs when working with generated markup? If you’re stuck working with a CMS that generates as many nested divs as the one discussed in this chapter, you can help make your markup easier to read (for you and others) by commenting the closing tag of each div with the ID or class of its corresponding opening tag. Take a look at the sample markup. See how much easier it is to pair up the closing tags of commented divs compared to the tags without comments?

    The layout and styles Now we’re getting into the heavy stuff, so you may want to let your family members know they won’t be seeing or hearing from you for quite a while, except for bringing you many cups of tea over the course of the next section—you do need your brain fuel, after all. We’re not actually going to get into a deep discussion regarding the layout itself—it’s not really that snazzy under the hood—but we are going to review the basic styles needed to create it.

    I find it helpful to organize CSS properties within a rule block, especially when reviewing/tweaking a style sheet during browser testing or when adjustments have to be made after launch. Here’s the order I prefer: ■

    Display method (display: or float:)



    Background settings



    Positioning method (position:)



    Position (x,y)



    Width/height



    Margin/padding



    Color



    Text settings (font/line height/alignment)



    Borders

    This is yet another simple time- and aggravation-saver that should make your life a bit easier. Anything that adds some structure and order to your markup or styles will pay you back down the road. 35

    8032CH02.qxd

    12/19/06

    11:20 AM

    Page 36

    Positioning elements While we're not trying to accomplish anything groundbreaking with the overall layout, it's worth reviewing how each major element is positioned before we move on to the nitty-gritty. First, clear the floats: .clearfix:after {content:"."; display:block; height:0; clear:both; visibility:hidden; } .clearfix {display:inline-block;} /* Hides from IE-mac \*/ .clearfix {display:block;} /* End hide from IE-mac */" body { background:#111 url(../i/bg_body.gif) repeat-x; margin:0;padding:0; font-family:'lucida grande',tahoma,sans-serif; font-size:small; } #wrapper { width:800px; } #content is set to float:left, causing it to enclose the two floats it contains (#content-primary and #sidebar-wrapper): #content { float:left; } #content-primary is also set to position:relative, allowing #sidebar-tab and #teaser to be positioned absolutely, but within the confines of their containing element. See Doug Bowman’s “Making Absolute Relative” (http://stopdesign.com/ articles/absolute/) for a good overview of this technique. #content-primary { float:left; background:url(../p/homepage_photo.jpg) no-repeat; position:relative; height:549px; width:520px; padding:0; color:#fff; } h1#logo { position:absolute;

    36

    8032CH02.qxd

    12/19/06

    11:20 AM

    Page 37

    #sidebar-tab { background:url(../i/bg_sidebartab_events.png) no-repeat; position:absolute; right:0; top:0; width:20px; height:194px; }

    chapter 2 Taming a Wild CMS with CSS, Flash, and JavaScript

    z-index:100; left:29px; top:39px; margin:0;padding:0; } h1#logo a { display:block; background:url(../i/logo_lifehouse.gif) no-repeat; width:38px; height:175px; text-indent:-5000px; }

    #teaser { background:url(../i/bg_teaser.png) no-repeat; position:absolute; left:0; bottom:0; width:507px; padding:20px 0 30px; color:#EFB32F; font-family:'lucida grande',verdana; line-height:1.3; } #nav is cleared to make sure it falls beneath #content-primary. Similarly, .module is cleared to allow any content within each module to be floated, because each subsequent .module will clear any such floats. #nav { background:url(../i/bg_nav.gif) repeat-x; width:520px; height:53px; margin-top:0; border-top:3px solid #111; clear:both; } #sidebar-wrapper { float:right; background:#1C1C1C url(../i/bg_sidebar_wrapper.gif) no-repeat left bottom; width:277px; margin:0 0 3px; padding:0 0 10px; } 37 #sidebar { background:url(../i/bg_sidebar.gif) repeat-y; }

    8032CH02.qxd

    12/19/06

    11:20 AM

    Page 38

    #sidebar .module { color:#A07029; padding:15px 15px 15px 0; border-top:1px solid #111; clear:both; } #footer-wrapper { background:#1B1B1B url(../i/bg_footer_wrapper.gif) repeat-x; padding-right:10px; clear:both; border-top:1px solid #333; } #footer { background:#262626 url(../i/bg_footer.gif) repeat-x; padding:20px 0 20px; } There is nothing really odd about any of this. It’s a mixture of container
    s (or wrappers), some floats for the columns, and a dash of absolute positioning. Since the purpose of this chapter isn’t to teach you the basic principles of CSS, I won’t go into the details here. I recommend reading Simon Collison’s Beginning CSS Web Development (Apress, ISBN: 1-59059689-7), if you feel you’re lagging behind in any of the basics.

    I like to name images based on the convention type_id_label to make it easier to remember the purpose of each image (for example, logo_footer_geffen.gif). Also, file-naming conventions make it easier for a third party or your client to determine the “whats and whys” associated with your design and code. While a style guide can also accomplish this task, often a project’s budget or timeline doesn’t allow for the creation of a style guide, or if one exists, it might not be available to someone making changes in the future.

    Targeting CSS selectors The big problem with the generated markup contained within the basic shell markup I showed you earlier is that I have no say in the decision of which markup is used. Where a definition list with nested paragraphs within the description might be most appropriate, I could be forced to deal with a few nested
    s containing

    s with <span>s littered all over the place. You can see this for yourself by reviewing the source of the live site. Ugh. Have another (strong) cup of tea to help you get over that mental image. Thankfully, as bad as that sounds, there is a relatively easy way to dig out of that hole. CSS selectors come in many shapes and sizes. Many designers are used to working with only the basics: IDs: Appear as #footer in CSS, and as an attribute value on an element in (X)HTML, such as