Presentation is loading. Please wait.

Presentation is loading. Please wait.

Web Page Layout With CSS CSS Level 2 vs. Nested Tables Mike Wallick – 11/3/04.

Similar presentations


Presentation on theme: "Web Page Layout With CSS CSS Level 2 vs. Nested Tables Mike Wallick – 11/3/04."— Presentation transcript:

1 Web Page Layout With CSS CSS Level 2 vs. Nested Tables Mike Wallick – 11/3/04

2 What is CSS? CSS stands for Cascading Style Sheets. Most common use is to remove tags from HTML pages. This is also know as CSS level 1. Example: highlighting a block of text:.highlighted { background: rgb(255,255,0); font-weight: bold; } CSS level 2, also known as CSS-P (positioning), uses style sheets to control a page’s layout, much like the traditional nested table approach.

3 Pros/Cons of Nested Table Layout Every mainstream web browser that I’m aware of supports tables. Simple table layouts are easy to learn and implement if you already understand HTML. Finding templates for traditional page layouts (header/footer with three columns in between) are relatively easy. Complex nested tables are error-prone due to the large amount of HTML code that must be used. Tracking down bugs in nested table layouts can be very difficult. For example, if you do have a bug in your table layout, some browsers will render the page correctly. The size of the HTML the client must download can get very large. HTML is not cached, at least not in the way images or style sheets are Large, complex nested table designs take longer for the browser to render.

4 Pros/Cons of CSS2 The HTML the client is required to download is smaller, improving page load times. Style sheets are downloaded once and cached like images and JavaScript files. You can truly separate presentation from content. The entire look of your site can be changed by applying a different style sheet (think, cell phone browser, text-only browser, screen reader applications). Site maintenance becomes much easier, as the HTML is much less complex and easier to debug. There are less “hacks” to code when considering compatibility for multiple browsers. Complex style sheets can get very large, somewhat offsetting the reduced HTML file size. There are several browsers that support CSS2, some better than others, but not every browser does. CSS2 is harder to learn than straight HTML.

5 Float: Taming ’s The CSS2 float element is used, this case, to style simple unordered ( ) lists. The sitenav is an example, using float:left to make the list elements lay out horizontally: TOOLS HELP DEPARTMENTS LOCATIONS WEB SITES PRODUCTS The corresponding CSS2 rules looks like this: div#sitenavback {min-width:800px; width:100%; border-top:1px solid black; border-bottom:1px solid black;} div#sitenav { margin: 0px; padding: 0px; width: 800px; height: 16px; } div#sitenav ul { margin: 0px; padding: 0px; list-style: none outside; } div#sitenav ul li { float: left; text-align: center; } div#sitenav ul li a { display: block; width: 105px; height: 16px; }

6 Here’s the with no styles applied Here’s the same code with the styles applied TOOLS HELP DEPARTMENTS LOCATIONS WEB SITES PRODUCTS div#sitenavback {min-width:800px; width:100%; border-top:1px solid black; border-bottom:1px solid black;} div#sitenav { margin: 0px; padding: 0px; width: 800px; height: 16px; } div#sitenav ul { margin: 0px; padding: 0px; list-style: none outside; } div#sitenav ul li { float: left; text-align: center; } div#sitenav ul li a { display: block; width: 105px; height: 16px; } Taming ’s

7 Rounded Corners Rounded corners are a bit easier using CSS2. Latest News New Corporate Travel Section Netscape Navigator Version 4 is No Longer Supported on the Intranet New Homeland Security Content on the Corporate Internet Web Page NEW Intranet Features! More Articles » Add an item - Edit/Delete div.roundcontent { background: rgb(229,229,229); } div.roundtop { background: url("images/tr") no-repeat top right; height: 15px; } div.roundbottom { background: url("images/br") no-repeat bottom right; height: 15px; } img.corner { width: 15px; height: 15px; display: block ! important; }

8 Latest News More » Add an Article - Edit/Delete Rounded corners with nested tables are a bit more difficult. Rounded Corners

9 Hacks/Workarounds/Bugs One advantage of CSS layouts over tabular layouts is the fact that there are less bugs/hacks/workarounds that you need to consider/deal with. Most notably, there is the Internet Explorer 3 pixel padding bug Top leftBottom right This is very easy to overcome using a very simple CSS rule: /* centercontent is the id of the where * the 3px padding occurs */ #centercontent { height: 50%; } Simply specify a height for the problem.

10 Hacks/Workarounds/Bugs Again, in Internet Explorer, there is a weird margin bug. Notice the white space next to the rounded corners. This only happens in IE, and again, the fix is very simple. Apply a negative 10 pixel margin, because the rounded gifs are 10x10 pixels..menu_curve_left { /* margin: top right bottom left; */ margin: 0px -10px 0px 0px; }.menu_curve_right { margin: 0px 0px 0px -10px; } » Tool Set Odd 10px margin -10px margin applied

11 Pros/Cons of this Layout Content is fairly separated from presentation The file size of the HTML has been reduced by about 20% (14KB to 11KB) The extra data the client is required to download are delivered in a cacheable format. Getting everything to line up “pixel perfect” was relatively easy. The layout grows and shrinks with the browser window. The layout works at 800x600. The additional style sheets add an additional 6KB of files to download. The overall download size for the HTML and stylesheets was a net increase to 17KB. The minimum screen resolution is for the layout to work “perfectly” is 1024x768 pixels. Since IE doesn’t seem to support the overflow:hide property, a Javascript workaround must be used for the center to allow the site to degrade to 800x600.

12 CSS Resources Below is a list of web sites that I found immensely useful in designing this layout. The W3C online resources reference: http://www.w3.org/Style/CSS/learning#online This is where I started and is where I discovered most of the sites below.http://www.w3.org/Style/CSS/learning#online css-discuss Wiki's rounded corner page: http://css-discuss.incutio.com/?page=RoundedCornershttp://css-discuss.incutio.com/?page=RoundedCorners Not very practical, but the CSS Destroy (http://www.literarymoose.info/=/css.xhtml) has some pretty neat examples of CSS use/abuse.http://www.literarymoose.info/=/css.xhtml CSS Zen Garden (http://www.csszengarden.com/) shows just how powerful style sheets can be.http://www.csszengarden.com/ This is the very first article that I read and started to work from: http://www.digital- web.com/articles/web_page_reconstruction_with_css/. It talks about taking an existing tabular site and converting it to CSS level 2.http://www.digital- web.com/articles/web_page_reconstruction_with_css/ An allegedly complete CSS2 reference site (I haven’t read the whole thing): http://zvon.org/xxl/CSS2Reference/Output/ http://zvon.org/xxl/CSS2Reference/Output/ A great CSS1 reference site with a little CSS2 thrown in (float, clear, etc.): http://www.htmlhelp.com/reference/css/. I use this one frequently. http://www.htmlhelp.com/reference/css/ http://www.positioniseverything.net/ - Probably the best resource I’ve found for explaining CSS-specific browser bugs and how to overcome them.http://www.positioniseverything.net/

13 Additional Resources Charlie Kroger added these helpful links: http://alistapart.com/topics/css/ http://www.zeldman.com/dwws/


Download ppt "Web Page Layout With CSS CSS Level 2 vs. Nested Tables Mike Wallick – 11/3/04."

Similar presentations


Ads by Google