What you want to see on DotNetFunda.com ?
Go to DotNetFunda.com
Twitter TwitterLinkedIn
YouTubeGoogle
 Online : 5166 |  Welcome, Guest!   Register  Login
Home > Articles > CSS > External Style Sheet

External Style Sheet

Article posted by Chikul on 1/23/2010 | Views: 4058 | Category: CSS | Level: Beginner red flag


External style sheets have many powerful that make them ubiquitous in professional Web sites:

It keeps your website design and content separate.
It's much easier to reuse your CSS code if you have it in a separate file. Instead of typing the same CSS code on every web page you have, simply have many pages refer to a single CSS file with the "link" tag.
You can make drastic changes to your web pages with just a few changes in a single CSS file.
It allows a single style sheet to control the rendering of multiple documents.
This results in a time-savings for the author, a savings of space for the web server, and less download time for the user.
This method can be used in both HTML and XML.

Introduction :

In Application When using CSS it is preferable to keep the CSS separate from your HTML.
Placing CSS in a separate file allows the web designer to completely differentiate between content (HTML) and design(CSS).

An External Style Sheet is a file containing only CSS syntax and should carry a MIME type of "text/css."
It is saved with a ".css" filename extensions that file is then referenced in your HTML using the <link> instead of <style>.
By using the Link Tag to load a basic external style sheet (CSS), it's possible to control the look n feel of multiply WebPages by making changes to One style sheet.
This means that it is easy to change font, bgcolor, background, etc on ALL pages - just by changing one external style sheet (CSS).

Those CSS files define page attributes for every page to which they are linked.
The style information is not explicitly tied directly to the document's elements, so Selector syntax is used to specify what styles attach to which portions of the document tree.
The full range of CSS syntax is allowed in this method.
Example with codes :

The 'link' is always added to the Head Section i.e anywhere between the <head> and the </head>
<link rel="stylesheet" type="text/css" href="style.css">

Just create a text (ASCII) file named (test.css) that contains the code shown below.
Put the style.css file in the same folder / directory as the file .

Let us create an external CSS file. Open up notepad.exe, or any other plain text editor and type the following CSS code.
CSS Code:
body 
{
background-color: #FFFFF0;
font-family: Arial, Verdana, sans-serif;
font-size: 18px;
color: #00008B;
}

a
{
font-family: Arial, Verdana, sans-serif;
font-size: 18px;
color: Blue;
text-decoration: underline
}

a:hover
{
font-family: Arial, Verdana, sans-serif;
font-size: 18px;
color: Red;
background-color: Green
}

h1 { font-family: Arial, Verdana, sans-serif; font-size: 32px; color: blue }

table
{
font-family: Arial, Verdana, sans-serif;
font-size: 18px;
color: #00008B;
margin-top: 0px;
margin-right: 0px;
margin-bottom: 0px;
margin-left: 0px;
padding-top: 0px;
padding-right: 0px;
padding-bottom: 0px;
padding-left: 0px;
}
Now save the file as a CSS (test.css) file.
Now create a new HTML file and fill it with the following code.
HTML Code:
<html>
<head runat="server">
<title>Style Page</title>
<link rel="stylesheet" type="text/css" href="test.css" />
</head>
<body>
<h1> A Blue Header </h1>
<table>
<tr>
<td>
<a href="Download/Mama0147.jpg">Image</a>
</td>
</tr>
</table>
</body>
</html>

Then save this file as "Sample.html" (without the quotes) in the same directory as your CSS file.

Now open your HTML file in your web browser and it should look something like this..

Display:

A Blue Header

Image link in Blue Colour. then on Mouse hover it will be red colur with green background because we changed it with CSS!
Advantages :
External style sheets have many powerful that make them ubiquitous in professional Web sites:
  • It keeps your website design and content separate.
  • It's much easier to reuse your CSS code if you have it in a separate file. Instead of typing the same CSS code on every web page you have, simply have many pages refer to a single CSS file with the "link" tag.
  • You can make drastic changes to your web pages with just a few changes in a single CSS file.
  • It allows a single style sheet to control the rendering of multiple documents.This results in a time-savings for the author, a savings of space for the web server, and less download time for the user.
  • This method can be used in both HTML and XML.

If you like this article, subscribe to our RSS Feed. You can also subscribe via email to our Interview Questions, Codes and Forums section.

Page copy protected against web site content infringement by Copyscape
Found interesting? Add this to:



Please Sign In to vote for this post.

Experience:1 year(s)
Home page:http://knowledgeparlour.blogspot.com/
Member since:Friday, November 20, 2009
Level:Bronze
Status: [Member]
Biography:
>> Write Response - Respond to this post and get points
Related Posts

You must have came across some .css issues related with the browser behavior. Some of the styles that works in IE doesn't work in FireFox. In that situation you need to write conditional code for both browsers.

In this article we are going to learn, how to use transition, text-shadow and border-radius in CSS3.

In this article we are going to learn how to use Rotating, Skew and Multiple background images in CSS3.

This article describe how to write common css code to change the look and feel of html elements.

Here i am going to teach you a very nice and cool css effect. Creating circles with css. Is it that amazing. I have tested it in mozilla firefox and chrome browsers. and it works fine.

More ...
About Us | Contact Us | The Team | Advertise | Software Development | Write for us | Testimonials | Privacy Policy | Terms of Use | Link Exchange | Members | Go Top
General Notice: If you find plagiarised (copied) contents on this page, please let us know the original source along with your correct email id (to communicate) for further action.
Copyright © DotNetFunda.Com. All Rights Reserved. Copying or mimicking the site design and layout is prohibited. Logos, company names used here if any are only for reference purposes and they may be respective owner's right or trademarks. | 5/22/2013 10:17:52 AM