More CSS
More CSS
More CSS
<link href="filename"
type="text/css" rel="stylesheet"
/>
HTML id attribute
2
#mission {
font-style: italic;
font-family: "Garamond", "Century Gothic", serif;
} CSS
.special {
background-color: yellow;
font-weight: bold;
}
p.shout {
color: red;
font-family: cursive;
} CSS
Today only!
output
CSS class selectors
7
Today only!
output
CSS ID selectors
8
class description
:active an activated or selected element
an element that has the keyboard
:focus
focus
:hover an element that has the mouse over it
:link a link that has not been visited
:visited a link that has already been visited
the first letter of text inside an
:first-letter
element
:first-line the first line of text inside an element
an element that is the first one to
:first-child
appear inside another
10 Styling Page Sections
Why do we need page sections?
11
<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
applies the given properties to selector2 only if it is inside a
selector1 on the page
CSS
Eat at Greasy’s Burger…
<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…
Every element
composed of:
content
a border around the
element
padding between the
content and the border
a margin between the
border and other content
The CSS Box Model (cont.)
18
This is a heading.
output
property description
thickness/style/size of border on all 4
border
sides
property description
border-color, border-width, specific properties of border on all 4
border-style sides
border-bottom, border-left, all properties of border on a particular
border-right, border-top side
border-bottom-color, border-bottom-
style,
border-bottom-width, border-left-
color, properties of border on a particular
border-left-style, border-left-width, side
border-right-color, border-right-style,
border-right-width, border-top-color,
border-top-style, border-top-width
Complete list of border properties
http://www.w3schools.com/css/css_reference.asp#border
Another border example
24
h2 {
border-left: thick dotted #CC0088;
border-bottom-color: rgb(0, 128, 128);
border-bottom-style: double;
} CSS
This is a heading.
output
property description
padding padding on all 4 sides
padding-bottom padding on bottom side only
padding-left padding on left side only
padding-right padding on right side only
padding-top padding on top side only
Complete list of padding properties
http://www.w3schools.com/css/css_reference.asp#padding
Padding example 1
26
This is a heading
output
Padding example 2
27
p {
padding-left: 200px; padding-top: 30px;
background-color: fuchsia;
} CSS
output
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#margin
Margin example 1
29
p {
margin: 50px;
background-color: fuchsia;
} CSS
p {
margin-left: 8em;
background-color: fuchsia;
} CSS
An h2 heading
output
property description
how wide or tall to make this element
width, height
(block elements only)
max-width, max-height, max/min size of this element in given
min-width, min-height dimension
Centering a block element: auto
32
margins
p {
margin-left: auto;
margin-right: auto;
width: 750px;
} CSS
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod
tempor incididunt ut labore et dolore magna aliqua.
output