Home About Feedback Advertise The Lab Sitemap

Google Adsense Pepperjam Network Adbrite Text Link Ads Bidvertiser Kontera
More...


Posts Tagged ‘CSS’

Cascading Stylesheets Advantages: 5 Reasons To Use CSS

Tuesday, August 26th, 2008

1. The content is separated from the design

Because you are able to create a separate Stylesheet and link it to all your webdocuments, you have great control over how your website looks. So if you want to change a certain aspect of your page, you only need to alter one file: your Stylesheet!

This Of course, generates some great flexibility. This flexibility is not available when your website is using tables for layout, inline font tags or inline defined colors.

A single CSS file can contain positioning, layout, font, colors and style information for an entire web site.

2. You site uses less bandwidth and loads faster

Because stylesheets are so lightweight, your website will load much faster. The main reason is because you do not need table layouts anymore for the positioning of elements. Since text loads really really fast your website will be visible in a flash.

This means that visitors will be happier when surfing your website. They only have to download the Stylesheet once, and it’s automatically reused for every page. So the only thing that needs to be loaded is the actual content.

On average a website will load five to ten times faster if it makes use of cascading style sheets.

3. Your website will automatically gain better search engine results

With CSS, you can position any element, anywhere you want. So if your menu is at the bottom of your HTML document, you can bring it up using absolute positioning. The reason this is useful is to make sure the search engine spiders pick up the main content first.

Another advantage you automatically gain is that your HTML code is much cleaner. So the search engine spider will not have to separate the junk code from the real content.

So make sure you put your logo text and your menu at the bottom of your HTML document at put it at the top using CSS!

4. CSS is compatible with newer browsers

Because more and more browsers are used other than Internet Explorer on a Windows machine, you need to be sure that your website is accessible by all major and newer browsers.

By using webstandards, defined by the w3c, you are making sure your content is viewable in the future.

Because there are so many browsers these days, it is impossible to test your website in all these browsers on different configurations. Coding to standards is then the only practical solution.

5. CSS can be used to display the same content on different media.

Because you are able to define different stylesheets for different media you have great flexibility in presenting your content.

The printer for example, is a medium on itself. If someone prints out your website, you will be able to modify the look of it. Add an extra black and white logo, remove the advertisements and change the colors to black and white values. It’s all done easily by using cascading stylesheets. And the best thing is, visitors do not even have to know you created a new Stylesheet especially for the printer.

Stylesheets can also be created specifically for PDA’s and such. As you will understand, this adds some great flexibility to the presentation of your web document.

Conclusion

Cascading Style Sheets are created to make things easier. It gives you great control of your website and makes your visitors happy when they are surfing your website.

You are prepared for the future and will gain better search engine results automatically. Start using CSS to its full potential today! It will suit you well.

How do I prevent people from ‘leeching’ my CSS or JS files?

Tuesday, August 26th, 2008

I’ve heard a few people complain that external sites have linked to their CSS or JS files, which is both a waste of bandwidth and a potential copyright violation. Unfortunately, there is no straightforward way to prevent this from happening, and have fun trying to pursue it legally — I was an expert witness in an Internet-related trial a few years ago, and it’s amazing how much crap a lawyer can get away with it simply because the judge has no technical savvy whatsoever. 
 
In any case, there are ways to prevent people from borrowing these file types, and it’s very similar to the method described in Article #2276, used to protect images from being swiped. 
 
The basic concept is that you serve up the CSS or JS from ASP, and the ASP page checks the referer to make sure it’s on the same domain. So, for example, you can do this: 
 

<SCRIPT LANGUAGE=javascript SRC=js.asp></SCRIPT> 
<LINK REL=Stylesheet HREF=css.asp></SCRIPT>

 
Where js.asp may have the following code: 
 

<% 
    ref = lcase(request.serverVariables(”HTTP_REFERER”)) 
    if instr(ref,”localhost”)>0 then 
        response.write “document.write(’HELLO’);” 
    end if 
%> 

 
And css.asp might look like this: 
 

<% 
    ref = lcase(request.serverVariables(”HTTP_REFERER”)) 
    if instr(ref,”localhost”)>0 then 
        response.write “body { font-size:72pt }” 
    end if 
%> 

 
As with the images solution, note that this will be a bigger performance hit… and may affect how JS / CSS files are cached.

CSS has its share of inconsistencies as well

Tuesday, August 26th, 2008

CSS may at times be misused, particularly by the author of web documents. Some developers who are accustomed to designing documents strictly in HTML may overlook or ignore the enabling features of CSS. For instance, a document author who is comfortable with HTML markup that mixes presentation with structure may opt to use strictly embedded CSS styles in all documents. While this may be an improvement over using deprecated HTML presentational markup, it suffers from some of the same problems that mixed-markup HTML does; specifically, it entails a similar amount of document maintenance.

 

Discrepancies compared: CSS vs programming languages

 

CSS also shares some pitfalls common with programming languages. In particular, the problem of choosing appropriate names for CSS classes and identifiers may afflict CSS authors. In the attempt to choose descriptive names for CSS classes, authors might associate the class name with desired presentational attributes; for example, a CSS class to be applied to emphasized text might be named “bigred,” implying that it is rendered in a large red font.

 

While such a choice of naming may be intuitive to the document author, it can cause problems if the author later decides that the emphasized text should instead be green; the author is left with a CSS class called “bigred” that describes something that is green. In this instance, a more appropriate class name might have been “emphasized,” to better describe the purpose or intent of the class, rather than the appearance of elements of that class.

 

In a programming language, such a misuse might be analogous to using a variable name “five” for a variable which contains the value 5; however, if the value of the variable changes to 7, the name is no longer appropriate.

 

CSS in a nutshell

 

CSS is used by both the authors and readers of web pages to define colors, fonts, layout, and other aspects of document presentation. It is designed primarily to enable the separation of document structure (written in HTML or a similar markup language) from document presentation (written in CSS).

 

This separation provides a number of benefits, including improved content accessibility, greater flexibility and control in the specification of presentational characteristics, and reduced complexity of the structural content. CSS is also capable of controlling the document’s style separately in alternative rendering methods, such as on-screen in print, by voice (when read out by a speech-based browser or screen reader) and on braille based, tactile devices.

 

CSS allows complete and total control over the style of a hypertext document. The only way this can be illustrated in a way that gets people excited is by demonstrating what it can truly be, once the reins are placed in the hands of those able to create beauty from structure.

What you need to know about CSS!

Tuesday, August 26th, 2008

Style sheet is a progressive breakthrough for the advancement of web. Today, more and more browsers are implementing style sheets, opening authors’ eyes to unique features that allow influence over presentation while preserving platform independence. The advantages of style sheets have become - apparent — and the disadvantage of continually creating more HTML tags — galore — for presentation effects with the gradual development of CSS.

 

Let’s understand CSS in the right perspective.

 

Style sheets in retrospect

 

Style sheets have been around in one form or another since the beginnings of HTML in the early 1990s.

 

As the HTML language grew, however, it came to encompass a wider variety of stylistic capabilities to meet the demands of web developers . With such capabilities, style sheets became less important, and an external language for the purposes of defining style attributes was not widely accepted until the development of CSS.

 

Teething problems with implementation of CSS

 

Many implementations of CSS are fraught with inconsistencies, bugs and other Authors have commonly had to use hacks and workarounds in order to obtain consistent results across web browsers and platforms.

 

One of the most well-known CSS bugs is the Internet Explorer box model bug; box widths are interpreted incorrectly in several versions of the browser, resulting in blocks which appear as expected in most browsers, but are too narrow when viewed in Internet Explorer. The bug can be avoided, but not without some cost in terms of functionality.

 

This is just one of hundreds of CSS bugs that have been documented in various versions of Internet Explorer,Netscape Mozilla , and Opera, many of which reduce the legibility of documents. The proliferation of such bugs in CSS implementations has made it difficult for designers to achieve a consistent appearance across platforms.

 

Currently there is strong competition between Mozilla’s Gecko layout engine, Opera’s Presto layout engine, and the KHTML engine used in both Apple’s Safari and the Linux Konqueror browsers - each of them is leading in different aspects of CSS. Internet Explorer remains the worst at rendering CSS by standards set down by World Wide Web Consortium as of 2005.

 

Some breakthroughs .

 

These problems have preisely led the W3C to revise the CSS2 standard into CSS2.1, which may be regarded as something of a working snapshot of current CSS support. CSS2 properties which no browser had successfully implemented were dropped, and in a few cases, defined behaviours were changed to bring the standard into line with the predominant existing implementations..

 

What makes style sheets significant enough?

 

Style sheet represents an enormous step forward for the Web. With the separation of content and presentation between HTML and style sheets, the Web no longer needs to drift away from the strong ideal of platform independence that provided the medium with its initial push of popularity. Authors can finally influence the presentation of documents without leaving pages unreadable to users

 

A style sheet is made up of style rules that tell a browser how to present a document. There are various ways of linking these style rules to your HTML documents, but the simplest method for starting out is to use HTML’s STYLE element. This element is placed in the document HEAD, and it contains the style rules for the page.

 

Functionality and Usage of CSS

 

CSS is well-designed to allow the separation of presentation and structure. Prior to CSS, nearly all of the presentational attributes of an HTML document were contained within the HTML code; all font colors, background styles, element alignments, borders and sizes had to be explicitly described, often repeatedly, in the midst of the HTML code.

 

CSS allows authors to move much of that information to a stylesheet, resulting in considerably simpler HTML code. The HTML documents become much smaller and web browsers will usually cache sites’ CSS stylesheets. This leads to a reduction in network traffic and noticeably quicker page downloads.

 

For example, the HTML element h2 specifies that the text contained within it is a level two heading. It has a lower level of importance than h1 headings, but a higher level of importance than h3 headings. This aspect of the h2 element is structural .

 

Customarily, headings are rendered in decreasing order of size, with h1 as the largest, because larger headings are usually interpreted to have greater importance than smaller ones. Headings are also typically rendered in a bold font in order to give them additional emphasis. The h2 element may be rendered in bold face, and in a font larger than h3 but smaller than h1 . This aspect of the h2 element is presentational .

 

Prior to CSS, document authors who wanted to assign a specific color, font, size, or other characteristic to all h2 headings had to use the HTML font element for each occurrence of that heading type.

 

Moreover, CSS can be used with XML, to allow such structured documents to be rendered with full stylistic control over layout, typography, color, and so forth in any suitable user agent or web browser.

Why your site should be developed with CSS and semantic markup

Tuesday, August 26th, 2008

One thing that I have learned in over a decade developing web sites is that the Net is continually changing, and to keep up you need to change with it. One of the more recent developments in web design is the use of CSS and semantic markup. CSS and semantic web design has several benefits: clarity in code, browser and other web-enabled devices compatibility, seperation of content and
presentation, smaller burden on bandwith, and better visibility to search engines.

Back in the day, we designed sites with tables and hacked those tables into doing things that they were never meant to do. The table tag was designed to display tabular data, not as a way to render the layout of a website. Unfortunately, a better alternative did not exist, so we used tables. This made for inefficient, slow loading sites with code that was very hard to read and maintain. Wikipedia defines sematic markup like this:

 

Sematic pages: supply information for Web search engines using web crawlers. This could be machine-readable information about the human-readable content of the document (such as the creator, title, description, etc., of the document) or it could be purely metadata representing a set of facts (such as resources and services elsewhere in the site). (Note that anything that can be identified with a Uniform Resource Identifier (URI) can be described, so the semantic web can reason about people, places, ideas, cats etc.)

These days, hip designers and developers use CSS extensively to create beautiful, fully standards compliant sites. CSS-based layout allows us to develop sites that will degrade effectively–that is that they will be viewable on all types of devices such as PDAs, cell phones, T.V.s–and will work correctly on devices that dont even exist yet as long as they are standards compliant.

Most importantly, developing sites with CSS allows us to effectively separate content and presentation. Have you ever looked at the source code of HTML pages that were created with a table-based layout and wondered what the heck is going on here? You see lots of opening and closing of tables and table rows all mixed together with textual content and graphics. With a clean, CSS-based layout you can create pages that are easily understood by looking at the source, making them easier to understand, maintain, and update. Look at the source of my company site http://www.vp3media.com and then look at the source code of this site that uses a tables based layout: http://webservices.org/. Big difference, huh?

If you have a site with high traffic, you can significantly reduce the amount of bandwdth used by transitioning from a table-based site to a CSS-based layout. If a visitor to your site doesnt have to load all of the code needed to render those tables and spacer gifs, you are transmiting less data.

CSS also offers search engine optimization benefits over tables. If you have a tables based business site that relys on Internet traffic to turn a profit or aquire new clients you will see real advantages by switching to CSS. When a search engine spiders your tables-based site, they retrieve a large amount of content that has nothing to do with you business. When search engines spiders a clean CSS-based site, the majority of content retrieved will be textual content that describes your business. The ratio of content-to-code is higher with CSS-based layouts.

Weve all seen search engine descriptions that dont make any sense; thats because search engine spiders use a top down method for retrieving information. Whatever is topmost in your document, the search engines are going to think is the most important part of the document, and therefore should be used as the description. Since we seperate content and presentation with CSS, we can put the most important information at the top of a document no matter where it is actually displayed on the page. Try that with tables!

I hope this article gives you an overview of why it is important to transition from your current tables-based layout to a fully valid CSS implementation. If you dont have a web site, but are planning on launching one in the near future, make sure you tell your developers you want a CSS-based implementation.