CSS

From 太極
Revision as of 17:29, 20 May 2014 by Brb (talk | contribs) (Created page with "The information is obtained from [http://www.w3schools.com/css/css_intro.asp w3schools.com]. = CSS = == Syntax == <pre> p { color:red; text-align:center; } </pre> where '''p'...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

The information is obtained from w3schools.com.

CSS

Syntax

p
{
color:red;
text-align:center;
}

where p is called selector and anything inside {} is declarations with a format of property:value.

Comments

A CSS comment starts with /* and ends with */. Comments can also span multiple lines

Selectors

  • element selector
p {  text-align:center;color:red; }
  • id selector
#para1  { text-align:center;color:red; }
  • class selector
.center { text-align:center;color:red; }

You can also specify that only specific HTML elements should be affected by a class.

p.center { text-align:center;color:red; }
  • group selectors
h1,h2,p { text-align:center;color:red; }

Three ways to insert CSS

  1. External style sheet
<head>
<link rel="stylesheet" type="text/css" href="mystyle.css">
</head>
  1. Internal style sheet
<head>
<style>
hr {color:sienna;}
p {margin-left:20px;}
body {background-image:url("images/background.gif");}
</style>
</head>
  1. Inline style sheet
<p style="color:sienna;margin-left:20px;">This is a paragraph.</p>