w3reference home
CSS Tutorial


Bookmark and Share

CSS Syntax

The CSS syntax consists of three parts namely, selector, property and value. The syntax is as follows:
selector {property : value }
Let's discuss this syntax. The selector is a tag to which you would like to give to a particular style. Property is the attribute that has to be associated with the style. The value that each property has to take is specified in value.
Look at the curly braces and the colon. The selector is followed by a curly brace which encloses property and value. The property and the value are separated by a colon. Let's see a simple example:
<HTML>
<HEAD>
<style type="text/css">
b {color:blue}
</style>
</HEAD>
<BODY>
<b>This is a bold text having blue color.</b>
</BODY>
</HTML>
The output of the above HTML document will be:
This is a bold text having blue color.
This was a very simple example to demonstrate the use of CSS. In this example, the HTML tag, b is the selector. The text between the tag b will have the color blue apart from being bold. CSS is hardly ever used in such a simple manner. There are many different variations of using this CSS syntax. We will see those variations now.

Suppose, you want to specify more than one property in a selector. This can be done by separating them by a semicolon. Following example will illustrate this:

<HTML>
<HEAD>
<style type="text/css">
b {color:blue; font-family:arial}
</style>
</HEAD>
<BODY>
<b>This is a bold text having blue color & font arial.</b>
</BODY>
</HTML>
The output of the above code will be:
This is a bold text having blue color & font arial.
Here, we have specified two properties to the element, b. We have changed the color to blue and the font to arial. Now suppose, the font was sans serif instead of arial. In this case, when the value contains more than one word, it should be enclosed within double quotes. See the example given below:
<HTML>
<HEAD>
<style type="text/css">
b {color:blue; font-family:"sans serif"}
</style>
</HEAD>
<BODY>
<b>This is a bold text having blue color & font sans serif.</b>
</BODY>
</HTML>
The output will be:
This is a bold text having blue color & font sans serif.
Another way to define a CSS is as follows:
b
{
color:blue;
font-family:"sans serif"
}
Code Validator
Learn FTP
Color finder
Link Checker
Free web designs
Coming soon!
Interview Questions...
'w3reference : Learn by examples ... Advanced to beginner's tutorials ...'
Ajax: AJAX tutorial1 | Apache: Apache HTTP Server | Restarting Apache | CSS: CSS Border | CSS Syntax | CSS Selector | CSS Comment | CVS: CVS Release | CVS Login | CVS Logout | CVS Annotate | Databases: Rolap Tutorial | OLAP Tutorial | OLTP Tutorial | data warehousing | Expect: HTML: html | Linux: Dot (.) conf files | Linux Mount Point | Linux Filesystem | SSH Tutorial | Linux Commands: cal | cat | cfdisk | chroot | MySQL: MySQL Commands | PHP: PHP Basics | PHP Variables | PHP Output (echo/print) | PHP String Concat | PL/SQL: PL/SQL Data Types | PL/SQL Control Structures | PL/SQL File Extensions | PL/SQL DBMS_OUTPUT package | Python: My first Python program | Shell: Starting Bash | Bash Redirection | Bash Pipes | Bash Variables | SQL: SQL Transactions | SQL Constraints | SQL Drop | SQL Union & Union All | SVN: svn architecture | SVN Repository | SVN Import | SVN Checkout | Tech: soap | Web Designing: Web Hosting | HTML/XHTML/CSS code validator | Learn FTP | Search Engine Optimization Tips | www: XML: XML vs HTML | XML Syntax | XML Tags, Elements and Attributes | XML Namespaces |
Sitemap | Disclaim | Privacy Policy | Contact | ©2007-2009 w3reference.com All Rights Reserved.