static
This is the normal positioning scheme in which
elements are positioned as they occur in the normal
document flow.
relative
– Relative positioning moves the box relative to its
original position in the flow.
– The distinctive behavior of relative positioning is that
the space the element would have occupied in the
normal flow is preserved as an empty space.
absolute
– Absolutely positioned elements are removed from the
document flow entirely and positioned with respect to
the browser window or a containing element.
fixed
– The distinguishing characteristic of fixed positioning is
that the element stays in one position in the window
even when the document scrolls.
– Fixed elements are removed from the document flow
and positioned relative to the browser window (or other
viewport) rather than another element in the document.
Specifying position
– Once you’ve established the positioning method,
the actual position is specified with four offset
properties.
* top, bottom, left, right
Relative Positioning– Example:
em{
position: relative;
top: 30px;
left: 60px;
background-color: fuchsia;
}
Absolute Positioning
Example:
em{
position: absolute;
top: 30px;
left: 60px;
background-color: fuchsia;
}
Fixed
div.fixed {
position: fixed;
top: 0;
left: 0;
width: 300px;
border: 3px solid #73AD21;
}
Use the font-family property to specify a font or list of fonts
Generic font families– serif
Examples: Times, Times New Roman, Georgia
Generic font families– sans-serif
Examples: Arial, Arial Black, Verdana, Trebuchet MS, Helvetica,
Geneva
Generic font families– monospace
Examples: Courier, Courier New, and Andale Mono
More Selector Types
– Element selector
* p { color: navy; }
– Grouped selectors
* p, ul, p, td, th { color: navy; }
Descendant selectors
– A descendant selector targets elements that are contained
within (and therefore are descendants of) another element.
– Descendant selectors are indicated in a list separated by a
character space.
– Example:
* li em{ color: olive; }
* h1 em, h2 em, h3 em { color: red; }
Child selector
– A child selector is similar to a descendant selector,
but it targets only the direct children of a given
element. There may be no other hierarchical levels
in between.
– They are indicated with the greater-than symbol (>).
The following rule affects emphasized text, but only
when it is directly contained in a p element. – An emelement inside a link (a) within the paragraph
would not be affected.
* p > em {font-weight: bold;}
Adjacent sibling selector
– An adjacent sibling selector targets an element
that comes directly after another element with
the same parent.
– It is indicated with a plus (+) sign.
– Other paragraphs are unaffected.
* div + p {font-style: italic;}
ID selectors
– ID selectors allow to target elements by their id
values. The symbol that identifies ID selectors is
known as a hash symbol.
ID selector example
<li>Happy Face T-shirt</li>
style{
li#catalog1234 { color: red; }
}
Class selectors
– Class names are indicated with a period (.) at the
beginning of the selector.
– To select all paragraphs (by <p> element) with
class=“special”, use this selector
* p.special { color: orange; }
– To apply a property to all elements of the same
class, omit the element name in the selector
* .special { color: orange; }
The Universal Selector
– Example
* * {color: gray; }
– It makes the foreground of every element in the document
gray.
* #intro * { color: gray; }
– It selects all elements in an “intro” section