Web Design Stuff
HTML Tutorials    CSS Tutorials    Web Hosting   Resources
Create a Web Page 101
Making Web Pages Intro What is a Web Page? Why Make a Web Page? The History of HTML Learn HTML or XHTML?
Basic HTML
Basic HTML Tutorials Basic HTML Necessities How to Make a Web Page How to Edit a Web Page The Basics of HTML Tags Basic HTML Page Structure HTML Attributes
HTML Font Codes
HTML Font Codes Intro HTML Font Color Codes HTML Font Size Codes HTML Font Style Codes HTML Bold/Italic Codes Combining Font Codes
Formatting Text
Formatting Text Intro Making Paragraphs Miscellaneous Formatting Headings & Subheadings Creating Hyperlinks
Using Graphics
Using Graphics on the Web Add Graphics to Your Pages Graphics and Accessibility How to Align Graphics Page Color & Background Graphics as Hyperlinks Horizontal Rules
Creating Tables
HTML Tables Tutorials HTML Table Fundamentals Background & Border Color Table Frames & Rules Table Width and Alignment Cells 1 -Space & Alignment Cells 2 -Row Column Span Cells 3 -Width & Height
Making Lists
HTML Lists Tutorials Bulleted Lists Numbered Lists Definition Lists
HTML Frames
HTML Frames Tutorials Using Frames for Layout Advanced Frame Layouts Putting Hyperlinks in Frames Frame Border Width Color, Margin and Control Problems with Frames SmartFrames: A Solution SSI: An Alternative to Frames
Web Page Forms
Making Feedback Forms A Simple Feedback Form Installing NMS FormMail Debugging Your Setup My Web Host is Out to Lunch User Input Components Text Fields Checkboxes & Radio Buttons Dropdown Menus Push Buttons Layout and Presentation
Basic CSS
Basic CSS Tutorials What is CSS? Why You Should Use CSS How to Use CSS Inline Styles Embedded Style Sheets External Style Sheets Class Selectors ID Selectors Combining Selectors
CSS Properties
CSS Properties Intro Font Styles Width, Height & Spacing Borders Backgrounds Position Float & Alignment Hyperlinks
All About Web Hosting
Hosting Your Own Website What is a Web Host? Your Website's Home Page Building a Website Offline About Free Web Hosting Best Free Web Hosting Commercial Web Hosting How to Get a Domain Name Ecommerce Web Hosting Web Hosting Terminology
Free Web Design Tools
Best Free Website Tools Best Free Text Editors Best Free Graphics Editors Free Website Analysis Tools
Setting Up HTML Kit
HTML Kit Introduction How to install HTML Kit Screenshot Breakdown Basic Configuration Overall Appearance Shortcuts and Startup Editing Window Customizing Toolbars Using the Favorites Tab Making a New Actions Bar Odds and Ends
Free Templates
Free Website Templates Two Column Fixed Width Three Column Liquid Layout Miscellaneous Templates Dynamic Menu Effects Two Column Experimental Terms of Use About These Templates
Website Templates Help
Getting Started Template Zip File Download How to Edit Your Template What to Edit in the HTML How to Add Your Logo Making a Website
Web Design Tips
Web Design Basics Tables vs. Tableless Using Tables for Layout Example Table Layouts World's Crappiest Web Page
Twitter Backgrounds
Twitter Backgrounds Intro Cool Twitter Backgrounds Cool Twitter Backgrounds 2 Plain Twitter Backgrounds Dark Twitter Backgrounds Best Twitter Backgrounds Cute Twitter Backgrounds Music Twitter Backgrounds Music Twitter Backgrounds 2 Twitter Backgrounds 101 TERMS OF USE
All About Web Browsers
What is a Web Browser? Mozilla Firefox Internet Explorer Opera How to Set Up Firefox Top 5 Firefox Extensions
 
Contact
Post Some Feedback Send Me An Email Iron Spider Blog About Iron Spider... Site Conventions
 
 
 

 

Embedded Style Sheets

 
Using embedded style sheets will allow you to begin unleashing the full power of CSS by enabling you to apply styles to all HTML elements of a particular type on an entire web page. Whereas an inline style will only allow you to address one HTML element at a time, an embedded style sheet will allow you to address multiple HTML elements at once. This is accomplished by using the style element and a list of CSS rule sets.

The style Element


The style element requires both start and end tags <style>...</style> which are inserted between the <head>...</head> tags (a.k.a., document head) of your web page. The type attribute defines the type of style sheet being used so we'll put text/css as the value. The entire contents of the style element should be wrapped in HTML comment tags to hide it from browsers not compatible with CSS.

Here's an example of an essential web page structure with the style element properly inserted in the document head:


Example 1 - THE style ELEMENT DISPLAYED IN THE DOCUMENT HEAD

<html>

<head>
<title></title>

<style type="text/css">
<!--
...CSS rule sets go here...
-->
</style>


</head>

<body>
...web page content...
</body>

</html>




CSS Rule Sets


Now all we have to do is define some CSS rule sets. These will associate a list of CSS properties with certain HTML elements on our web page. Here's the syntax you use to create a CSS rule set:

SELECTOR {property: value; property: value; property: value;}

In the above:
  1. SELECTOR refers to the targetted HTML element(s). You can simply insert the actual name of the HTML element you wish to target (known as a type selector) or you can be more specific by using class or id selectors.
  2. property refers to a CSS property.
  3. value refers to an associated CSS value.

Here's a few things to remember about CSS syntax in embedded style sheets:
  1. The list of property/value pairs (a.k.a., style declarations) are enclosed in a set of curly braces { }
  2. The property and its associated value are separated by a colon (:)
  3. Each property/value pair ends with a semi-colon (;)
  4. When using multiple word values in embedded style sheets, the multiple word string must be enclosed in either single or double quotation marks.

Here's an example of a web page document with a simple CSS rule set using a type selector. This will apply the color green to the text contained in all paragraph tags on the web page:


Example 2 - A CSS RULE SET TARGETS ALL PARAGRAPHS ON THE SAME PAGE

<html>

<head>
<title></title>

<style type="text/css">
<!--

p {color: green;}
-->
</style>


</head>

<body>

<p>...This text will be green...</p>
<p>...This text will be green...</p>
<p>...This text will be green...</p>

</body>

</html>




You may insert as many CSS rule sets as you like in the style element. When listing multiple CSS property/value pairs, many web authors (myself included) prefer to stack them one on top of the other and then indent the list to make it easier to read. This is perfectly fine since CSS code —like HTML— is designed to ignore extraneous white space.

Here's an example of this kind of formatting using multiple rule sets which themselves contain multiple property/value pairs:


Example 3 - EMBEDDED STYLE SHEET CSS RULE SETS (FORMATTED FOR EASY READING)

<style type="text/css">
<!--
H1 {
   font-family: 'Times New Roman';
   font-size: 36px;
   background: #ffffff;
   color: maroon;
}

H2 {
   font-family: arial,verdana,sans-serif;
   font-size: 20px;
   background: #ffffff;
   color: black;
}

P {
   font-family: arial,verdana,sans-serif;
   font-size: 16px;
   background: #ffffff;
   color: navy;
}
-->
</style>



Example 3 - EMBEDDED STYLE SHEET CSS RULE SETS (UNFORMATTED)

<style type="text/css">
<!--
H1 {font-family: 'Times New Roman'; font-size: 36px; background: #ffffff; color: maroon;}

H2 {font-family: arial,verdana,sans-serif; font-size: 20px; background: #ffffff; color: black;}

P {font-family: arial,verdana,sans-serif; font-size: 16px; background: #ffffff; color: navy;}
-->
</style>



 

Click here to view Example 3 applied to an actual web page...


NOTES:
  • When the above list of rule sets is inserted in the style element, it will apply the associated CSS properties to all H1, H2 and P elements on the web page. (Need to be more 'selective' with your selectors? Try using classes and IDs.)
  • The multi-word Times New Roman value must be enclosed in single (or double) quotation marks.
  • The value for the font-family property declared for the H2 and the P elements is a comma-separated list of fonts which will be applied in order from left to right according to the availability of the font on the user's computer. (This uses the same principle for applying a list of fonts using the font element in HTML. See Font Face for more information).
  • Type selectors (HTML element names) are case-insensitive.

*   *   *


Well then, that takes care of applying CSS to an entire web page. Let's turn it on full blast and learn how to apply CSS to multiple web pages at once using just one .css file. This is accomplished using external style sheets...


SEE ALSO:
  • What is CSS?
  • How to use CSS - An Overview
  • Inline styles
  • External Style Sheets
  • CSS Properties




Best Free Stuff
for webmasters

Free Text Editors
Free Graphics Editors
Website Analysis Tools
Free Website Templates

See also:

Best Free Web Hosting
How to Make a Web Page

 

If you need a .COM web address, you can get one quick and easy at...

www.GoDaddy.com
<~ BACK TOP NEXT ~>
 
HTML Tutorials |  CSS Tutorials |  Web Hosting |  Domain Names |  Web Design Resources
Iron Spider © Copyright 2004-2011 Robert Darrell