Module 6
Module 6
CSS (3/3)
(box, layout)
Johnny Zhang
CSS Box Model
o In CSS, the term “box model” is used when talking about design and
layout.
o The CSS box model is essentially a box that wraps around every
HTML element.
• Each element is represented by a rectangular box
• There are certain spaces that can be references with CSS
• Content: the content of the box, where text and images Margin
appear
• Padding is between content and
the border
• Border: A border that goes around the padding and content.
• Margin: Clears and area outside the boarder.
border:
• border-top, border-right, border-bottom, border-left
• attributes: color, width, style
• E.g., border-top-color, border-top-width, border-top-style
• style value: solid, dashed, dotted, double, inset, outset..
top
right
left
bottom
Practice 1
• margin-left
Center an Element (Block and Inline)
Any problems?
Challenge Questions
1. p{
width: 250px;
background: gray;
}
2. How to center the content (Welcome to
JavaScript) horizontally?
1. Practice 2
Solution
Width= 10+1+20+250+20+1+10
Height= 10+1+20+18+20+1+10
Box: default value (body)
Box: default value (p)
margin-bottom:
20px
margin-top:
10px
How many pixels?
CSS Layout: Position
• The position property specifies the type of
positioning method used for an element (static,
relative, fixed, absolute or sticky).
• There are five different position values:
v static
v relative
v fixed
v absolute
v sticky
position: static;
Explain: Why?
position: fixed
650px
CSS Layout - float and clear
• The CSS float property specifies how an element
should float.
• The float is used for positioning and formatting content.
• The CSS clear property specifies what elements can
float beside the cleared element and on which side.
• The clear property specifies what should happen with the
element that is next to floating element.
float
vnone - The element does not float (will be displayed just where it occurs in the
text). This is default
Width=600+(5+5+5+5)*3
Layout -1