• Category Category: CSS
  • Comment Comments: 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
styles.

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>- http://www.devarticles.com/art/1/7 -<br /> http://hotwired.lycos.com/webmonkey/98/15/index0a.html -<br /> http://www.webreview.com/style/index.shtml -</p> <p>http://jigsaw.w3.org/css-validator/</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="http://www.addtoany.com/share_save"><img src="http://articles.org/wp-content/plugins/add-to-any/share_save_256_24.png" width="256" height="24" alt="Share"/></a></div> <script type="text/javascript"><!-- wpa2a.script_load(); //--></script> </div> <!-- end content --> <div class="tags_link"> <p class="tags_link_p"><strong>Tags</strong></p> </div> </div> <div class="box" style="border-bottom:none; background-color:#EEF3F8;"> <p> <img src="http://articles.org/wp-content/themes/article_directory/images/no_avatar.gif" 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="http://articles.org/53017_introduction_to_cascading_style_sheets/">http://articles.org/53017_introduction_to_cascading_style_sheets/</a><br/><strong>Author: </strong><a href="http://articles.org/author/admin/" title="Posts by admin" rel="author">admin</a><br/> </p> <div class="sub_icon"> <ul> <li> <img src="http://articles.org/wp-content/themes/article_directory/images/icon_author.png" alt="author"/><strong>By:</strong> <a href="http://articles.org/author/admin/" title="Posts by admin" rel="author">admin</a> </li> <li> <img src="http://articles.org/wp-content/themes/article_directory/images/icon_writte.gif" alt="writer"/><strong>Posted On:</strong> March 13, 2006 </li> <li> <strong> </strong> </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" style="border:1px #d0dbe4 solid;"> <div class="title" style="width:690px; height:34px; border-left:none; border-right:none; border-top:none;"> <h2 style="margin-top:8px;"> Post <span> Comment</span></h2> </div> <form id="commentform" action="http://articles.org/wp-comments-post.php" method="post"> <div class="box" id="comment-box"> <div class="comment-box-message" style="display: none"> <div> </div> </div> <div class="register"> <label><strong> Username:</strong> <span class="red">*</span> </label> <div style="float:left; width:400px;"> <div class="registerby"> <input id="comment-name" type="text" name="author" size="29px" value=""/> </div> </div> </div> <div class="clear"></div> <div class="register"> <label><strong> Email:</strong> <span class="red">*</span> </label> <div style="float:left; width:400px;"> <div class="registerby"> <input id="comment-email" type="text" name="email" size="29px" value=""/> </div> </div> </div> <div class="clear"></div> <div class="register"> <label><strong>Website:</strong></label> <div style="float:left; width:400px;"> <div class="registerby"> <input id="comment-url" type="text" name="url" size="29px" value="""/> </div> </div> </div> <div class="register"> <label><strong>Message:</strong> </label> <div style="float:left; width:400px;"> <div class="registerby2"> <textarea id="comment-content" rows="8" cols="30" name="comment"></textarea> </div> </div> </div> <div class="clear"></div> <div class="register"> <input style="margin-left:325px;" type="submit" name="submit" value="Post Comment" class="button" /> </div> </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="22d14974be" /></p> </form> </div> <!-- Recent Artcle --> <div class="col_boxgrey4" style="border:1px #d0dbe4 solid; 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" style="padding-bottom:15px;"> <h2>Related Searches</h2> </div> </div> Twitter Updates <div class="textwidget"><p><script src="http://widgets.twimg.com/j/2/widget.js"></script><br /> <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: '#ff5e00', color: '#000000' }, tweets: { background: '#ffffff', color: '#000000', links: '#ff5e00' } }, features: { scrollbar: false, loop: false, live: true, behavior: 'all' } }).render().start(); </script></p> </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 --> <!-- FOOTER --> <div id="footer"> <div class="footer_res"> <div class="footer_main"> <div class="fott_top"> <div class="fott"><h3>Our Newsletter<br /><span>Sign Up For The Latest News</span></h3><div class="search_box" style="width:285px; margin-left:15px; margin-bottom:15px;"><div class="box_input1"></div> <form action="http://feedburner.google.com/fb/a/mailverify" target="popupwindow" method="post" onsubmit="window.open('http://feedburner.google.com/fb/a/mailverify?uri=Articles.org', 'popupwindow', 'scrollbars=yes,width=550,height=520');return true"> <div class="box_input"> <input type="text" name="email" size="25px" value="Enter your e-mail" onfocus="if (this.value == 'Enter your e-mail') {this.value = '';}" onblur="if (this.value == '') {this.value = 'Enter your e-mail' ;}" /> </div> <div class="box_input2"></div> <div id="bottom-search-butt" class="butt"> <input id="bottom-search-button" type="submit" value="Ok" class="button" size="" /> </div> <input value="Articles.org" name="uri" type="hidden"/> <input value="en_US" name="loc" type="hidden"/> </form> </div><p>Sign up our free newsletter. Articles Organization is a free and shared article directory. The registration and the membership on the website are free. You can submit your articles and promote your business. </p></div><div class="fott"><h3>Socialize!<br /><span>Follow Us</span></h3><p> It is a long established fact that a reader will be distracted by the readable content of a page when looking at its layout.</p><div class="icon"><a href="http://twitter.com/articlesorg"><img src="http://articles.org/wp-content/themes/article_directory/images/icon_t.png" alt=""/></a><a href="http://www.facebook.com/pages/Articles-Organization/140232106038330"><img src="http://articles.org/wp-content/themes/article_directory/images/icon_f.png" alt=""/></a><a href="http://feeds.feedburner.com/Articles-FreeArticleDirectory-Articlesorg"><img src="http://articles.org/wp-content/themes/article_directory/images/icon_rss.png" alt=""/></a><a href="http://www.addthis.com/bookmark.php?v=250&username=orifastlich"><img src="http://articles.org/wp-content/themes/article_directory/images/icon_share.png" alt=""/></a></div></div> </div> <div class="fott_top" 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/'>Contact Us</a> </div> <div class="fott_bottom"> <div class="logo_small"> <img src="http://articles.org/wp-content/themes/article_directory/images/logo_small.png" alt="logo"/> </div> <div class="copyright"> <p> <br/><span>Copyright © 2010 Article Directory Powered by WordPress</span> </p> <center><h1>Articles.Org - Add Article to the free articles directory</h1></center> </div> </div> </div> </div> </div> <script type="text/javascript"><!-- wpa2a.targets=[ {title:'Introduction To Cascading Style Sheets',url:'http://articles.org/53017_introduction_to_cascading_style_sheets/'}]; wpa2a.html_done=true;if(wpa2a.script_ready&&!wpa2a.done)wpa2a.init();wpa2a.script_load(); //--></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: http://www.w3-edge.com/wordpress-plugins/ Page Caching using disk: enhanced Object Caching 322/333 objects using memcached Served from: articles.org @ 2012-11-01 04:03:34 -->