CSS Part 2
CSS Part 2
CSS (Part 2)
Content
2
CSS Tables
CSS Border
The CSS Box Model
CSS Floats
3
CSS Tables
Table Borders
4
<style type="text/css">
table,th,td
{
border:1px solid black;
}
</style>
Collapse Borders
5
CSS Border
CSS Border
11
Sample:
http://www.w3schools.com/css/tryit.asp?filename=trycss_bor
der-style
Border Width
13
Shorthand
border-style:dotted solid double dashed;
border-style:dotted solid double;
border-style:dotted solid;
border-style:dotted;
Border - Shorthand
16
border-style
border-color
17
Margin
Border
Padding
Content
The CSS Box Model
21
Margin
Border
Padding
Padding
Content
Margins & Padding
23
Margins
Margins define the space around elements outside the
border
Margin properties can have negative values in order to
deliberately overlap content
Margin properties will affect the position of background
elements (graphics and/or colours) in relation to the edges
of the containing block element
Margin properties can be defined independently on top,
right, bottom and left, or all-at-once using CSS shorthand
Margins & Padding
24
Padding
Padding defines the space around elements inside the
border; i.e between the border and the content itself
Padding properties cannot have negative values
30
6
CSS Shorthand: Margin and Padding
27
Content Area
20 20
20
5
CSS Shorthand: Margin and Padding
28
10
0
CSS Shorthand: Margin and Padding: auto
29
CSS Floats
Floats: Positioning CSS Boxes
32
Setting the float property tex t text text text text text text text text text
tex t text text text text text text text text text
to left or right causes a tex t text text text text text text text text text
tex t text text text text text text text text text
block
box to be taken out of tex t text text text text text text text text text
inline
tex t text text text text text text text text text
its position in the tex t text text text text text text text text text
tex t text text text text text text text text text
normal flow and moved tex t text text text text text text text text text
tex t text text text text text text text text text
as far left or right as tex t text text text text text text text text text
tex t text text text text text text text text text
possible.
Float Values
33
To restore the “normal tex t text text text text text text text text text
inline
tex t text text text text text text text text text
flow”, we can use the clear tex t text text text text text text text text text
block
CSS Positioning
35
Fixed Positioning
Relative Positioning
Absolute Positioning
Containing box
CSS Positioning: Fixed Positioning
37
Box 4
Containing box
CSS Positioning: Relative Positioning
38
Containing box
CSS Positioning: Relative Positioning
39
In this example, box 2 is offset 20px, top and left. The result
is the box is offset 20px from its original position in the
normal flow. Box 2 may overlap other boxes in the flow, but
other boxes still recognize its original position in the flow.
}
Box 2
Containing box
CSS Positioning: Absolute Positioning
40
Left: 20px
Box 1 Box 3
Position: absolute
Box 2
top: 20px
#myBox {
position: absolute;
Left: 20px
left: 20px;
Box 1 Box 3
top: 20px; Position: absolute
}
Box 2
End of CSS
End
45