• BEGINNING
• HTML and CSS
Agenda
•
•
•
•
•
Review of HTML
Review of CSS
Box Model
Review of Positioning
Layouts
Fixed
Liquid
Review LAST CHANCE
• Let’s review the terms & jargon we’ve learned thus far:
• HTML terms:
• Tag
• Element
• Attribute
• CSS terms:
• Element Selector
• Class Selector
• Id Selector
Brief review of terms
Tag
Tags are used to denote the start of an element (i.e.
or the end of an element (i.e. </p>).
A tag is either a start tag or an end tag.
Examples of tags: <strong>, <html>, </p>, </body>
<p>)
Element
An element is the start tag + its content + the end tag:
<p>This is some paragraph text</p>
Attribute
Attributes provide additional information about HTML elements.
Attributes are formatted like this: attr="value"
The attribute always goes in the opening tag, never in the closing tag.
Example: In <img src=”http://www.google.com/images/logos/ps_logo2.png” />, src is
the attribute.
CSS Review
• The hallmark of all CSS is the combination of two things:
• A property
• A value
• We separate the property from the value with a colon.
• We end the value with a semicolon
Property : Value ;
CSS Element Selectors
CSS ID Selectors
CSS Pseudoclasses
Stylesheet Review
• There are three ways to insert styles on an HTML page:
• External Stylesheet
• Internal Stylesheet
• Inline Styles
Inline and internal
External
Positioning with CSS
• CSS provides four main ways to position your content:
• Static
• Fixed
• Relative
• Absolute
• If you use these in combination with
the CSS Box model, and float, you can layout
your websites in myriad ways.
Box Model
Width and height of an element
• When you set the width and height properties of an
element with CSS, you just set the width and height of
the content area.
• To calculate the full size of an element, you must also
add padding, borders and margins.
Example
• div {
width: 320px;
padding: 10px;
border: 5px solid gray;
margin: 0;
}
• 320px (width)
+ 20px (left + right padding)
+ 10px (left + right border)
+ 0px (left + right margin)
= 350px
Static and Fixed Positioning
• Static Positioning
• HTML elements are positioned static by default; there is
no need to set them to static. Static positioned elements
are positioned according to the normal flow of a page.
They ignore anything specified by top, bottom, right or
left properties.
• Fixed Positioning
• An element with fixed position is positioned relative to
the browser window.
• It will not move even if the window is scrolled--it will
always stay in the same, fixed location on the screen.
Relative Positioning
• A relative positioned element is positioned relative to its
normal position.You use the properties top, right, bottom
and left to position an element.
• For example, position:relative; left:-20px; will set an
element 20 pixels to the left of its normal position; it
subtracts 20 pixels from its normal left position.
Absolute Positioning
• The position of an absolutely positioned element is
determined by
the properties: top, right, bottom and left.
• an absolutely positioned element is offset from its
"container block."
• The "container block“ is the first parent element that has
a position other than static. If no such element is found,
the containing block is <html>.
• Absolutely positioned elements can overlap
• Unlike a Fixed element, an absolute element will move
as you scroll away from it.
Liquid vs Fixed Layouts
• Fixed Layouts
• In a Fixed Layout, the columns are set to a specific
width:
• A Set number of pixels in total (by total, I mean if you
add up the widths of all the columns), 750 pixels total,
900 pixels total, etc.
• If you resize the browser on a fixed layout page, the
columns will stay the same size.
Liquid vs Fixed Layouts
Liquid Layout:
• In a Liquid Layout, instead of using pixels to set a
specific width, the columns change sizes as you adjust
the browser size.
• One way to do this is with percentages. The left column
could be 20% of the page, the middle column 50% and
the right column 30%, for example.
Fixed Layout
• Let’s create a three-column layout that uses Absolute
Positioning in CSS
• We’ll begin by adding a header, wrapper and footer div
to the HTML:
<body>
<header>header!</header>
<main>
</main>
<footer>footer!</footer>
</body>
Adding Three Columns
• Next, insider the main we created, we’ll add three
additional divs
• <div id="left">I'm the left column</div>
• <div id="middle">I'm the middle column</div>
• <div id="right">I'm the right column</div>
Using an External Stylesheet
<head>
</head>
<title>New Web Project</title>
<link rel="stylesheet" href="style.css">
Styling the Header and Footer
• Now, let’s begin to add some styles to the divs, so we
can see them.
• • First, we’ll style both the header and the footer divs to
have a background- color and a specific size:
header, footer
{
background-color: beige;
height: 50px; width: 440px; padding:5px;
}
Styling main
•
•
•
•
•
We are going to style the mainto use position:relative;
This will create a new “containing block”
That means that any elements positioned
inside this main will use it as the starting location
Recall that the default starting location is the top left
main {
width: 100%;
position:relative;
top:10px;
}
Styling the Three Columns
• We’ll give all of the divs that are nested inside main the
same base
• We’ll do this using the nesting selectors concept
• This CSS will style all divs that live inside the main
element.
main div {
display:inline;
position:absolute;
padding:5px;
}
Styling the Three Columns
• We make all the divs display:inline so they will show up
one right after the other horizontally•
• We give them a default position:absolute because we’ll
be using the left property to put each column in a
different location.
main div {
display:inline;
position:absolute;
padding:5px;
}
Styling the Outer Columns
•
•
•
•
Now let’s give some
color to the left and right divs.
•We also give the left and right divs a specific size.
They will be positioned on top of one another-• we’ll fix that next.
#left, #right
{
background-color: lightblue;
width: 140px;
height: 200px;
}
Styling the Middle Column
• Now let’s give a different color to the middle div.
• We also give it a specific size.
• Next, we use the left property to move the middle div
150px to the left of its parent element-- the MAIN
#middle {
position: absolute;
left: 150px;
width: 140px;
height: 200px;
background-color: beige;
}
Styling the Right Column
• Now let’s position the right div.
• We position it 300px from the left of the containing MAIN
#right
{
position: absolute;
left: 300px;
}
Styling the Footer
• We already set the common styles that the header and
footer share. Now let’s give the footer an unique position
• We position it 290px from the top to allow for padding
etc
footer
{
position: absolute;
top: 290px;
}
Liquid Layout
• Let’s take a version of that file, and convert it to be a
liquid layout instead of a fixed layout.
Changing our Fixed Layout to Liquid
• Changing the CSS:
• Make the header and footer both have a 100% width
• We need to remove the default absolute positioning from
the divs inside the wrapper element
• We also need to remove the display:inline
Changing our Fixed Layout to Liquid
• We need a new selector for the left div:
#left {
float:left;
}
Changing our Fixed Layout to Liquid
• Changing the CSS:
• #right should not be position:absolute anymore.
• Let’s change #right instead to have float: right;
• Changing the CSS:
• Let’s take out the width, left and position: absolute
from the #middle id selector.
#middle
{
height: 200px;
background-color: beige;
}
Help!!!
Changing our Fixed Layout to Liquid
• Changing the HTML:
• That’s because when items are floated, anything you
want to fill in space left behind must go after
the floated elements.
• The middle div no longer goes in the middle!
<div id="left">I'm the left column</div>
<div id="right">I'm the right column</div>
<div id="middle">I'm the middle column</div>
A Few Tweaks
• Adding a margin to the right of the left column
• ensures the middle div’s text isn’t right next to the left
column.
#left {
float:left;
margin-right:10px;
}
© Copyright 2025 Paperzz