Friday, August 29, 2014

The Bits that Make Up a Style Sheet

RULES

A style sheet can be broken down into progressively smaller bits. From large to small, those pieces are:
➤ Style sheet
➤ Rule
➤ Selector
➤ Declaration
➤ Property
➤ Value

SELECTORS

In CSS, a selector is the HTML element or elements to which a CSS rule is applied. Put simply, the selector tells the browser what to style

Grouping Selectors

When more than one selector appears in the same rule, they are said to be grouped

DECLARATIONS

Declarations are enclosed within curly braces ({}) to separate them from selectors.
A declaration is composed of a property name, a colon, and, depending on the property, one or more values.

A Declaration is    property : value(s)

body <-----------------   selector
{
       width: 650px;  <---------------- declaration
       margin: 0 auto;
       background: #000;
       color: #FFF;
       font: 12px sans-serif;
}

Values in a declaration

Keyword: A keyword value is a named value
Eg. red, green, and blue, bold, left, auto etc.

Strings:
One use of strings in CSS is to specify a font that contains spaces in its name

font-family: ‘Times New Roman’, Times, serif;

Length and Measurement

There are two kinds of lengths used in CSS:

absolute
UNIT ABBREVIATION                                   DESCRIPTION
in                                                                             Inches
cm                                                                          Centimeters
mm                                                                          Millimeters
pt                                                                            Points, 1 point is equal to 1/72nd of an inch
pc                                                                           Picas, 1 pica is equal to 12 points

relative
UNIT ABBREVIATION                                    DESCRIPTION
em                                                           Length relevant to the nearest font size.
ex                                                           The x-height of the relevant font (height of the letter x).
px                                                           Pixels, relative to the viewing device, for example, a computer monitor.
%                                                            Percentage measurement; how percentage length is calculated depends on what property it is being applied to.

Including CSS in a Document

using embedded style sheets, which are included between <style> and </style> tags directly in an HTML document

<style type=”text/css”>
      body {
              font: 12px sans-serif;
               }
</ style >

CSS can be included in its own document and linked to an HTML document

<link rel=”stylesheet” type=”text/css” href=”example_1-1.css”>

CSS can be imported from within either an embedded or linked style sheet by using an @import rule.

<style type=”text/css”>
       @import url(example_1-1.css);
</ style >

CSS declarations can be applied directly to an element in an HTML document by using inline styles with the style attribute
<body style=”font: 12px sans-serif;”>





No comments:

Post a Comment