Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Best Practices and CSS


Published on

A powerpoint presentation on Best Practices and CSS given to the Chicago Dreamweaver Meetup Group.

Published in: Technology, Education
  • ★★ How Long Does She Want You to Last? ★★ A recent study proved that the average man lasts just 2-5 minutes in bed (during intercourse). The study also showed that many women need at least 7-10 minutes of intercourse to reach "The Big O" - and, worse still... 30% of women never get there during intercourse. Clearly, most men are NOT fulfilling there women's needs in bed. Now, as I've said many times - how long you can last is no guarantee of being a GREAT LOVER. But, not being able to last 20, 30 minutes or more, is definitely a sign that you're not going to "set your woman's world on fire" between the sheets. Question is: "What can you do to last longer?" Well, one of the best recommendations I can give you today is to read THIS report. In it, you'll discover a detailed guide to an Ancient Taoist Thrusting Technique that can help any man to last much longer in bed. I can vouch 100% for the technique because my husband has been using it for years :) Here's the link to the report 
    Are you sure you want to  Yes  No
    Your message goes here
  • ➤➤ 3 Reasons Why You Shouldn't take Pills for ED (important) ➤➤
    Are you sure you want to  Yes  No
    Your message goes here
  •    Reply 
    Are you sure you want to  Yes  No
    Your message goes here
  • very nice!
    Are you sure you want to  Yes  No
    Your message goes here
  • very nice!
    Are you sure you want to  Yes  No
    Your message goes here

Best Practices and CSS

  1. Best Practices and CSS An Overview
  2. What is CSS? C ascading S tyle S heets <ul><li>Cascading Style Sheets is a means to separate the presentation from the structural markup (xhtml) of a web site. By applying a CSS style you have the ability to keep the structure of your document lean and fast, while controlling the appearance of content. </li></ul>
  3. Content <ul><li>Content is the collective term for all the text, images, videos, sounds, animations, and files (such as PDF documents) that you want to deliver to your audience. </li></ul>
  4. XHTML (e X tensible H yper T ext M arkup L anguage <ul><li>XHTML enables you to define what each element of your content is. Is it a heading or a paragraph? Is it a list of items, a hyperlink, or an image? </li></ul><ul><li>You determine this by adding XHTML markup to your content. Markup comprises tags (the tag name is in enclosed in angle brackets<>) that identify each element of your content. </li></ul><ul><li>XHTML defines a document’s structure . </li></ul>
  5. Key Requirements for XHTML Code <ul><li>Declare a DOCTYPE, Strict or Transitional </li></ul><ul><li>Declare an XML namespace, </li></ul><ul><ul><ul><li><html xmlns= lang=“en” xml: lang=“en”> </li></ul></ul></ul><ul><li>Declare your content type, <meta http-equiv=&quot;Content-type&quot; content=&quot;text/html; charset=utf-8&quot; /> </li></ul><ul><li>Close every tag, <img src=&quot;cat.jpg&quot; alt=&quot;My cat&quot; / > <br / > <hr / > </li></ul><ul><ul><ul><li>NOTE: YOU MUST USE ALT TAGS ON EVERY IMAGE, EVEN IF THE VALUE IS “”, OR YOUR CODE WON’T VALIDATE. </li></ul></ul></ul><ul><li>All tags used must be nested correctly, <strong><em> The <em> needs to be closed before the <strong>. </em></strong> </li></ul><ul><li>Inline tags can’t contain block level tags, </li></ul><ul><ul><li>If you nest a block element, such as a paragraph p , inside an inline element, such as link a , your code won’t validate. </li></ul></ul><ul><li>Write tags in lowercase, <span> vs <SPAN> </li></ul><ul><li>Attributes must have values and must be quoted, </li></ul><ul><ul><li><a href= &quot; &quot; > vs <a href=> </li></ul></ul><ul><li>Use encoded equivalents for left bracket and ampersand. </li></ul><ul><ul><li>&lt; vs < &amp; vs & </li></ul></ul>
  6. Start With a Blank Page of Content <ul><li>After you have a design, start with a blank page of content. “Include your headers, your navigation, a sample of the content and your footer. Then start adding your xhtml markup. Then start adding your CSS. </li></ul><ul><li>Use HTML tables semantically–for tabular data, not layout. </li></ul>
  7. The Style sheet <ul><li>A style sheet is a set of stylistic CSS rules that tell a browser how the different parts of a XHTML document are presented. </li></ul><ul><li>A style sheet is simply a text file with the file name extension .css </li></ul><ul><li>There are three different ways to add CSS to your web pages, inline, embedded, and linked from a separate CSS style sheet. </li></ul>
  8. Inline <ul><li>Inline styles (also known as local styles) are added to a tag using the XHTML style attribute, like this </li></ul><ul><ul><li><p>This paragraph simply takes on the browser’s default paragraph style</p> </li></ul></ul><ul><ul><li><p style=“font-size: 25pt; font-weight:bold; font-style:italic; color:red;” >By adding inline CSS style to this paragraph, we can override the default styles.</p> </li></ul></ul><ul><ul><li><p>And now we are back to a regular default paragraph without any inline styles.</p> </li></ul></ul>An inline style only affects the tag to which it is attached. Adding inline styles everywhere is bad for the portability and editability of your markup. Inline styles should be generally avoided.
  9. Embedded (internal) <ul><li>You can place a group of CSS styles in the head of your XHTML document—these are known as embedded styles. </li></ul><ul><li>The scope of embedded styles is limited to the page that contains the styles. </li></ul><ul><li>When you embed the styles in the head of the document, you are not truly separating the styles from the content; they are still in the same document. </li></ul><ul><li><head> </li></ul><ul><li><title>Embedded Styles Example</title> </li></ul><ul><li><meta http-equiv=“Content-type” content=“text/html”; charset=iso-8859-1” /> </li></ul><ul><li><meta http-equiv=“Content-Language” content=“en-us” /> </li></ul><ul><li><style type=&quot;text/css&quot;> </li></ul><ul><li><!-- </li></ul><ul><li>h1 { font-size: 16pt; font-weight:bold; } </li></ul><ul><li>p { color: blue; } </li></ul><ul><li>--> </li></ul><ul><li></style> </li></ul><ul><li></head> </li></ul>
  10. Linked Styles <ul><li>You can place styles in a separate document (a style sheet) that links to multiple pages so that the styles have global (site-wide) scope —the styles defined in this style sheet can affect every page of your site, not just a single page or a single tag. </li></ul><ul><li>This is the only method of the three that truly separates the presentational styles from the structural markup. </li></ul><ul><li>Using this method allows web site design and editing to become easier. If you need to make changes that affect the whole site, doing so is as quick and painless as modifying one CSS style. </li></ul><ul><li>You can link your style sheet to as many XHTML pages as you wish with a single line of code in the head of each XHTML page. </li></ul><ul><ul><ul><li><link href=“my_style_sheet.css” media=“screen” rel=“stylesheet” type=“text/css” /> </li></ul></ul></ul>
  11. Anatomy of a CSS Rule <ul><li>A CSS rule is made up of two parts: the selector , which states which tag the rule selects, (or targets), and the declaration , which states what happens when the rule is applied. </li></ul><ul><li>The declaration itself is made up of two elements: a property , which states what is to be affected, and a value , which states what the property is set to. </li></ul>p {color:red;} selector declaration property value
  12. Writing CSS Rules <ul><li>This basic structure of the selector and the declaration can be extended in three ways: </li></ul><ul><ul><li>Multiple declarations can be contained within a rule. </li></ul></ul><ul><ul><ul><li>p { color:red; font-size:12px; line-height:15px;} </li></ul></ul></ul><ul><ul><li>Note that each declaration ends with a semicolon to separate it from the next. </li></ul></ul>
  13. Writing CSS Rules <ul><li>Multiple selectors can be grouped. If, say, you want text for tags h1 through h3 to be blue and bold, you might type this: </li></ul><ul><ul><li>h1 {color:blue; font-weight:bold;} </li></ul></ul><ul><ul><li>h2 {color:blue; font-weight:bold;} </li></ul></ul><ul><ul><li>h3 {color:blue; font-weight:bold;} </li></ul></ul><ul><li>But you don’t have to; you can group selectors in a single rule like this: </li></ul><ul><ul><li>h1, h2, h3 {color:blue; font-weight:bold;} </li></ul></ul><ul><li>Just be sure to put a comma after each selector except the last. </li></ul>
  14. Writing CSS Rules <ul><li>Multiple rules can be applied to the same selector. If, having written the previous rule, you decide that you also want just the h3 tag to be italicized, you can write a second rule for h3, like this: </li></ul><ul><ul><li>h1, h2, h3 {color:blue; font-weight:bold;} </li></ul></ul><ul><ul><li>h3 {font-style: italic;} </li></ul></ul>
  15. Reset the Styling <ul><li>Before you do anything else when coding a website, you should start by overriding all the browser styles. </li></ul><ul><li>Because of browser differences, it’s a good idea to “zero out” the formatting for commonly used tags. All you have to do is set up some basic styles at the beginning of your style sheet that remove the offensive formatting. </li></ul>
  16. Reset the Styling <ul><li>Here are some things you may want to do to make browsers stop meddling with your designs: </li></ul><ul><ul><li>Remove padding and margins . Browsers add top and bottom margins to most block-level elements—the familiar space that appears between <p> tags, for example. It is best to remove padding and margins from the block-level tags you use and then purposely add the amount you want by creating new styles. </li></ul></ul>
  17. Reset the Styling <ul><ul><li>Apply consistent font sizes. While text inside a <p> tag is displayed as 1em, Web browsers apply different sizes to other tags. You can force all tags to be 1em to begin with, and then create additional styles with specific font sizes for the different tags. That way, you stand a much better chance of getting consistent font sizes across browsers. </li></ul></ul>
  18. Reset the Styling <ul><ul><li>Remove underlines from links. You can create visually exciting navigation bars that use plain old text links. In fact, most of the links in your site look more like buttons, or you use other formatting to indicate an element’s clickability (maybe by adding hover effects), then start off by removing the underlines. You can later selectively add underlines when you want them. </li></ul></ul>
  19. Reset the Styling <ul><ul><li>Remove borders from linked images. Internet Explorer, Firefox, and other browsers add a colored border around any image inside of a link. </li></ul></ul><ul><li>To put these ideas into action, here are a few basic styles you can add at the beginning of your style sheet: </li></ul>
  20. Reset the Styling <ul><ul><li>/* Normalizes margin, padding */ </li></ul></ul><ul><ul><li>body, div, h1, h2, h3, h4, h5, h6, p, ol, ul, dt, dl, dd, form, blockquote, fieldset, input { </li></ul></ul><ul><ul><li>padding: 0; </li></ul></ul><ul><ul><li>margin: 0; </li></ul></ul><ul><ul><li>} </li></ul></ul><ul><ul><li>/* Normalizes font-size for headers */ </li></ul></ul><ul><ul><li>h1, h2, h3, h4, h5, h6 { </li></ul></ul><ul><ul><li>font-size: 1em; </li></ul></ul><ul><ul><li>} </li></ul></ul><ul><ul><li>/* Removes list-style from lists */ </li></ul></ul><ul><ul><li>ol, ul { </li></ul></ul><ul><ul><li>list-style: none; </li></ul></ul><ul><ul><li>} </li></ul></ul><ul><ul><li>/* Removes text-decoration from links */ </li></ul></ul><ul><ul><li>a { </li></ul></ul><ul><ul><li>text-decoration: none; </li></ul></ul><ul><ul><li>} </li></ul></ul><ul><ul><li>/* Removes border from img */ </li></ul></ul><ul><ul><li>a img { </li></ul></ul><ul><ul><li>border: none; </li></ul></ul><ul><ul><li>} </li></ul></ul>The first two styles here are group selectors that apply the same formatting to every one of the tags listed. Add these styles to the beginning of your style sheet, then, further down the style sheet, override them on a case-by-case basis. Thanks to the cascade, as long as a new style appears after the group selectors removing the margins and changing the font size, the new values take precedence.
  21. Reset the Styling Examples <ul><li>Here are styles before they are “zeroed out”. </li></ul><ul><li>Web Page Before Being Reset </li></ul><ul><li>Here are styles after they are “zeroed out”. </li></ul><ul><li>Web Page After Being Reset </li></ul>
  22. Flexible Text Using Ems <ul><li>Sizing text using em units—allows users to resize text. While ems are relative units, they also offer a bit more precision and control. </li></ul><ul><ul><li>What does an em actually mean? Robert Bringhurst, author of The Elements of Typographic Style , writes: </li></ul></ul><ul><ul><ul><li>The em is a sliding measure. One em is a distance equal to the type size. In 6 point type, an em is 6 points; in 12 point type an em is 12 points and in 60 point type an em is 60 points. Thus a one em space is proportionately the same in any size. </li></ul></ul></ul>
  23. Flexible Text Using Ems (cont.) <ul><li>Applying that to the Web world, if the current font-size is the default medium setting (16px in most browsers), 1em would equal 16px . If the default is set smaller at 11px, 1em would equal 11px . The advantage to using ems for font size, line height, and spacing between elements is that as text size is adjusted, those measurements will adjust proportionately. </li></ul>
  24. Flexible Text Using Ems (cont.) <ul><li>Richard Rutter explains a crafty method for normalizing a base font size using ems (, where the units match (more or less) to pixel equivalents. The technique assumes a default browser text size set at medium, which is most often 16px. </li></ul>
  25. Flexible Text Using Ems (cont.) <ul><li>Richard’s method begins by knocking down the base font-size of the page to 62.5% on the <body> element: </li></ul><ul><ul><li>body { font-size: 62.5%; } </li></ul></ul><ul><li>This magic percentage essentially takes the default medium text down from 16px to 10px. The reasoning, Richard explains, is that having a base of 10px means you’ll have a nice round number to deal with and you can think in pixels while actually setting type in ems. </li></ul>
  26. Flexible Text Using Ems (cont) <ul><li>For example, after you apply 62.5% to the <body>, 1em would appear as 10px, 1.2em as 12px, .9em as 9px, 1.8em as 18px, and so on. If we were specifying different values for various elements on the page, we might do something like this: </li></ul>
  27. Flexible Text Using Ems (cont) <ul><ul><li>body { font-size: 62.5%; } /* gives us a base of 10px */ </li></ul></ul><ul><ul><li>h1 { font-size: 2em; } /* 20px */ </li></ul></ul><ul><ul><li>h2 { font-size: 1.8em; } /* 18px */ </li></ul></ul><ul><ul><li>p { font-size: 1.2em; } /* 12px */ </li></ul></ul><ul><ul><li>#sidebar { font-size: 1em; } */ 10px */ </li></ul></ul>
  28. Flexible Text Using Ems-Examples <ul><li>Flexible Text without styles removed. </li></ul><ul><li>Flexible Text with Styling Reset </li></ul><ul><li>Flexible Text with New Font Styles applied. </li></ul><ul><li>Flexible Text with the rest of the CSS markup applied. </li></ul>
  29. Anchor Link Pseudo-Classes <ul><li>Style for Links </li></ul><ul><ul><li>Four psuedo-classes let you format links in four different states based on how a visitor has interacted with that link. They identify when a link’s in one of the following four states: </li></ul></ul>
  30. Anchor Link Pseudo-Classes <ul><ul><li>a:link selects any link that your guest hasn’t visited yet, while the mouse isn’t hovering over or clicking it. This style is your regular, unused Web link. </li></ul></ul><ul><ul><li>a:visited is a link that your visitor has clicked before, according to the web browser’s history. You can style this type of link differently than a regular link to tell your visitor, “Hey, you’ve been there already!” </li></ul></ul>
  31. Anchor Link Pseudo-Classes <ul><ul><li>a:hover lets you change the look of a link as your visitor passes the mouse over it. The rollover effects you can create aren’t just for fun—they can provide useful visual feedback for buttons on a navigation bar. </li></ul></ul><ul><ul><li>a:active lets you determine how a link looks as your visitor clicks. In other words, it covers the brief nanosecond when someone’s pressing the mouse button before releasing it. </li></ul></ul>
  32. Anchor Link Pseudo-Classes <ul><li>In most cases, you’ll include at least :link , :visited , and :hover styles in your style sheets for maximum design control. But in order for that to work, you must specify the links in a particular order: link, visited, hover, and active. </li></ul>
  33. Anchor Link Pseudo-Classes <ul><li>Use this easy mnemonic to remember it: LoVe/HAte . So here’s the proper way to add all four link styles: </li></ul><ul><ul><li>a:link { color: #f60; } </li></ul></ul><ul><ul><li>a:visited { color: #900; } </li></ul></ul><ul><ul><li>a:hover { color: #f33; } </li></ul></ul><ul><ul><li>a:active { color: #b2f511; } </li></ul></ul><ul><li>If you change the order, the hover and active states won’t work. For example, if you put a:hove r before a:link and a:visited , then the color change won’t take effect when hovering. </li></ul><ul><li>Here’s what it looks like </li></ul>
  34. Targeting Particular Links <ul><li>The styles in the previous section are basic a tag styles. They target certain link states, but they style all links on a page. What if you want to style some links one way and some links another way? A simple solution is to apply a class to particular link tags. </li></ul>
  35. Targeting Particular Links <ul><li>Say you have a bunch of links within the body of an article, some of which point to other stories on your web site and others that point outside to other sites. You may want to identify external links in some way so visitors can tell they’re about to leave your site. In this case, you can apply a class to these external links, like this: </li></ul>
  36. Targeting Particular Links <ul><li><a href=“” class=“external”>Visit this great resource.</a> </li></ul><ul><li>To style this link in it’s own way, you’d create styles like this: </li></ul><ul><ul><li>a.external:link { color: #990000; } </li></ul></ul><ul><ul><li>a.external:visited { color: #000066; } </li></ul></ul><ul><ul><li>a.external:hover { color: #3F5876; } </li></ul></ul><ul><ul><li>a.external:active { color:#990000; } </li></ul></ul>Here is what the page will look like: Targeting Particular Links
  37. Building Navigation Bars <ul><li>Every site needs good navigation features to guide visitors to the information they’re after—and help them find their way back. CSS makes it easy to create a great looking navigation bar, rollover effects and all. </li></ul>
  38. Building Navigation Bars <ul><li>At heart, a navigation bar is nothing more than a bunch of links. More specifically, it’s actually a list of the different sections of a site. Lists provide us with a way of grouping related elements and, by doing so, we give them meaning and structure. </li></ul>
  39. Building Navigation Bars <ul><li>A navigation menu is based on a simple list inside a div, like this: </li></ul><ul><ul><ul><li><ul id=“listMenu&quot;> </li></ul></ul></ul><ul><ul><ul><li><li><a href=&quot;#&quot;>Customers</a></li> </li></ul></ul></ul><ul><ul><ul><li><li><a href=&quot;#&quot;>Members</a></li> </li></ul></ul></ul><ul><ul><ul><li><li><a href=&quot;#&quot;>Dealers<a/></li> </li></ul></ul></ul><ul><ul><ul><li><li><a href=&quot;#&quot;>Distributors</a></li> </li></ul></ul></ul><ul><ul><ul><li></ul> </li></ul></ul></ul>
  40. Sample Vertical Navigation Bar <ul><li>Here is the list without the CSS applied </li></ul><ul><li>Here is the list with the CSS applied </li></ul>
  41. Samples of Horizontal Navigation <ul><li>Here is an example of the horizontal navigation bar based on the same list as the vertical navigation. </li></ul><ul><li>Horizontal navigation bar without CSS applied. </li></ul><ul><li>Horizontal navigation bar with CSS applied. </li></ul>
  42. Samples of My Navigation <ul><li>Here is a sample of a navigation I did for one of my clients and here’s the markup: </li></ul><ul><ul><li><div class=&quot;menu&quot;> </li></ul></ul><ul><ul><li> <ul> </li></ul></ul><ul><ul><li> <li><a href=&quot;krueter.html&quot; id=&quot;peepshow&quot;><img src=&quot;images/peepshow.gif&quot; width=&quot;92&quot; height=&quot;22&quot; border=&quot;0&quot; alt=“Peepshow&quot; /></a></li> </li></ul></ul><ul><ul><li> <li><a href=&quot;krueter.html&quot; id=&quot;ann&quot;>Ann von Kreuter</a></li> </li></ul></ul><ul><ul><li> <li><a href=&quot;breyer.html&quot; id=&quot;barbara&quot;>Barbara Breyer</a></li> </li></ul></ul><ul><ul><li> <li><a href=&quot;chocolateBox.html&quot; id=&quot;chocolate&quot;>Chocolate Box</a></li> </li></ul></ul><ul><ul><li> <li><a href=&quot;eastBalt.html&quot; id=&quot;east&quot;>East Balt</a></li> </li></ul></ul><ul><ul><li> <li><a href=&quot;kapnick.html&quot; id=&quot;elise&quot;>Elise Kapnick</a></li> </li></ul></ul><ul><ul><li> <li><a href=&quot;haven.html&quot; id=&quot;haven&quot;>Haven Youth Services</a></li> </li></ul></ul><ul><ul><li> <li><a href=&quot;heartland.html&quot; id=&quot;heartland&quot;>Heartland Alliance</a></li> </li></ul></ul><ul><ul><li> <li><a href=&quot;kindermusik.html&quot; id=&quot;kindermusik&quot;>Kindermusik</a></li> </li></ul></ul><ul><ul><li> <li><a href=&quot;landgraf.html&quot; id=&quot;landgraf&quot;>Landgraf Group</a></li> </li></ul></ul><ul><ul><li> <li><a href=&quot;mphc.html&quot; id=&quot;mphc&quot;>MPHC</a></li> </li></ul></ul><ul><ul><li> <li><a href=&quot;pupule.html&quot; id=&quot;pupule&quot;>Pupule</a></li> </li></ul></ul><ul><ul><li> <li><a href=&quot;reading.html&quot; id=&quot;reading&quot;>Reading Is Fundamental</a></li> </li></ul></ul><ul><ul><li> <li><a href=&quot;tpm.html&quot; id=&quot;tpm&quot;>The Present Moment</a></li> </li></ul></ul><ul><ul><li> <li><a href=&quot;zoobooks.html&quot;id=&quot;zoobooks&quot;>Zoobooks</a></li> </li></ul></ul><ul><ul><li></ul> </li></ul></ul><ul><ul><li></div> </li></ul></ul>
  43. Samples of My Navigation Styles <ul><li>Navigation with no CSS styles applied. </li></ul><ul><li>Navigation with CSS styles applied. </li></ul>
  44. Divs <ul><li>One element that can help add structure to a document is a <div> element. Div actually stands for division and is used to mark a logical group of elements on a page. </li></ul><ul><li>Divs’ divide the page into rectangular, box-like areas. These areas are invisible unless you turn their borders on or color their backgrounds. </li></ul><ul><li>You should include <div> tags for all the major regions of your page, such as a banner, main content area, sidebar, footer, etc. </li></ul>
  45. Divs <ul><li>Once you’ve got your <div> tags in place, add either a class or ID to each one, which becomes your handle for styling each <div> separately. </li></ul><ul><li>For parts of the page that appear only once and form the basic building blocks of the page, web designers usually use an ID. You can use an ID only once per page, so when you have an element that appears multiple times, use a class instead. </li></ul><ul><li>ID selectors are identified using a hash character; (#) class selectors are identified with a period(.). </li></ul>
  46. Type of Web Page Layouts <ul><li>Nearly every page design you see falls into one of three types of layouts— fixed width , liquid, or elastic . </li></ul><ul><li>A fixed width gives you the most control over how your design looks, but can inconvenience some of your visitors. People with really small monitors have to scroll to the right to see everything, and those with large monitors have wasted space that could be showing more of your excellent content. </li></ul><ul><li>Liquid designs make controlling the design of the page more challenging, but make the most effective use of the brower window. </li></ul><ul><li>An elastic design combines some advantage of both. </li></ul>
  47. Fixed Width <ul><li>Many web designers prefer the consistency of a set width. Regardless of the browser window’s width, the page content’s wide remains the same. In some cases, the design clings to the left edge of the browser window, or more commonly, it’s centered in the middle. With the fixed-width approach, you don’t have to worry about what happens to your design on a very wide (or small) monitor. </li></ul><ul><li>Many fixed width designs are about 760 pixels wide—a good size for 800 x 600 screens since you have to leave a little room for scrollbars. </li></ul><ul><li>However, more and more sites are about 950 pixels wide, on the assumption that visitors have at least 1024 x 768 monitors. </li></ul>
  48. Liquid <ul><li>A liquid design adjusts to fit the browser’s width—whatever it may be. Your page gets wider or narrower as your visitor resizes the window. While this type of design makes the best use of the available browser window real estate, it’s more work to make sure your design looks good at different window sizes. </li></ul><ul><li>On very large monitors, these types of designs can look really wide. </li></ul>
  49. Elastic <ul><li>An elastic design is really just a fixed-width design with a twist—type size flexibility. With this kind of design, you define the page’s width using em values. An em changes when the browser’s font size changes, so the design’s width is ultimately based on the browser’s base font size. </li></ul><ul><li>Elastic designs keep everything on your page in the same relative proportions, and makes sure that when someone with poor vision has to pump up the text size, the columns holding the text grow as well. </li></ul>
  50. A Simple Two-Column Fixed Layout <ul><li>In this first example, I introduce a very common layout; it contains a narrow left column for navigation and a right column that houses the rest of the page’s content. In this example, the navigation column is a fixed width, but the content area is fluid—that is, it changes width depending on the width of the browser window. </li></ul>
  51. Two Column Layout-Content <ul><li><!DOCTYPE html PUBLIC &quot;-//W3C//DTD XHTML 1.0 Strict//EN&quot; &quot;;> </li></ul><ul><li><html xmlns=&quot;;> </li></ul><ul><li><head> </li></ul><ul><li><meta http-equiv=&quot;Content-Type&quot; content=&quot; charset=iso-8859-1 &quot; /> </li></ul><ul><li><title>A Simple Two Column Layout Without CSS Applied</title> </li></ul><ul><li></head> </li></ul><ul><li><body> </li></ul><ul><li><div id=&quot;nav&quot;> </li></ul><ul><li><ul> </li></ul><ul><li> <li><a href=&quot;#&quot;>Link 1</a></li> </li></ul><ul><li> <li><a href=&quot;#&quot;>Link 2</a></li> </li></ul><ul><li> <li><a href=&quot;#&quot;>Link 3</a></li> </li></ul><ul><li></ul> </li></ul><ul><li></div> </li></ul><ul><li><div id=&quot;content&quot;> </li></ul><ul><li><h1>A Simple Two column Layout</h1> </li></ul><ul><li><p><strong>Step X - bold text here... </strong>More text here...</p> </li></ul><ul><li><p>More text here</p> </li></ul><ul><li><p>More text here</p> </li></ul><ul><li><p>More text here</p> </li></ul><ul><li></div> </li></ul><ul><li></body> </li></ul><ul><li></html> </li></ul>Two Column Fixed-Content Only The markup has two divs; the first is the navigation div, which is a set of links organized within a list, and the second is the content div, which is a heading and some paragraphs. Here’s what it looks like:
  52. Two-Column Layout-CSS <ul><li>CSS Applied- </li></ul><ul><ul><ul><li>body { </li></ul></ul></ul><ul><ul><ul><li>margin: 0px; </li></ul></ul></ul><ul><ul><ul><li>padding: 0px; </li></ul></ul></ul><ul><ul><ul><li>} </li></ul></ul></ul><ul><ul><ul><li>div#nav { </li></ul></ul></ul><ul><ul><ul><li>position:absolute; </li></ul></ul></ul><ul><ul><ul><li>width:150px; </li></ul></ul></ul><ul><ul><ul><li>left:0px; </li></ul></ul></ul><ul><ul><ul><li>top:0px; </li></ul></ul></ul><ul><ul><ul><li>border-right:2px solid red; </li></ul></ul></ul><ul><ul><ul><li>} </li></ul></ul></ul>The first step in creating your two-column layout is to break the navigation out of the flow of the document by positioning it absolutely. Note that you also need to set the margins and padding of the body to zero to remove any default settings. In addition, you should set the width of your navigation to 150px to create the width of the column and temporarily turn on the right border so that you can see exactly where the div is now positioned. Here’s what it looks like: Two-Column Layout-Step 2 The navigation is now absolutely positioned, and by setting the left and top to zero, you ensure that its top left corner is aligned with the top left corner of its containing element, body . The content area now takes the navigation div’s place as the first element in the regular flow of the document, so it moves to the top left corner of the parent body element. The page looks a bit of a mess at this point. However, the tops of both elements are now aligned, and all you have to do next is push the content div over to the right. We do this by setting its left margin. Here’s what it looks like after setting the content div’s left margin: Two-Column Layout-Step 3 div#content { margin-left: 150px; }
  53. Two-Column Layout-Step Three CSS <ul><li>CSS Applied- </li></ul><ul><li>body { </li></ul><ul><li>margin: 0px; </li></ul><ul><li>padding: 0px; </li></ul><ul><li>font: 1em Verdana, Arial, Helvetica, sans-serif; [ SET THE BASELINE FONT AND FONT-SIZE ] </li></ul><ul><li>} </li></ul><ul><li>div#nav { </li></ul><ul><li>position:absolute; [ RED BORDER REMOVED ] </li></ul><ul><li>left:0px; top:0px; width:150px; </li></ul><ul><li>padding:.5em 0 0 0; [ PUSH THE LIST DOWN FROM THE TOP OF THE NAV DIV ] </li></ul><ul><li>margin: 22px 0 0 15px; [ MOVE THE NAV DIV DOWN AND IN FROM EDGE ] </li></ul><ul><li>border-top:2px solid #069 ; [ ADD A RULE ACROSS THE TOP AND BOTTOM OF THE NAV ] </li></ul><ul><li>border-bottom:1px solid #069 ; </li></ul><ul><li>} </li></ul><ul><li>div#nav ul { margin-top:0px; margin-bottom:.8em; } [ POSITIOIN LIST VERTICALLY WITHIN CONTAINING DIV ] </li></ul><ul><li>div#nav li { </li></ul><ul><li>margin-bottom:.5em; [ ADD SPACE BELOW EACH LIST ITEM ] </li></ul><ul><li>font-weight:bold; [ STYLE LINKS ] </li></ul><ul><li>font-size:.75em; </li></ul><ul><li>} </li></ul><ul><li>div#content { </li></ul><ul><li>margin:20px 0 0 165px; (width (150) + left-margin(15) in div#nav ) [ MOVE CONTENT DIV DOWN AND TO LEFT TO CLEAR NAV ] </li></ul><ul><li>padding: 0 1em; [ PUSH THE CONTENT IN ON THE LEFT AND RIGHT ] </li></ul><ul><li>} </li></ul><ul><li>div#content h1 { font-size:1em; } [ STYLE THE TEXT ELEMENTS ] </li></ul><ul><li>div#content p { font-size:.8em; } </li></ul><ul><li>div#content li { font-size:.75em; } </li></ul>Now that you have your two-column layout, you need to think about making it look more presentable. Two Column Fixed with CSS Applied-Step 4
  54. Sample of Liquid Layout <ul><li>No CSS Applied page </li></ul><ul><li>Web Page with CSS applied </li></ul>