T6 CSS
T6 CSS
1
The good, the bad and the… ugly!
2
<p>
<font face="Arial">Shashdot.</font>
News for <b>everybody!!</b> You will <i>never</i>,
<u>EVER</u> be
<font size="+4" color="red">BORED</font> here!
</p> HTML
selector {
property: value;
property: value;
...
property: value;
} CSS
p {
font-family: sans-serif;
color: red;
} CSS
n A CSS file consists of one or more rules
n A selector specifies an HTML element(s) and then applies style properties to them
n a selector of * selects all elements
Attaching a CSS file <link>
5
<head>
...
<link href="filename" type="text/css" rel="stylesheet" />
...
</head> HTML
<head>
<style type="text/css">
p { font-family: sans-serif; color: red; }
h2 { background-color: yellow; }
</style>
</head>
HTML
n CSS
code can be embedded within the head of an
HTML page
Inline styles: the style attribute
7
HTML
This is a paragraph
output
p {
color: red;
background-color: yellow;
}
CSS
property description
color color of the element's text
color that will appear behind the
background-color
element
Specifying colors
9
p { color: red; }
h2 { color: rgb(128, 0, 196); }
h4 { color: #FF8800; }
CSS
n RGB codes: red, green, and blue values from 0 (none) to 255 (full)
n hex codes: RGB values in base-16 from 00 (0, none) to FF (255, full)
Grouping styles
10
p, h1, h2 {
color: green;
}
h2 {
background-color: yellow;
} CSS
/* This is a comment.
It can span many lines in the CSS file. */
p {
color: red; background-color: aqua;
} CSS
n The <!-- ... --> HTML comment style is also NOT supported in CSS
CSS properties for fonts
12
property description
font-family which font will be used
font-size how large the letters will be drawn
font-style used to enable/disable italic style
font-weight used to enable/disable bold style
p {
font-family: Georgia;
}
h2 {
font-family: "Courier New";
} CSS
p {
font-family: Garamond, "Times New Roman", serif;
} CSS
n If the first font is not found on the user's computer, the next is tried
n Placing a generic font name at the end of your font-family value, ensures that every computer
will use a valid font
font-size
15
p {
font-size: 24pt;
} CSS
n units: pixels (px) vs. point (pt) vs. m-size (em) 16px, 16pt, 1.16em
p {
font-size: 24pt;
} CSS
p {
font-weight: bold;
font-style: italic;
} CSS
property description
text-align alignment of text within its element
text-decoration decorations such as underlining
line-height,
word-spacing, gaps between the various portions of the text
letter-spacing
text-indent indents the first letter of each paragraph
text-align
19
UIB’s Quote
La Universitat de les Illes Balears, hereva de la Universitat Lul·liana
de Mallorca, fou creada l’any 1978; la primera de l’era democràtica.
Des d’aleshores, aquesta institució pública d’ensenyament superior
ha recorregut el camí que l’ha conduïda a nivells cada vegada més
n text-align
alts de qualitatcan be left,
acadèmica right, center,
i de responsabilitat social. or
justify
output
text-decoration
20
p {
text-decoration: underline;
} CSS
ol { list-style-type: lower-roman; }
CSS
n Possible values:
i. none : No marker
body {
font-size: 16px;
}
CSS
n Saves
you from manually applying a style to each
element
Cascading Style Sheets
23
This is a heading
A styled paragraph. Previous slides are available on the website.
property description
background-color color to fill background
background-image image to place in background
background-position placement of bg image within element
whether/how bg image should be
background-repeat
repeated
background-attachment whether bg image scrolls with page
shorthand to set all background
background
properties
background-image
28
body {
background-image: url("images/draft.jpg");
}
CSS
body {
background-image: url("images/draft.jpg");
background-repeat: repeat-x;
}
CSS
body {
background-image: url("images/draft.jpg");
background-repeat: no-repeat;
background-position: 370px 20px;
} CSS
n Browser will load that page and scroll to element with given
ID
CSS ID selectors
34
#mission {
font-style: italic;
font-family: "Garamond", "Century Gothic", serif;
} CSS
on the page
CSS class selectors
36
.special {
background-color: yellow;
font-weight: bold;
}
p.shout {
color: red;
font-family: cursive;
} CSS
Today only!
output
CSS class selectors
37
Today only!
output
CSS ID selectors
38
<div class="shout">
<h2>Coding Horror! Coding Horror!</h2>
<p class="special">See our special deal on Droids!</p>
<p>We'll beat any advertised price!</p>
</div> HTML
selector1 selector2 {
properties
} CSS
<div id="ad">
<p>Eat at <strong>Greasy's Burger</strong>...</p>
<ul>
<li class="important">The <strong>greasiest</strong>
burgers in town!</li>
<li>Yummy and <strong>greasy at the same time
</strong>!</li>
</ul>
</div> HTML
#ad li.important strong { text-decoration: underline; }
CSS
Eat at Greasy’s Burger…
This is a heading.
output
property description
thickness/style/size of border on
border
all 4 sides
An h2 heading
output
property description
how wide or tall to make this
width, height element
(block elements only)
max-width, max-height, max/min size of this element in
min-width, min-height given dimension
CSS properties for margins
63
property description
margin margin on all 4 sides
margin-bottom margin on bottom side only
margin-left margin on left side only
margin-right margin on right side only
margin-top margin on top side only
Complete list of margin properties
http://www.w3schools.com/css/css_reference.asp#mar
gin
CSS properties for dimensions
66
An h2 heading
output
property description
how wide or tall to make this
width, height element
(block elements only)
max-width, max-height, max/min size of this element in
min-width, min-height given dimension