color
property<style>
element within the
<head>
element of a document
<head> <style type="text/css"> h1 { background: yellow; color: purple; } </style> ... </head>
type
attribute defines the type of style
being included (strictly the MIME type)text/css
h1
is called the selectorbackground
and color
are propertiesyellow
and purple
are valuesh1
headings will have purple text on a yellow background:
<link>
element within the
<head>
element of a documentnotes.html
files for this module
contain the following
<head> ... <link rel="stylesheet" href="../notes.css" type="text/css" /> ... </head>
rel
attribute specifies the relationship
between the document and the file referred to, i.e.,
notes.css
in the parent directorystyle
tags)h1, h2, h3, h4, h5, h6 { background: yellow; color: purple; text-align: center; }
ol li { list-style: decimal; } ol ol li { list-style: lower-alpha; } ol ol ol li { list-style: lower-roman; }
em { color: red; } ul em { color: blue; }
ul em
, the em
element can occur as a descendant of the ul
elementclass
and id
attributesclass
and id
attributediv
and
span
elements of (X)HTML for styling purposesid
attribute is meant to be unique within a document<p class="red">A red paragraph</p> <p class="green">A green paragraph</p> <p id="p123">A yellow paragraph</p>may have the following style rules applied
.red { color: red; } .green { color: green; } #p123 { color: yellow; }where
.
is the class selector and
#
is the id selector
p.red { color: red; } p.green { color: green; }
pre span.keyword, code span.keyword { color: red; }
span
elementclass
attribute value of keyword
pre
or code
elementpre
element is:
<pre> pre span.keyword, code span.keyword { color: <span class="keyword">red</span>; } </pre>
Selector | Example | Selects ... |
---|---|---|
.class |
.keyword |
all elements with class="keyword" |
#id |
#123 |
the element with id="123" |
* |
* |
all elements |
element |
p |
all p elements |
element, element |
div, p |
all div elements and all p elements |
element element |
div p |
all p elements inside div elements |
element > element |
div > p |
all p elements whose parent is a div element |
element ~ element |
p ~ ul |
all ul elements having a p element as a preceding sibling |
[attribute] |
[style] |
all elements with a style attribute |
[attribute = value] |
[type="text/javascript"] |
all elements with type="text/javascript" |
[attribute ^= value] |
a[href ^= "http"] |
all a elements whose href attribute value begins with "http" |
[attribute $= value] |
a[href $= ".pdf"] |
all a elements whose href attribute value ends with ".pdf" |
[attribute *= value] |
a[href *= "bbk"] |
all a elements whose href attribute value contains "bbk" |
Property | Some values | Meaning |
---|---|---|
font-size |
large , 24px |
px is pixels, also cm , ... |
font-family |
arial , serif , sans-serif |
specific like arial , or generic like serif |
font-style |
normal , italic |
|
font-weight |
normal , bold |
|
display |
block , inline |
|
margin-top |
1cm , 2em |
em is the size of the letter m |
line-height |
normal , 2 |
2 is twice the current font size |
text-decoration |
underline , line-through |
|
list-style-type |
circle , lower-alpha |
circle for ul , lower-alpha for ol |
www.w3.org/Style/CSS/Overview.en.html
en.wikipedia.org/wiki/Cascading_Style_Sheets
www.w3schools.com/css/