CSS Lecture - 08
CSS Lecture - 08
2
Shorthand Font Property
⬥font
⬥background-color
⬩ fixed / scroll
4
Backgrounds (2)
⬥background-position: specifies vertical and
horizontal position of the background image
⬩ Vertical position: top, center, bottom
⬩ Horizontal position: left, center, right
⬩ Both can be specified in percentage or other
numerical values
⬩ Examples:
background-position: top left;
is equal to writing:
background-color: #FFF0C0;
background-image: url("back.gif");
background-repeat: no-repeat;
background-attachment: fixed;
background-position: top;
7
Borders
⬥border-width: thin, medium, thick or
numerical value (e.g. 10px)
⬥border-color: color alias or RGB value
⬥border-style: none, hidden, dotted,
dashed, solid, double, groove, ridge,
inset, outset
⬥Each property can be defined separately for
left, top, bottom and right
⬩ border-top-style, border-left-color,
…
8
Border Shorthand Property
⬥border: shorthand rule for setting border
properties at once:
border: 1px solid red
is equal to writing:
border-width:1px;
border-color:red;
border-style:solid;
10
Margin and Padding
⬥margin and padding define the
spacing around the element
⬩ Numerical value, e.g. 10px or -5px
⬩ Can be defined for each of the four sides
separately - margin-top, padding-left, …
⬩ margin is the spacing outside of the border
⬩ padding is the spacing between the border
and the content
⬩ What are collapsing margins?
11
Margin and Padding: Short Rules
⬥margin: 5px;
⬩ Sets all four sides to have margin of 5 px;
⬥margin: 10px 20px;
⬩ top and bottom to 10px, left and right to 20px;
⬥margin: 5px 3px 8px;
⬩ top 5px, left/right 3px, bottom 8px
⬥margin: 1px 3px 5px 7px;
⬩ top, right, bottom, left (clockwise from top)
⬥Same for padding
12
The Box Model
13
IE Quirks Mode
⬥ When using quirks
mode (pages with no
DOCTYPE or with a
HTML 4 Transitional
DOCTYPE), Internet
Explorer violates the
box model standard
14
Positioning
⬥position: defines the positioning of the
element in the page content flow
⬥ The value is one of:
⬩ static (default)
⬩ relative – relative position according to
where the element would appear with static
position
⬩ absolute – position according to the
innermost positioned parent element
⬩ fixed – same as absolute, but ignores
page scrolling 15
Positioning (2)
⬥Margin VS relative positioning
⬥ Fixed and absolutelypositioned elements do
not influence the page normal flow and usually
stay on top of other elements
⬩ Their position and size is ignored when
calculating the size of parent element or
position of surrounding elements
⬩ Overlaid according to their z-index
⬩ Inline fixed or absolutely positioned elements
can apply height like block-level elements
16
Positioning (3)
left, bottom, right: specifies offset of
⬥ top,
absolute/fixed/relative positioned element as
numerical values
⬥ z-index : specifies the stack level of
positioned elements
⬩ Understanding stacking context
Each positioned element creates a stacking
context.
Elements in different stacking contexts are
overlapped according to the stacking order of
their containers. For example, there is no way
for #A1 and #A2 (children of #A) to be
placed over #B without increasing the z-
index of #A. 17
Inline element positioning
⬥ vertical-align: sets the vertical-alignment
of an inline element, according to the line
height
⬩ Values: baseline, sub, super, top, text-top,
middle, bottom, text-bottom or numeric
⬥ Also used for content of table cells (which apply
middle alignment by default)
18
Float
⬥float: the element “floats” to one side
⬩ left: places the element on the left and
following content on the right
⬩ right: places the element on the right and
following content on the left
⬩ floated elements should come before the
content that will wrap around them in the code
⬩ margins of floated elements do not collapse
⬩ floated inline elements can apply height
19
Float (2)
⬥How floated elements are positioned
20
Clear
⬥clear
21
Clear (2)
⬥ Clearing floats (continued)
⬩ :after { content: ""; display: block;
clear: both; height: 0; }
⬩ Triggering hasLayout in IE expands a container
of floated elements
⬩ display: inline-block;
⬩ zoom: 1;
22
Opacity
⬥opacity: specifies the opacity of the element
23
Visibility
⬥visibility
24
Display
⬥display: controls the display of the element
and the way it is rendered and if breaks should
be placed before and after the element
⬩ inline: no breaks are placed before and after
(<span> is an inline element)
⬩ block: breaks are placed before AND
after the element (<div> is a block element)
25
Display (2)
⬥display: controls the display of the element
and the way it is rendered and if breaks should
be placed before and after the element
⬩ none: element is hidden and its dimensions are
not used to calculate the surrounding
elements rendering (differs from
visibility: hidden!)
⬩ There are some more possible values, but not
all browsers support them
⬩ Specific displays like table-cell and table-
row
26
Overflow
⬥ overflow: defines the behavior of element when
content needs more space than you have specified by
the size properties or for other reasons. Values:
⬩ visible (default) – content spills out of
the element
⬩ auto - show scrollbars if needed
⬩ scroll – always show scrollbars
⬩ hidden – any content that cannot fit is
clipped
27
Other CSS Properties
⬥ cursor: specifies the look of the mouse
cursor when placed over the element
⬩ Values: crosshair, help, pointer,
progress, move, hair, col-resize, row-
resize, text, wait, copy, drop, and others
⬥white-space – controls the line breaking of
text. Value is one of:
⬩ nowrap – keeps the text on one line
⬩ normal (default) – browser decides whether
to brake the lines if needed
28
Benefits of using CSS
⬥More powerful formatting than using
presentation tags
⬥Your pages load faster, because browsers
cache the .css files
⬥ Increased
accessibility, because rules can be
defined according given media
⬥Pages are easier to maintain and update
29
Maintenance Example
Title Title
Some random Title Some random
Title text here. You Some random text here. You
Title can’t read it text here. You Title can’t read it
Some random
anyway! Har har can’t read it anyway! Har har
Title te t here. You Title Some random har! Use Css. Some random
x n’t read it anyway! Har har har! Use Css.
Some random Some random text here. Yo u text here. You
ca yway! Har har har! Use Css.
text here. You text here. You can’t read it Title can’t read it
anr! Use Css.
can’t read it can’t read it anyway! Har har anyway! H ar har
ha Some random Title Title
anyway! Har har anyway! Har har har! Use Css. har! Use Css.
text here. You Some random Some random
har! Use Css. har! Use Css.
can’t read it text here. You text here. You Title
anyway! Har har can’t read it can’t read it
Title Some random
har! Use Css. anyway! Har har anyway! Har har
Some random Title Title Title text here. You
Title har! Use Css. har! Use Css.
text here. You can’t read it
Some random Some random Some random
can’t read it Some random anyway! Har har
text here. Yo u text here. You Title text here. You
anyway! Har har text here. You har! Use Css.
can’t read it can’t read it can’t read it Title
har! Use Css. can’t read it Some random
anyway! Har har anyway! Har har anyway! Har har
anyway! Har har text here. You Title Some random
har! Use Css. har! Use Css. har! Use Css.
Title har! Use Css. Title can’t read it text here. You
Some random
anyway! Har har can’t read it
Some random Some random Title text here. You
har! Use Css. anyway! Har har
text here. You text here. You can’t read it
Some random har! Use Css.
can’t read it can’t read it anyway! Har har
text here. You
anyway! Har har anyway! Har har har! Use Css.
Title can’t read it Title
har! Use Css. har! Use Css. anyway! Har har
Some random har! Use Css. Some random
CSS
Title text here. You text here. You Title
Title can’t read it can’t read it
Some random Some random
anyway! Har har anyway! Har har
text here. You Some random Title Title Title text here. You
har! Use Css. har! Use Css.
can’t read it text here. You can’t read it
Some random Some random Some random
anyway! Har har can’t read it anyway! Har har
Title text here. You text here. You text here. You
har! Use Css. anyway! Har har har! Use Css.
can’t read it can’t read it can’t read it
har! Use Css. Some random
anyway! Har har anyway! Har har anyway! Har har
file
text here. You Title Title
har! Use Css. har! Use Css. har! Use Css.
can’t read it
Some random Some random
anyway! Har har
Title text here. You Title Title text here. You
har! Use Css.
n’t read it can’t read it
Some random Some random Some random
ca yway! Har har anyway! Har har
Title text here. You text here. You text here. You
an Use Css.
har! har! Use Css.
can’t read it can’t read it can’t read it
Some random anyway! H ar har anyway! Har har
Title te t here. Yo u anyway! Har har Title Title
x n’t read it har! Use Css. har! Use C ss. har! Use Css.
Some random ca Title Some random Title Some random Title
y! Har har
text here. You an Some random text here. You Some random text here. You Some random
ywase Css.
can’t read it ha text here. You can’t read it text here. You can’t read it Title text here. You
r!
anyway! Har har can’t read it anyway! Har har can’t read it anyway! Har har can’t read it
U Some random
har! Use Css. anyway! Har har har! Use Css. anyway! Har har har! Use Css. anyway! Har har
text here. Yo u
har! Use Css. har! Use Css. har! Use Css.
Title Title can’t read it
anyway! Har har
Some random Title Some random Title
har! Use Css.
text here. You Some random text here. You Some random
Title can’t read it text here. You can’t read it text here. You
anyway! Har har can’t read it anyway! Har har can’t read it
Some random Title
har! Use Css. anyway! Har har har! Use Css. anyway! Har har
text here. You
Title Some random
har! Use Css. har! Use Css.
can’t read it Title text here. You Title
Some random
anyway! Har har can’t read it
text here. You Some random Some random Title
har! Use Css. anyway! Har har
can’t r it text here. You text here. You
har! Use Css. Some random
ea H ar har
anyway! n’t read it can’t read it
Title Title text here. You
d ca
har! Use yway! Har har anyway! Har har can’t read it
Css. Some random an r! Use Css. Some random har! Use Css. anyway! Har har
text here. You text here. You Title Title
ha har! Use Css.
can’t read it can’t read it
Some random Some random
anyway! Har har anyway! Har har
text here. You text here. You
har! Use Css. har! Use Css.
can’t read it can’t read it
anyway! Har har anyway! Har har
har! Use Css. har! Use Css.
30
CSS Development Tools
⬥Visual Studio – CSS Editor
31
CSS Development Tools (3)
⬥ Firebug
– add-on to Firefox used to examine
and adjust CSS and HTML
32
CSS Development Tools (4)
⬥IE Developer Toolbar
– add-on to IE used to
examine CSS and HTML (press [F12])
33