Academic Tutorials



English | French | Portugese | German | Italian
Home Advertise Payments Recommended Websites Interview Questions FAQs
News Source Codes E-Books Downloads Jobs Web Hosting
Chats

CSS 2.0
CSS 2.0 Introduction
CSS 2.0 Attaching Style
CSS 2.0 Applying Style
CSS 2.0 Key Concepts
CSS 2.0 Color Contents
CSS 2.0 Fonts Contents
CSS 2.0 Text
CSS 2.0 Lists
CSS 2.0 the box model
CSS 2.0 Advanced concepts
CSS 2.0 Positioning
CSS 2.0 Boxes
CSS 2.0 Generated content
CSS 2.0 Dynamic effects
CSS 2.0 Tables
CSS 2.0 Paged media
CSS 2.0 Font Face
CSS 2.0 Aural Style Sheets
CSS 2.0 Language styles

HTML Tutorials
HTML Tutorial
XHTML Tutorial
CSS Tutorial
TCP/IP Tutorial
CSS 1.0
CSS 2.0
HLML
XML Tutorials
XML Tutorial
XSL Tutorial
XSLT Tutorial
DTD Tutorial
Schema Tutorial
XForms Tutorial
XSL-FO Tutorial
XML DOM Tutorial
XLink Tutorial
XQuery Tutorial
XPath Tutorial
XPointer Tutorial
RDF Tutorial
SOAP Tutorial
WSDL Tutorial
RSS Tutorial
WAP Tutorial
Web Services Tutorial
Browser Scripting
JavaScript Tutorial
VBScript Tutorial
DHTML Tutorial
HTML DOM Tutorial
WMLScript Tutorial
E4X Tutorial
Server Scripting
ASP Tutorial
PERL Tutorial
SQL Tutorial
ADO Tutorial
CVS
Python
Apple Script
PL/SQL Tutorial
SQL Server
PHP
.NET (dotnet)
Microsoft.Net
ASP.Net
.Net Mobile
C# : C Sharp
ADO.NET
VB.NET
VC++
Multimedia
SVG Tutorial
Flash Tutorial
Media Tutorial
SMIL Tutorial
Photoshop Tutorial
Gimp Tutorial
Matlab
Gnuplot Programming
GIF Animation Tutorial
Scientific Visualization Tutorial
Graphics
Web Building
Web Browsers
Web Hosting
W3C Tutorial
Web Building
Web Quality
Web Semantic
Web Careers
Weblogic Tutorial
SEO
Web Site Hosting
Domain Name
Java Tutorials
Java Tutorial
JSP Tutorial
Servlets Tutorial
Struts Tutorial
EJB Tutorial
JMS Tutorial
JMX Tutorial
Eclipse
J2ME
JBOSS
Programming Langauges
C Tutorial
C++ Tutorial
Visual Basic Tutorial
Data Structures Using C
Cobol
Assembly Language
Mainframe
Forth Programming
Lisp Programming
Pascal
Delphi
Fortran
OOPs
Data Warehousing
CGI Programming
Emacs Tutorial
Gnome
ILU
Soft Skills
Communication Skills
Time Management
Project Management
Team Work
Leadership Skills
Corporate Communication
Negotiation Skills
Database Tutorials
Oracle
MySQL
Operating System
BSD
Symbian
Unix
Internet
IP-Masquerading
IPC
MIDI
Software Testing
Testing
Firewalls
SAP Module
ERP
ABAP
Business Warehousing
SAP Basis
Material Management
Sales & Distribution
Human Resource
Netweaver
Customer Relationship Management
Production and Planning
Networking Programming
Corba Tutorial
Networking Tutorial
Microsoft Office
Microsoft Word
Microsoft Outlook
Microsoft PowerPoint
Microsoft Publisher
Microsoft Excel
Microsoft Front Page
Microsoft InfoPath
Microsoft Access
Accounting
Financial Accounting
Managerial Accounting
Network Sites


Attaching style to pages Contents


Previoushome Next






Attaching style to pages Contents

A D V E R T I S E M E N T

 




Introduction

There are three basic ways of declaring style data. The first is in the <HEAD> of pages, the second is at tag level and the third is in a separate external style sheet.

In each case, style sheets do not contain any HTML, just style commands. For example:

P {color: red}

is a style statement.




External style sheets

Linked style sheets

Style sheets are linked using the <LINK rel="stylesheet" type="text/css" href="name.css"> tag, which must go in the header of a page.

The tag's various attributes indicate things about the style sheet - the rel attribute, the type of link (a style sheet); the type attribute, the type of style sheet (always text/css); and the href attribute, the location of the style sheet.

Example

<HTML>
  <HEAD>
    <LINK rel="stylesheet" type="text/css" href="fluorescent.css">
  </HEAD>
  <BODY>
    ...
  </BODY>
</HTML>

Once you have linked the style sheet to your page, you then have to create the style sheet. For example:

BODY {color: black;
font-family: Geneva, Helvetica, Arial, sans-serif;
background-color: white}

If you saved the example above as a style sheet, then every page that links to it will have the specified styles.

Linked style sheets are advantageous insofar as one style sheet can be attached to hundreds of files. Thus they are the only way to go if you want consistency of style, and indeed in my opinion they are the only way to go anyway. Their only disadvantage is that if a page is downloaded and read offline, the user is unlikely to bother to save the style sheet. The main reason for using them is that you can attach the same sheet to many files ensuring consistency and reducing file sizes.

Importing style sheets

Say you have standard corporate margins in corestyles.css:

BODY {margin-left: 0.5in;
margin-right: 0.3in}

However, you have different color schemes:.

@import url(corestyles.css);
BODY {color: red;
background-color: black}

The @import rule thus allows you to keep some things the same while having others different; and follows this syntax: @import url(nameoffile.css);. It must come at the start of the style sheet, before any rulesets (a ruleset is something like P {color: red}).

Alternatively it can be specified as @import "nameoffile.css";, as @import url("nameoffile.css"); or as @import 'nameoffile.css';. However, Internet Explorer only supports the url() formats, not the " and ' formats.

There are esssentially three reasons for using @import:

  1. If you are writing for XML and your documents include right-to-left text (such as Hebrew), you are responsible for setting your own bidi, and to do this it is better to have a standard bidi style sheet:

    @import url(bidi.css);

    That way there is no chance of accidentally changing the bidi settings, and you can control the bidi of many style sheets.

  2. You might have a standard style sheet that specifies the appearance of P elements, Heading elements and so on for the whole of a large site, but also areas that are specific to a small section of the site. That way, rather than copying out the whole style sheet, you can just import it. This helps in that it allows caching, which reduces the load on your server, and also means that when you make a change to the style sheet you only have to change one, rather than changing one and updating all the others.
  3. You can modularize your style sheets; for example, you can have a margins module and a colors module. That way you can combine them without redundancy. For example:

    @import url(margins3.css);
    @import url(fonts1.css);
    @import url(colors2.css);

    could be the style sheet, using the fonts sheet 1, the margins sheet 3 and the colors sheet 2.




Embedded style sheets

Embedded style sheets are enclosed in a <STYLE type="text/css"> and </STYLE> tag. They go in the header of a page:

<HTML>
  <HEAD>
    <STYLE type="text/css">
      <!--
        BODY {color: red}
      -->
    </STYLE>
  </HEAD>
  <BODY>
    ...
  </BODY>
</HTML>

Note the <!-- and --> tags. These are the HTML comment tags, and are unnecessary for browsers that do support style sheets, but are essential for those that do not to avoid the unsightly problem of the style sheet appearing on the screen. This affects about 4% of all browsers.

They have two benefits over linked style sheets:

  1. They do not affect all the rest of the style sheets that you might use
  2. If a document is saved and read offline, the style will be maintained - users might not save linked style sheets.



Inline style

Any tag except the <HTML> tag itself can take the style attribute:

<P style="color: green">
</P>

Inside the style attribute comes style declarations. In this example, the P element is being made green.

The most important difference between inline (tag-level) style and other styles is that by applying the style to an individual element, you have selected the element unambiguously, and therefore inline style does not use selectors. Thus with the example above, there is no need for a selector, whereas if you were making the element green in a LINKed or embedded style sheet, you would need to have P {color: green}.

In my opinion, inline style should be avoided, since it does not indicate why you have changed the style. Thus if you gave the paragraph above a name that indicates its content, you could easily change it. The means of doing this is discussed in the next section.




Overview so far

The bare HTML & CSS document should look like this:

<HTML>
  <HEAD>
    <LINK rel="stylesheet" type="text/css" href="filename.css">
  </HEAD>
  <BODY>
    ...
  </BODY>
</HTML>

And the CSS document looks like this:

...




Getting started

At this stage you should be able to create your own style sheet. Most probably you will do this by adding a <LINK rel="stylesheet" href="nameoffile.css" type="text/css"> tag to the HEAD of your pages. Then you will creating the file 'style.css'. Try creating one now - you should have got the idea how to specify that something should be red or green or whatever - P {color: red} or BODY {font-size: 16px}. When you've played around a bit, the next section deals with how styles are specified as applying to individual elements, etc.

 



Be the first one to comment on this page.




  CSS 2.0 eBooks
More Links » »
 
 CSS 2.0 FAQs
More Links » »
 
 CSS 2.0 Interview Questions
More Links » »
 
 CSS 2.0 Articles

No CSS 2.0 Articles could be found as of now.

 
 CSS 2.0 News

No News on CSS 2.0 could be found as of now.

 
 CSS 2.0 Jobs

No CSS 2.0 Articles could be found as of now.


Share And Enjoy:These icons link to social bookmarking sites where readers can share and discover new web pages.
  • blinkbits
  • BlinkList
  • blogmarks
  • co.mments
  • connotea
  • del.icio.us
  • De.lirio.us
  • digg
  • Fark
  • feedmelinks
  • Furl
  • LinkaGoGo
  • Ma.gnolia
  • NewsVine
  • Netvouz
  • RawSugar
  • Reddit
  • scuttle
  • Shadows
  • Simpy
  • Smarking
  • Spurl
  • TailRank
  • Wists
  • YahooMyWeb

Previoushome Next

Keywords: Attaching style to pages Contents, CSS2, css2, CSS2 tutorial, CSS2 tutorial pdf, history of CSS2, Custamizing Style Sheet, learn CSS2

HTML Quizzes
HTML Quiz
XHTML Quiz
CSS Quiz
TCP/IP Quiz
CSS 1.0 Quiz
CSS 2.0 Quiz
HLML Quiz
XML Quizzes
XML Quiz
XSL Quiz
XSLT Quiz
DTD Quiz
Schema Quiz
XForms Quiz
XSL-FO Quiz
XML DOM Quiz
XLink Quiz
XQuery Quiz
XPath Quiz
XPointer Quiz
RDF Quiz
SOAP Quiz
WSDL Quiz
RSS Quiz
WAP Quiz
Web Services Quiz
Browser Scripting Quizzes
JavaScript Quiz
VBScript Quiz
DHTML Quiz
HTML DOM Quiz
WMLScript Quiz
E4X Quiz
Server Scripting Quizzes
ASP Quiz
PERL Quiz
SQL Quiz
ADO Quiz
CVS Quiz
Python Quiz
Apple Script Quiz
PL/SQL Quiz
SQL Server Quiz
PHP Quiz
.NET (dotnet) Quizzes
Microsoft.Net Quiz
ASP.Net Quiz
.Net Mobile Quiz
C# : C Sharp Quiz
ADO.NET Quiz
VB.NET Quiz
VC++ Quiz
Multimedia Quizzes
SVG Quiz
Flash Quiz
Media Quiz
SMIL Quiz
Photoshop Quiz
Gimp Quiz
Matlab Quiz
Gnuplot Programming Quiz
GIF Animation Quiz
Scientific Visualization Quiz
Graphics Quiz
Web Building Quizzes
Web Browsers Quiz
Web Hosting Quiz
W3C Quiz
Web Building Quiz
Web Quality Quiz
Web Semantic Quiz
Web Careers Quiz
Weblogic Quiz
SEO Quiz
Web Site Hosting Quiz
Domain Name Quiz
Java Quizzes
Java Quiz
JSP Quiz
Servlets Quiz
Struts Quiz
EJB Quiz
JMS Quiz
JMX Quiz
Eclipse Quiz
J2ME Quiz
JBOSS Quiz
Programming Langauges Quizzes
C Quiz
C++ Quiz
Visual Basic Quiz
Data Structures Using C Quiz
Cobol Quiz
Assembly Language Quiz
Mainframe Quiz
Forth Programming Quiz
Lisp Programming Quiz
Pascal Quiz
Delphi Quiz
Fortran Quiz
OOPs Quiz
Data Warehousing Quiz
CGI Programming Quiz
Emacs Quiz
Gnome Quiz
ILU Quiz
Soft Skills Quizzes
Communication Skills Quiz
Time Management Quiz
Project Management Quiz
Team Work Quiz
Leadership Skills Quiz
Corporate Communication Quiz
Negotiation Skills Quiz
Database Quizzes
Oracle Quiz
MySQL Quiz
Operating System Quizzes
BSD Quiz
Symbian Quiz
Unix Quiz
Internet Quiz
IP-Masquerading Quiz
IPC Quiz
MIDI Quiz
Software Testing Quizzes
Testing Quiz
Firewalls Quiz
SAP Module Quizzes
ERP Quiz
ABAP Quiz
Business Warehousing Quiz
SAP Basis Quiz
Material Management Quiz
Sales & Distribution Quiz
Human Resource Quiz
Netweaver Quiz
Customer Relationship Management Quiz
Production and Planning Quiz
Networking Programming Quizzes
Corba Quiz
Networking Quiz
Microsoft Office Quizzes
Microsoft Word Quiz
Microsoft Outlook Quiz
Microsoft PowerPoint Quiz
Microsoft Publisher Quiz
Microsoft Excel Quiz
Microsoft Front Page Quiz
Microsoft InfoPath Quiz
Microsoft Access Quiz
Accounting Quizzes
Financial Accounting Quiz
Managerial Accounting Quiz
Testimonials | Contact Us | Link to Us | Site Map
Copyright 2008. Academic Tutorials.com. All rights reserved Privacy Policies | About Us
Our Portals : Academic Tutorials | Best eBooksworld | Beyond Stats | City Details | Interview Questions | Discussions World | Excellent Mobiles | Free Bangalore | Give Me The Code | Gog Logo | Indian Free Ads | Jobs Assist | New Interview Questions | One Stop FAQs | One Stop GATE | One Stop GRE | One Stop IAS | One Stop MBA | One Stop SAP | One Stop Testing | Webhosting in India | Dedicated Server in India | Sirf Dosti | Source Codes World | Tasty Food | Tech Archive | Testing Interview Questions | Tests World | The Galz | Top Masala | Vyom | Vyom eBooks | Vyom International | Vyom Links | Vyoms | Vyom World
Copyright 2003-2017 Vyom Technosoft Pvt. Ltd., All Rights Reserved.