Csspagelayout
Csspagelayout
Overview
2
<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
<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
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
border-right, border-top particular 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_border.asp
Another border example
18
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_padding.asp
Padding example 1
20
This is a heading
output
Padding example 2
21
p {
padding-left: 200px; padding-top: 30px;
background-color: fuchsia;
}
CSS
paragraph
This is a first paragraph.
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_margin.asp
Margin example 1
23
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
26 Floating Elements
The CSS float property
27
img.headericon {
float: right; width: 130px;
} CSS
property description
side to hover on; can be left, right, or none
float
(default)
p { background-color: fuchsia; }
h2 { clear: right; background-color: yellow; }
CSS
Mario
Mario isis aa fictional
fictional character
character in in his his video video game game series. series.
Serving
Serving asas Nintendo's
Nintendo's mascot
mascot and and the the main main protagonist protagonist of
of
thethe series,
series, Mario
Mario hashas appeared
appeared in in over over 200 200 video video games
games since
since his his creation.
creation
Super Mario Fan Site!
output
The clear property (cont.)
31
property description
disallows floating elements from
overlapping this element;
clear
can be left, right, or none
(default)
Clear diagram
32
CSS
Mario is a fictional character in his video game series.
Serving as Nintendo's mascot and the main protagonist
of the series, Mario has appeared in over 200 video
games since his creation.
output
The overflow property (cont.)
35
property description
specifies what to do if an
element's content is too large;
overflow
can be auto, visible, hidden, or
scroll
Multi-column layouts
36
<div>
<p>first paragraph</p>
<p>second paragraph</p>
<p>third paragraph</p>
Some other text that is important
</div> HTML
CSS
Some other text that is important
third paragraph second paragraph first paragraph
output
37 Sizing and Positioning
The position property (examples)
38
div#ad {
position: fixed;
right: 10%;
top: 45%;
} CSS
#menubar {
position: absolute;
left: 400px;
top: 50px;
} CSS
¨ absolute-positioned elements
are normally positioned at an
offset from the corner of the
overall web page
¨ to make the absolute element to
position itself relative to some
other element's corner, wrap the
absolute element in an element
whose position is relative
Fixed positioning
41
#menubar {
position: fixed;
left: 400px;
top: 50px;
} CSS
property description
specifies where an inline element
should be aligned vertically, with
vertical-align
respect to other content on the same
line within its block element's box
output
property description
sets the type of CSS box model
display
an element is displayed with
<ul id="topmenu">
<li>Item 1</li>
<li>Item 2</li>
<li>Item 3</li>
</ul> HTML
#topmenu li {
display: inline;
border: 2px solid gray;
margin-right: 1em;
} CSS
output
p.secret {
visibility: hidden;
} CSS
output
¨ hidden elements will still take up space onscreen, but will not
be shown
¤ to make it not take up any space, set display to none instead
¨ can be used to show/hide dynamic HTML content on the page
in response to events