Report this Article

Introduction To Cascading Style Sheets

  • Posted March 13, 2006
  • by
  • in category CSS

  • Comments 0
  • Views 0

CSS (Cascading Style Sheets) have been around for a while now,
and act as a complement to plain old HTML files. Style sheets
allow a developer to separate HTML code from formatting rules
and styles. It seems like many HTML beginners’ under-estimate
the power and flexibility of the style sheet. In this article,
I’m going to describe what cascading style sheets are, their
benefits, and two ways to implement them.

————————————— Cascading whats?

Cascading Style Sheets…that’s what! They’re what paint is to
canvas, what topping is to ice cream… they complement HTML and
allow us to define the style (look and feel) for our entire site
in just one file!

Cascading style sheets were introduced to the web development
world way back in 1996. They get their name from the fact that
each different style declaration can be “cascaded” under the one
above it, forming a parent-child relationship between the

They were quickly standardized, and both Internet Explorer and
Netscape built their latest browser releases to match the CSS
standard (or, to match it as closely as they could).

So, you’re still asking what a style sheet exactly is? A style
sheet is a free-flowing document that can either be referenced
by, or included into a HTML document. Style sheets use blocks of
formatted code to define styles for existing HTML elements, or
new styles, called classes.

Style sheets can be used to change the height of some text, to
change the background color of a page, to set the default border
color of a table…the list goes on and on. Put simply though,
style sheets are used to set the formatting, color scheme and
style of an HTML page.

Style sheets should be used instead of the standard , ,
and tags because:

– One style sheet can be referenced from many pages, meaning
that each file is kept to a minimum size and only requires only
extra line to load the external style sheet file

– If you ever need to change any part of your sites look/feel,
it can be done quickly and only needs to be done in one place:
the style sheet.

– With cascading style sheets, there are many, many page
attributes that simply cannot be set without them: individual
tags can have different background colors, borders, indents,
shadows, etc.

Style sheets can either be inline (included as part of a HTML
document), or, referenced externally (Contained in a separate
file and referenced from the HTML document). Inline style sheets
are contained wholly within a HTML document and will only change
the look and layout of that HTML file.

Open your favorite text editor and enter the following code.
Save the file as stylesheet.html and open it in your browser:

Cascading Style Sheet Example < itle></p> <style> h1 { color: #636594; font-family: Verdana; size: 18pt; } </style> <p> </head> <body><br /> <h1>This is one big H1 tag!</h1> <p> </body><br /> </html> </p> <p>When you fire up your browser, you should see the text “This is<br /> one big H1 tag!” in a large, blue Verdana font face.</p> <p>Let’s step through the style code step by step. Firstly, we have<br /> a pretty standard HTML header. The page starts with the <html><br /> tag followed by the <head> tag. Next, we use a standard <title><br /> tag to set the title of the page we are working with. </p> <p>Notice, though, that before the <head> tag is closed, we have<br /> our<br /> <style> tag, its contents, and then the closing </style> <p> tag.</p> <style> h1 { color: #636594; font-family: Verdana; size: 18pt; } </style> <p>When you add the style sheet code inline (as part of the HTML<br /> document), it must be bound by<br /> <style> and </style> <p> tags<br /> respectively. Our example is working with the<br /> <h1> tag. We are<br /> changing three attributes of the<br /> <h1>‘s style: the text color<br /> (color), the font that any<br /> <h1> tags on the page will be<br /> displayed in (font-family), and lastly, the size of the font<br /> (size). </p> <p>The code between the { and } are known as the attributes. Our<br /> sample code has three. Try changing the hexadecimal value of the<br /> color attribute to #A00808 and then save and refresh the page.<br /> You should see the same text, just coloured red instead of blue.</p> <p>————————————— An example of an<br /> external style sheet —————————————</p> <p>External style sheets are similar to internal style sheets,<br /> however, they are stripped of the<br /> <style> and </style> <p> tags, and<br /> need to be referenced from another HTML file to be used. </p> <p>Create a new file called “mystyle.css” and enter the following<br /> code into it:</p> <p>h1 { color: #a00808; font-family: Verdana; size: 18pt } </p> <p>Next, create a HTML file and name it external.html. Enter the<br /> following code into external.html:</p> <p><html> <head> <title> External Style Sheet Reference Example <<br /> itle> <link rel="stylesheet" type="text/css" href="mystyle.css"> </head> <body><br /> <h1>This is one big H1 tag!</h1> <p> </body> </html> </p> <p>As mentioned above, you can see that the actual code in<br /> mystyle.css is exactly the same as it was in the inline example.<br /> In our HTML file, we simply place a <link> tag in the <head><br /> section of our page. The rel=”stylesheet” attribute tells the<br /> browser that the link to the external file is a style sheet. The<br /> type=”text/css” attribute tells the browser that mystyle.css is<br /> a text file containing css (cascading style sheet) declarations.<br /> Lastly, the href=”mystyle.css” attribute tells the browser that<br /> the actual file we want to load is mystyle.css. </p> <p>————————————— Conclusion<br /> —————————————</p> <p>Well, there you have it, a quick look at style sheets and how to<br /> implement both an inline and external version. Checkout the<br /> links below if you’ve never worked with cascading style sheets<br /> before. You will be surprised at some of the things you can do<br /> with them! </p> <p>- -<br /> -<br /> -</p> <p></p> <div class="addtoany_share_save_container"><div class="a2a_kit a2a_target addtoany_list" id="wpa2a_1"><a class="a2a_dd addtoany_share_save" href=""><img src="" width="256" height="24" alt="Share"/></a></div> <script type="text/javascript"><!-- wpa2a.script_load(); //--></script> </div> <!-- end content --> <div class="post_footer"> <div class="tags_link"> <img src="" alt=""/> <div class="tags_link_div" id="0"></div> </div> <script type="text/javascript"> processtags("0"); </script> </div> </div> <div class="box author"> <p> <img src="" alt="admin" style="float:left; display:inline; margin-right:10px; padding:1px; border:1px #b2b2b2 solid;width: 86px; height:86px" /> <strong>Article's Source: </strong><a href=""></a><br/><strong>Author: </strong><a href="" title="Posts by admin" rel="author">admin</a><br/> </p> <div class="sub_icon"> <br /> <ul> <li>Posted On March 13, 2006 </li> <li>Published articles 283513 </li> </ul> </div> </div> <!-- COMMENTS --> <div class="box" style="border-bottom:none; text-align:right;"> <div class="wp-pagenavi"> <p> </p> </div> </div> </div> <div class="col_boxgrey4"> <div class="title"> <h2>Post Comment</h2> </div> <form id="commentform" action="" method="post"> <div class="comment-box-message" style="display: none"> <div> </div> </div> <div class="register"> <label><strong> Username:</strong> <span class="red">*</span> </label> <div class="registerby"> <input id="comment-name" type="text" name="author" size="29px" value=""/> </div> </div> <div class="clear"></div> <div class="register"> <label><strong> Email:</strong> <span class="red">*</span> </label> <div class="registerby"> <input id="comment-email" type="text" name="email" size="29px" value=""/> </div> </div> <div class="clear"></div> <div class="register"> <label><strong>Website:</strong></label> <div class="registerby"> <input id="comment-url" type="text" name="url" size="29px" value="""/> </div> </div> <div class="register"> <label><strong>Message:</strong> </label> <div class="registerby2"> <textarea id="comment-content" rows="8" cols="30" name="comment"></textarea> </div> </div> <div class="clear"></div> <input type='hidden' name='comment_post_ID' value='53017' id='comment_post_ID' /> <input type='hidden' name='comment_parent' id='comment_parent' value='0' /> <p style="display: none;"><input type="hidden" id="akismet_comment_nonce" name="akismet_comment_nonce" value="305f2eaec8" /></p> <script type='text/javascript'> var RecaptchaOptions = { theme : 'red', lang : 'en' , tabindex : 5 }; </script><script type="text/javascript" src=""></script> <noscript> <iframe src="" height="300" width="500" frameborder="0"></iframe><br/> <textarea name="recaptcha_challenge_field" rows="3" cols="40"></textarea> <input type="hidden" name="recaptcha_response_field" value="manual_challenge"/> </noscript> <div id="recaptcha-submit-btn-area"> </div> <noscript> <style type='text/css'>#submit {display:none;}</style> <input name="submit" type="submit" id="submit-alt" tabindex="6" value="Submit Comment"/> </noscript> <div class="register register_button"> <input type="submit" name="submit" value="Post Comment" class="button" /> </div> </form> </div> <!-- Recent Artcle --> <div class="col_boxgrey4" style="display:none"> <div class="title" style="width:690px; height:34px; border-left:none; border-right:none; border-top:none;"> <h2 style="margin-top:8px;"> </h2> </div> <div class="box" style="border-bottom:none;"> <div class="col_boxgrey5"> <ul> </ul> </div> <!-- ADVERTISING --> <!-- END ADVERTISING --> </div> </div> </div> <!-- END BODY --> <!-- SIDEBAR --> <div class="col_right"> <div class="col_boxgrey2"><div class="box2"><h2><img src="" alt=""/>Top Categories</h2></div><ul class="popular-category-list"><li><a href="">Business <span>66846</span></a></li><li><a href="">Other <span>65880</span></a></li><li><a href="">Sports <span>47947</span></a></li><li><a href="">Health and Medical <span>43979</span></a></li><li><a href="">Uncategorized <span>28799</span></a></li><li><a href="">Internet Marketing <span>20695</span></a></li><li><a href="">Home-and-Garden <span>15338</span></a></li><li><a href="">Travel <span>14557</span></a></li><li><a href="">Finance <span>12273</span></a></li><li><a href="">Entertainment <span>12047</span></a></li></ul></div><div class="col_boxgrey2"> <div class="textwidget"><div> </div> <script src=""></script> <script> new TWTR.Widget({ version: 2, type: 'search', search: 'articlesorg', interval: 30000, title: 'The best of Twitter according to', subject: 'Articles.Org Article Directory', width: 'auto', height: 500, theme: { shell: { background: '#F1F1F1', color: '#000000' }, tweets: { background: '#ffffff', color: '#000000', links: '#F9951C' } }, features: { scrollbar: false, loop: false, live: true, behavior: 'all' } }).render().start(); </script></div> </div> </div> </div> </div> </div> <div style="clear:both;"></div> <script type="text/javascript"> function recent(){ document.getElementById('st1').style.display ="block"; document.getElementById('st2').style.display ="none"; } function viewed(){ document.getElementById('st2').style.display ="block"; document.getElementById('st1').style.display ="none"; } </script> <!-- END SIDEBAR -->  </div> <!--end wrapper--> <!-- FOOTER --> <div id="footer"> <div class="footer_res"> <!--<div class="fott_top footer_links" style='text-align:center'> <a href='/articles-about/'>About Us</a> | <a href='/terms-and-conditions/'>Terms and Conditions</a> | <a href='/privacy-policy/'>Privacy Policy</a> | <a href='/wp-content/themes/article_directory/new_contact.php'>Contact Us</a> </div>--> <div class="fott_top footer_links" style='text-align:center'> <a href='/articles-about/'>About Us</a> <a href='/terms-and-conditions/'>Terms and Conditions</a> <a href='/privacy-policy/'>Privacy Policy</a> <a href='/contact-us-2/'>Contact Us</a> </div> <div class="footer_main"> <div class="foot_right"> <div class="fott"><h3><span>Follow Us:</span></h3><div class="icon"><a href=""><img src="" alt=""/></a><a href=""><img src="" alt=""/></a><a href=""><img src="" alt=""/></a></div></div> </div> <div class="foot_left"> <div class="copyright"> <p> <span>Copyright © 2015 Article Directory Powered by WordPress</span> </p> </div> </div> </div> </div> </div> <script type="text/javascript"><!-- wpa2a.targets=[ {title:'Introduction To Cascading Style Sheets',url:''}]; wpa2a.html_done=true;if(wpa2a.script_ready&&!wpa2a.done)wpa2a.init();wpa2a.script_load(); //--></script> <script type="text/javascript"> var sub = document.getElementById('submit'); document.getElementById('recaptcha-submit-btn-area').appendChild (sub); document.getElementById('submit').tabIndex = 6; if ( typeof _recaptcha_wordpress_savedcomment != 'undefined') { document.getElementById('comment').value = _recaptcha_wordpress_savedcomment; } document.getElementById('recaptcha_table').style.direction = 'ltr'; </script> </body> </html> <script type="text/javascript"> jQuery(document).ready(function(){ jQuery('.comment-box-message').hide(); jQuery('#commentform').submit(function(){ if (jQuery.trim(jQuery('#comment-name').val()) == ''){ jQuery('.comment-box-message div').html("Name can't be empty"); jQuery('.comment-box-message').show(); return false; } if (jQuery.trim(jQuery('#comment-email').val()) == ''){ jQuery('.comment-box-message div').html("Email can't be empty"); jQuery('.comment-box-message').show(); return false; } if (!validateEmail(jQuery('#comment-email').val())){ jQuery('.comment-box-message div').html("Email is invalid"); jQuery('.comment-box-message').show(); return false; } if (jQuery.trim(jQuery('#comment-content').val()) == ''){ jQuery('.comment-box-message div').html("Comment content can't be empty"); jQuery('.comment-box-message').show(); return false; } jQuery('.comment-box-message').hide(); }); }); </script> <!-- Performance optimized by W3 Total Cache. Learn more: Served from: @ 2015-04-28 11:21:20 by W3 Total Cache -->