What is CSS?
CSS is the acronym for: ‘Cascading Style Sheets’. CSS is an extension to basic HTML that allows you to style your web pages. An example of a style change would be to make words bold. In standard HTML you would use the tag like so:
make me bold
This works fine and there is nothing wrong with it per se, except that now if you wanted to, say, change all your text that you initially made bold to underlined, you would have to go to every spot in every page and change the tag.
Another disadvantage can be found in this example: say you wanted to make the above text bold, make the font style Verdana and change its color to red you would need a lot of code wrapped around the text:
This is text
This is verbose (wordy) and contributes to making your HTML messy. With CSS you can create a custom style elsewhere and set all its properties, give it a unique name and then ‘tag’ your HTML to apply these stylistic properties:
My CSS styled text
And in between the < head> tags at the top of your web page you would insert this CSS code that defines the style we just applied:
In the above example we include the style sheet code inline, or in other words, in the page. This is fine for smaller projects or in situations where the styles you're defining will only be used in a single page. There are many times when you will be applying your styles to many pages and it would be a hassle to have to copy and paste you CSS code into each page. Besides, the fact that you will be cluttering up each page with the same CSS code, you also find yourself having to edit each of these pages if you want to make a style change. Like with JavaScript, you can define/create your CSS style in a separate file and then link it to the page you want to apply the code to:
< link href="myFirstStyleSheet.css" rel="stylesheet" type="text/css">
The above line of code links your external style sheet called ‘myFirstStyleSheet.css’ to the HTML document. You place this code in between the tags in your web page.
To create an external style sheet all you need to do is create a simple text document (on Windows you simply right-click and select new -> text document) and then change it from a file type .txt to .css. You can change the file type by just changing the file names extension. The file name’s extension on Windows tells the computer what kind of file it is and allows the computer to determine how to handle the file when, for example, you try to open it.
You probably guessed it; CSS files are just specially (specifically) formatted text files much in the same way that HTML pages are. There is nothing special or different about the file itself, rather it is the contents of the file that makes a CSS document a CSS document.
When working with an external CSS document there are a couple of points to remember:
1. You DON'T add these tags in the CSS document/page itself as you would if you embedded the CSS code in your HTML:
Since the link in your web page connecting the CSS page to your HTML page says that you are linking to a CSS page, you don’t need to declare that the code in the page is CSS. That is what the above tags do. Instead you would just add your CSS code directly to the page:
.myNewStyle {
font-family: Verdana, Arial, Helvetica, sans-serif;
font-weight: bold;
color: #FF0000;
}
.my2ndNewStyle {
font-family: Verdana, Arial, Helvetica, sans-serif;
font-weight: bold;
color: #FF0000;
}
.my3rdNewStyle {
font-family: Verdana, Arial, Helvetica, sans-serif;
font-weight: bold;
font-size: 12pt;
color: #FF0000;
}
In the above example I have created a series of CSS classes that can be applied to any HTML tag like so:
My CSS styled text
or
My CSS styled text
You will notice that in the above example I applied a CSS style to an
nice post i am looking for software development company malaysia, can any one help me
ReplyDeleteya ..wat kind of help u r seeking..
ReplyDelete