Tuesday, May 12, 2009

CSS Sprites


As a web designer, Are you still slicing your images (icons, buttons, layout and mouse over images) and think that this slicing will make pages load faster. All that technique did was of dark ages of www and fool the eye to make it look like the page was loading faster by loading bits and pieces all over at once. Each one of those images is a separate HTTP-Request, and the more of those, the less efficient your page is.

Let’s look at a quote from the article “Performance Research, Part 1: What the 80/20 Rule Tells Us about Reducing HTTP Requests” by Tenni Theurer on the Yahoo! User Interface Blog.

Every single image, whether it’s an <> tag or an background-image from your CSS is a separate HTTP-Request, so you can image how quickly those requests can wrack up.


So what are the CSS Sprites? CSS Sprite is a single image containing set of images used in website the only thing is to place your image set in css sprite and on one image at a time and off all other images. The image will load at once instead of loading all images one by one and save not only HTTP requests but also total size of images.

You can quickly preview the CSS-Sprite example in action by downloading the source code from here



The comparison of old sliced images and this CSS-sprite images load time according to the above example is as follows.
OLD Slicing technique (10 HTTP Requests, 21KB image size) CSS Sprite Method (1 HTTP Request, 13KB image size)








Friday, May 8, 2009

Clean CSS Writing

As a css designer. "How to write CSS" is a question from beginners but "How to write a Clean & optimized CSS" is a question often asked by the experts. Here is My coding style sample with the help of which you can understand and off course able to write the CSS in clean and optimized way and I also share some tips to clean your CSS after finalyzing your css code.

Clean your CSS through code
In case of huge websites I always use different css files for achieving different purposes (i.e. type.css, theme.css and default.css). But in case of small or medium website in use only one css and segregate my css file into following areas / sections

1. global reset
---------------------
- Under this section, I always reset the box issues of IE by grouping the html box tags in the scene of padding, margins and fonts.
- Also I always apply same
fonts
colors
boxes
positioning &
widths
under this section by grouping the 3rd level TOC classes i.e. In case of width .w100,#mHdr,#mMnu,#mCnt,#mFtr{Width:100%;}

2. global hacks
-----------------------
The browser specific hacks which i have to use in almost every website include in this section i.e. PNG-IE hack, hack for outlining, opacity and curves are placed here.

3. layout basic
----------------------
- The website first level TOC placed there i.e. wrapper, header, menu, content, news, footer e.t.c. & only floats, backgrounds and borders are entertained here.

4. layout deep
----------------------
- The website all levels TOC inclusive of first one which is already entertained in Layout Basic placed here i.e. In case of footer the main id is already defined in layout basic i.e #mFtr now I placed all child classes here
A simple example for it is footer griding

#mFtr .mnu (for footer menu container)
#mFtr .mnu ul, #mFtr .mnu ul li (for footer menu styling treatment individually)
#mFtr .mnu ul li a (footer menu links)

#mFtr .cR (copyrighting area / Privacy policy or terms and conditions styling treatment)
#mFtr .cR a (footer copyrighting links)

5. fonts
-----------
All fonts sizes, family and decorations are entertained here.

6. datasets
----------------
All datasets properties along with the hover effects and speeding effects are entertained under this section

7. forms
------------
This section is dedicated for the form elements. All form properties are entertained here.

CONCLUSION
*****************
Above segregation will help me to avoid redundancy and repetition of css code. for instance. I never use float:left / right in each and every class which is most common in practice instead of this i group all classes and apply the style float:left by this way a lot of extra css space is cleaned. Same in the case of widths, colors and font properties are applied. Also I never use font and color properties together in a class. Instead of this I always call both classes in my html so that i can use same font in different color or different colors in same fonts without making extra classes. NOTE that this is not only in the case of just fonts or colors. This is the main reason to utilize the sections defined above appropriately. In the end I always remove all comments and space areas by using dreamveaver find and replace option. css white space optimization

Clean your css after code
You can check
unused CSS selectors with the help of firefox extension https://addons.mozilla.org/en-US/firefox/addon/5392
You can use csstidy to optimize and compress your css. You can download css tidy from http://sourceforge.net/project/showfiles.php?group_id=148404&package_id=166585 OR you can use its online optimizer from http://floele.flyspray.org/csstidy//css_optimiser.php


Reblog this post [with Zemanta]

Tuesday, April 28, 2009

CSS Troubleshooting

Many people asked me about CSS troubleshooting / debugging. This article is specifically written for those who are coding using DIV approach but facing issues and they don't know how to trouble shoot the issues.

  1. The first and simplistic method is using Adobe Dreamweaver CSS Panel. Just click on your HTML code and you will able to find all selectors and their values in CSS Panel. You can find CSS Panel from Menu Bar > windows > CSS Style (Shift + F11).

  2. Second Method is also a simple one, Use multi level selectors for defining outlines by uncommeting following code one by one/* * { outline: 2px dotted red }

    /* * { outline: 1px solid red }*/
    /* * * { outline: 2px dotted green }*/
    /* * * * { outline: 2px dotted orange }*/
    /* * * * * { outline: 2px dotted blue }*/
    /* * * * * * { outline: 1px solid red }*/
    /* * * * * * * { outline: 1px solid green }*/
    /* * * * * * * * { outline: 1px solid orange }*/
    /* * * * * * * * * { outline: 1px solid blue }*/

  3. Third Method is commonly used by web designers and developers. "Firefox Addon - Web Developer Toolkit" You can download it by following the link above . You can troubleshoot your CSS by enable / disable CSS OR Apply Border Function.

  4. The most widely and my favorite one "Firefox Addon - Firebug", You can download it by following the link above OR visit its official website to explore what can you do with firebug http://getfirebug.com/. You can check any website presentation, user behaviour code , edit it and can even duplicate it with the help of this tool. Firefox also have a Lite version for other browsers such as I.E, Opera and Safari e.t.c you can download it from http://getfirebug.com/lite.html



Reblog this post [with Zemanta]

The cascade

Style sheets may have three different origins: author, user, and user agent.

  • Author: The author specifies style sheets for a source document according to the conventions of the document language. For instance, in HTML, style sheets may be included in the document or linked externally.
  • User: The user may be able to specify style information for a particular document. For example, the user may specify a file that contains a style sheet or the user agent may provide an interface that generates a user style sheet (or behaves as if it did).
  • User agent: Conforming user agents must apply a default style sheet (or behave as if they did). A user agent's default style sheet should present the elements of the document language in ways that satisfy general presentation expectations for the document language (e.g., for visual browsers, the EM element in HTML is presented using an italic font). See A sample style sheet for HTML for a recommended default style sheet for HTML documents.

Note: that the user may modify system settings (e.g. system colors) that affect the default style sheet. However, some user agent implementations make it impossible to change the values in the default style sheet.

Style sheets from these three origins will overlap in scope, and they interact according to the cascade.

The CSS cascade assigns a weight to each style rule. When several rules apply, the one with the greatest weight takes precedence.

By default, rules in author style sheets have more weight than rules in user style sheets. Precedence is reversed, however, for "!important" rules. All user and author rules have more weight than rules in the UA's default style sheet.

Cascading Order
To find the value for an element/property combination, user agents must apply the following sorting order:

1. Find all declarations that apply to the element and property in question, for the target media type. Declarations apply if the associated selector matches the element in question and the target medium matches the media list on all @media rules containing the declaration and on all links on the path through which the style sheet was reached.
2. Sort according to importance (normal or important) and origin (author, user, or user agent). In ascending order of precedence:
1. user agent declarations
2. user normal declarations
3. author normal declarations
4. author important declarations
5. user important declarations
3. Sort rules with the same importance and origin by specificity of selector: more specific selectors will override more general ones. Pseudo-elements and pseudo-classes are counted as normal elements and classes, respectively.
4. Finally, sort by order specified: if two declarations have the same weight, origin and specificity, the latter specified wins. Declarations in imported style sheets are considered to be before any declarations in the style sheet itself.

Apart from the "!important" setting on individual declarations, this strategy gives author's style sheets higher weight than those of the reader. User agents must give the user the ability to turn off the influence of specific author style sheets, e.g., through a pull-down menu. Conformance to UAAG 1.0 checkpoint 4.14 satisfies this condition

Monday, April 27, 2009

A simple solution for IE6 PNG support is
HTML Code:
< div class="iePng_logo" id="ieBg"> <img src="images/logo_png.png" class="ieHide" /> </div>

CSS Code:
.iePng_logo {filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(src='images/logo_png.png',sizingMethod='scale'); width:307px; height:34px;}
.iePng {filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(src='images/screenshot.png',sizingMethod='scale'); width:438px; height:230px;}
.ieHide {border:0 solid #fff; _display:none;}
#ieBg {border:0;}

You can check its working demo from the following URL, Check top left logo in all browsers its transparent PNG, you can save it and check its transparency
http://expertsdesk.net/novotech/
Reblog this post [with Zemanta]