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