Introduction To Cascading Style Sheets


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> <br/><br/><style> <br/><br/>h1 <br/><br/>{ <br/><br/>color: #636594; <br/><br/>font-family: Verdana; <br/><br/>size: 18pt; <br/><br/>}<br/><br/></style> <br/><br/></head> <br/><body> <br/><br/>This is one big H1 tag! <br/></body> <br/></html> <br/><br/>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.<br/><br/>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. <br/><br/>Notice, though, that before the <head> tag is closed, we have<br/>our <style> tag, its contents, and then the closing </style> tag.<br/><br/><style> <br/><br/>h1 <br/><br/>{ <br/><br/>color: #636594; <br/><br/>font-family: Verdana; <br/><br/>size: 18pt; <br/><br/>} <br/></style> <br/><br/>When you add the style sheet code inline (as part of the HTML<br/>document), it must be bound by <style> and </style> tags<br/>respectively. Our example is working with the tag. We are<br/>changing three attributes of the ’s style: the text color<br/>(color), the font that any tags on the page will be<br/>displayed in (font-family), and lastly, the size of the font<br/>(size). <br/><br/>The code between the { and } are known as the attributes. Our<br/>sample code has three. Try changing the hexadecimal value of<br/>the color attribute to #A00808 and then save and refresh the<br/>page. You should see the same text, just coloured red instead<br/>of blue.<br/><br/>An example of an external style sheet<br/><br/>External style sheets are similar to internal style sheets,<br/>however, they are stripped of the <style> and </style> tags,<br/>and need to be referenced from another HTML file to be used. <br/><br/>Create a new file called “mystyle.css” and enter the following<br/>code into it:<br/><br/>h1 <br/>{ <br/><br/>color: #a00808; <br/><br/>font-family: Verdana; <br/><br/>size: 18pt <br/>} <br/><br/>Next, create a HTML file and name it external.html. Enter the<br/>following code into external.html:<br/><br/><html> <br/><br/><head> <br/><br/><title> External Style Sheet Reference Example < itle> <br/><br/><link rel"stylesheet" type"text/css" href"mystyle.css"> <br/><br/></head> <br/><br/><body> <br/><br/>This is one big H1 tag! <br/><br/></body> <br/></html> <br/><br/>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.<br/>The type”text/css” attribute tells the browser that mystyle.css<br/>is a text file containing css (cascading style sheet)<br/>declarations. Lastly, the href”mystyle.css” attribute tells<br/>the browser that the actual file we want to load is mystyle.css. <br/><br/>Conclusion<br/><br/>Well, there you have it, a quick look at style sheets and how<br/>to 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! <br/><br/>- 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<br/>- http://jigsaw.w3.org/css-validator/<br/><br/><p> About the Author <p>Mitchell is the founder and senior editor of<br/>http://www.devarticles.com. DevArticles provides its readers<br/>with top quality ASP, PHP and.NET articles, interviews and<br/>product reviews. If you're looking for insider tips and tricks,<br/>you'll also find them at DevArticles. You can visit DevArticles<br/>by clicking on this link: http://www.devarticles.com.<br/><br/></div><div class="panel panel-default" style="padding: 10px 10px 10px 10px;"><a class="btn btn-outline-primary btn-sm" href="/on/development/">development</a> <a class="btn btn-outline-primary btn-sm" href="/on/style/">style</a> <a class="btn btn-outline-primary btn-sm" href="/on/sheets/">sheets</a> <a class="btn btn-outline-primary btn-sm" href="/on/file/">file</a> <a class="btn btn-outline-primary btn-sm" href="/on/sheet/">sheet</a> <a class="btn btn-outline-primary btn-sm" href="/on/code/">code</a> <a class="btn btn-outline-primary btn-sm" href="/on/cascading/">cascading</a> </div> </div> </div> <!-- /#page-content-wrapper --> </div> <!-- /#wrapper --> <footer class="footer"> <div class="container-fluid text-right"> <p class="text-muted"><i class="fa fa-copyright" aria-hidden="true"></i> <a href="http://ondapc.com/" target="_blank">ondapc</a> project 2024</p> </div> </footer> <!-- CONTACT US --> <div class="modal" id="contact"> <div class="modal-dialog"> <div class="modal-content"> <div class="modal-header"> <h4 class="modal-title"><i class="far fa-envelope"></i> Contact Me</h4> <button type="button" class="close" data-dismiss="modal"><i class="fa fa-times"></i></button> </div> <div class="modal-body"> <form id="contactar" name="contactar" method="post"> <input type="hidden" name="token" value="0f83b1a020207f39b769ed9fd1745124"> <input type="hidden" name="captcha" value=""> <div class="form-group"> <div class="input-group-prepend"> <span class="input-group-text"><i class="fas fa-user"></i></span> <input class="form-control" id="name" name="name" placeholder="Your Name" required="required" value="" type="text"> </div> </div> <div class="form-group"> <div class="input-group-prepend"> <span class="input-group-text"><i class="far fa-envelope"></i></span> <input class="form-control" id="email" name="email" placeholder="Email" required="required" value="" type="email"> </div> </div> <div class="form-group"> <div class="input-group-prepend"> <span class="input-group-text"><i class="fas fa-edit"></i></span> <textarea name="message" id="message" class="form-control" rows="9" cols="25" placeholder="Write a message" required="required"></textarea> </div> </div> </div> <div class="modal-footer"> <button type="submit" class="btn btn-primary">Send <i class="fas fa-chevron-right"></i></button> </div> </div> </div> </div> <div id="contact" class="modal fade" role="dialog"> <div class="modal-dialog"> <div class="modal-content"> <div class="modal-header"> <button type="button" class="close" data-dismiss="modal"><i class="fa fa-times"></i></button> <h4 class="modal-title"><i class="fa fa-envelope-o"></i> Contact Me</h4> </div> <div class="modal-body"> </div> </div> </div> <script> $(function(){ $('#contactar').on('submit', function(e){ e.preventDefault(); $.ajax({ url: '/contactx/', type: 'POST', data: $('#contactar').serialize(), success: function(data){ $('#contactar')[0].reset(); $("#contact-success").append('<span><i class="fa fa-check"></i> Message Sent!</span>'); } }); }); }); </script> <!-- Bootstrap core JavaScript --> <script src="vendor/jquery/jquery.min.js"></script> <script src="vendor/bootstrap/js/bootstrap.bundle.min.js"></script> <!-- Menu Toggle Script --> <script> $("#menu-toggle").click(function(e) { e.preventDefault(); $("#wrapper").toggleClass("toggled"); }); </script> </body> </html> <!-- CACHE 05a476c5032690da7b7f71c5f2208041 2024-11-26 05:07:44 -->