SlideShare a Scribd company logo
FFunundadammeennttaalslso
o
f
fW
W
e
e
b
b
Randy C onnolly and Ricardo Hoar Fundamentals of Web Development
Textbook to be published by Pearson Ed in early 2
http://www.funwebdev.c
01
4
Fundamentals of Web Development
© 2015 Pearson
http://www.funwebdev.com
Advanced CSS:
Layout
Chapter 5
Positioning
Elements
Approaches to
CSS Layout
Responsive
Design
Objectives
1 Normal Flow
2
4 Multicolumn
Layouts
6
3 Floating
Elements
5
7 CSS
Frameworks
Fundamentals ofWeb Development
NORMAL FLOW
Fundamentals ofWeb Development
Section 1 of 7
Normal flow refers here to how the browser will
normally display block-‐level elements and inline
elements from left to right and from top to bottom
• Block-‐level elements are each contained on their
own line
• <p>, <div>, <h2>, <ul>, and <table>
• Inline elements do not form their own blocks but
instead are displayed within lines
• as <em>, <a>, <img>, and <span>
Fundamentals ofWeb Development
Normal Flow
If it’s so normal why have I never heard of it?
Normal Flow
Example
Fundamentals ofWeb Development
Normal Flow
Example
Fundamentals ofWeb Development
There are actually two types of inline elements:
replaced and nonreplaced.
• Replaced inline elements are elements whose
content and thus appearance is defined by some
external resource, such as <img> and the various
form elements.
• Nonreplaced inline elements are those elements
whose content is defined within the document,
which includes all the other inline elements.
Fundamentals ofWeb Development
Inline Elements
Two types
Working Together
Block level and in-line elements example
Fundamentals ofWeb Development
It is possible to change whether an element is block-‐
level or inline via the CSS display property. Consider
the following two CSS rules:
span { display: block; }
li { display: inline; }
These two rules will make all <span> elements behave
like block-‐level elements and all <li> elements like
inline (that is, each list item will be displayed on the
same line).
Fundamentals ofWeb Development
Take control
You can override defaults
POSITIONING ELEMENTS
Fundamentals ofWeb Development
Section 2 of 7
It is possible to move an item from its regular position
in the normal flow, and
• move an item outside of the browser viewport so it
is not visible
• position it so it is always visible in a fixed position
while the rest of the content scrolls.
The position property is used to specify the type of
positioning
Fundamentals ofWeb Development
Positioning Elements
Move it a little left…
Positioning
Its mostly relative – to something
Fundamentals ofWeb Development
Value Description
absolute The element is removed from normal flow and positioned in relation to
its nearest positioned ancestor.
fixed The element is fixed in a specific position in the window even when the
document is scrolled.
relative The element is moved relative to where it would be in the normal flow.
static The element is positioned according to the normal flow. This is the
default.
In relative positioning an element is displaced out of
its normal flow position and moved relative to where
it would have been placed
The other content around the relatively positioned
element “remembers” the element’s old position in
the flow; thus the space the element would have
occupied is preserved
Fundamentals ofWeb Development
Relative Positioning
Relative to what
Relative Positioning
Relatively simple Example
Fundamentals ofWeb Development
Absolute Positioning
Absolutely!
Fundamentals ofWeb Development
When an element is positioned absolutely,
it is removed completely from normal
flow.
Unlike with relative positioning, space is
not left for the moved element, as it is no
longer in the normal flow.
absolute positioning can get confusing
Absolute Positioning
Absolutely great example
Fundamentals ofWeb Development
Absolute Positioning
Absolutely relative?
Fundamentals ofWeb Development
A moved element via absolute position is actually
positioned relative to its nearest positioned ancestor
container
Absolute Positioning
A bit tricky
Fundamentals ofWeb Development
Z-Index
So, like the last topic?
Fundamentals ofWeb Development
When overlapping elements items closest to the
viewer (and thus on the top) have a larger z-‐index
• only positioned elements will make use of their z-‐
index
• simply setting the z-‐indexvalue of elements will not
necessarily move them on top or behind other
items.
Z-index
Example
Fundamentals ofWeb Development
Z-index
Example
Fundamentals ofWeb Development
Elements with fixed
positioning do not move
when the user scrolls up or
down the page
Fixed Position
Place your annoying ads here
Fundamentals ofWeb Development
FLOATING ELEMENTS
Fundamentals ofWeb Development
Section 3 of 7
• It is possible to displace an element out of its
position in the normal flow via the CSS float
property
• An element can be floated to the left or floated to
the right
• When an item is floated, it is moved all the way to
the far left or far right of its containing block and
the rest of the content is “re-‐flowed” around the
floated element
Fundamentals ofWeb Development
Floating Elements
Out of position
Value Description
left The left-‐handedge of the element cannot be adjacent to another element.
right The right-‐handedge of the element cannot be adjacent to another element.
both Both the left-‐hand and right-‐hand edges of the element cannot be adjacent to another element.
none The element can be adjacent to other elements.
Fundamentals ofWeb Development
Floating Elements
Edge(s) not adjacent
Floating Elements
Example floating
Fundamentals ofWeb Development
Notice that a floated block-‐level element must have a
width specified, if you do not, then the width will be
set to auto, which will mean it implicitly fills the entire
width of the containing block, and there thus will be
no room available to flow content around the floated
item.
Fundamentals ofWeb Development
Floating Elements
Details
It should be reiterated that a floated item moves to
the left or right of its container (also called its
containing block).
Fundamentals ofWeb Development
Floating within a container
Containing block rules
Floating within a container
Fundamentals ofWeb Development
Floating within a container
Zoom
Fundamentals ofWeb Development
Floating Multiple Items side by side
Fundamentals ofWeb Development
When you float multiple items that are in proximity,
each floated item in the container will be nestled up
beside the previously floated item
All other content in the containing block (including
other floated elements) will flow around all the
floated elements
Floating side by side
Example
Fundamentals ofWeb Development
You can stop elements from flowing around a floated
element by using the clear property
The Clear Property
Its very clear
Fundamentals ofWeb Development
Another problem that can occur with floats is when an
element is floated within a containing block that
contains only floated content. In such a case, the
containing block essentially disappears
Containing Floats
Problem
Fundamentals ofWeb Development
One solution would be to float the container as well,
but depending on the layout this might not be
possible. A better solution would be to use the
overflow property
Containing Floats
Solution
Fundamentals ofWeb Development
Overlaying and Hiding Elements
Fundamentals ofWeb Development
One of the more common design tasks with CSS is to
place two elements on top of each other, or to
selectively hide and display elements. Positioning is
important to both of these tasks.
Positioning is often used for smaller design changes,
such as moving items relative to other elements
within a container
In such a case, relative positioning is used to create
the positioning context for a subsequent absolute
positioning move
Positioning Context
A Helpful thing to learn
Fundamentals ofWeb Development
Positioning Context
A realistic example
Fundamentals ofWeb Development
Hiding elements
Fundamentals ofWeb Development
Two different ways to hide elements in CSS:
1. using the display property
• The display property takes an item out of the flow:
it is as if the element no longer exists
2. using the visibility property
• The visibility property just hides the element, but
the space for that element remains.
Hiding elements
Two ways to hide: display and visibility
Fundamentals ofWeb Development
Using :hover to make thumbnails
Fundamentals ofWeb Development
Next slide shows how the combination of absolute
positioning, the :hover pseudo-‐class, and the visibility
property can be used to display a larger version of an
image
Using :hover to make thumbnails
Fundamentals ofWeb Development
CONSTRUCTING MULTICOLUMN
LAYOUTS
Section 4 of 7
Fundamentals ofWeb Development
Constructing Multicolumn Layouts
Fundamentals ofWeb Development
There is unfortunately no simple and easy way to
create robust multicolumn page layouts. There are
tradeoffs with each approach:
• Using Floats to Create Columns
• Using Positioning to Create Columns
Using Floats to create Columns
Fundamentals ofWeb Development
The most common way to create columns of content
is using floats.
• The first step is to float the content container that
will be on the left-
‐
hand side. Remember that the
floated container needs to have a width specified.
Using Floats to create Columns
Fundamentals ofWeb Development
Using Floats to create Columns
Fundamentals ofWeb Development
The other key step is changing the left-‐margin so that
it no longer flows back under the floated content.
Using Floats to create Columns
Fundamentals ofWeb Development
Using Floats for Columns
3 Column Example
Fundamentals ofWeb Development
Using Positioning to Create Columns
Fundamentals ofWeb Development
Positioning can also be used to create a multicolumn
layout. Typically, the approach will be to absolute
position the elements that were floated in the
examples from the previous section
Using Positioning to Create Columns
Fundamentals ofWeb Development
Positioning discussion
Positives
Fundamentals ofWeb Development
Notice that with positioning it is easier to construct
our source document with content in a more SEO-‐
friendly manner; in this case, the main <div> can be
placed first.
Positioning discussion
Positives
Fundamentals ofWeb Development
Positioning discussion
Challenges
Fundamentals ofWeb Development
What would happen if one of the sidebars had a lot of
content and was thus quite long?
• In the floated layout, this would not be a problem
at all, because when an item is floated, blank space
is left behind.
• But when an item is positioned, it is removed
entirely from normal flow, so subsequent items will
have no “knowledge” of the positioned item.
Positioning Discussion
Problem illustration
Fundamentals ofWeb Development
APPROACHES TO CSS LAYOUT
Fundamentals ofWeb Development
Section 5 of 7
Approaches to CSS Layout
Fundamentals ofWeb Development
One of the main problems faced by web designers is
that the size of the screen used to view the page can
vary quite a bit.
• 21-‐inch wide screen monitor that can display
1920x1080 pixels
• older iPhone with a 3.5 screen and a resolution of
320x480 px
Satisfying both users can be difficult; the approach to
take for one type of site content might not work as
well with another site with different content.
Approaches to CSS Layout
Fundamentals ofWeb Development
Most designers take one of two basic approaches to
dealing with the problems of screen size.
• Fixed Layout
• Liquid Layout
• Hybrid Layout
In a fixed layout, the basic width of the design is set by the
designer, typically corresponding to an “ideal” width based
on a “typical” monitor resolution
The advantage of a fixed layout is that it is easier to produce
and generally has a predictable visual result.
Fixed layouts have drawbacks.
• For larger screens, there may be an excessive amount of
blank space to the left and/or right of the content.
• It is also optimized for typical desktop monitors;
however, as more and more user visits are happening
via smaller mobile devices
Fundamentals ofWeb Development
Fixed Layout
It isn't even broken
Fixed Layout
Notice the fixed size
Fundamentals ofWeb Development
Problem with fixed layouts
Fundamentals ofWeb Development
In a liquid layout (also called a fluid layout) widths are not
specified using pixels, but percentage values.
Advantage:
•adapts to different browser sizes,
Disadvantages:
• Liquid layouts can be more difficult to create because
some elements, such as images, have fixed pixel sizes
• the line length (which is an important contributing factor
to readability) may become too long or too short
Fundamentals ofWeb Development
Liquid Layout
Liquidy goodness
Liquid Layout
Liquidy goodness
Fundamentals ofWeb Development
A hybrid layout combines pixel and percentage
measurements.
• Fixed pixel measurements might make sense for a
sidebar column containing mainly graphic
advertising images that must always be displayed
and which always are the same width.
• percentages would make more sense for the main
content or navigation areas, with perhaps min and
max size limits in pixels set for the navigation
areas
Fundamentals ofWeb Development
Hybrid Layout
Such a smug feeling
RESPONSIVE DESIGN
Fundamentals ofWeb Development
Section 6 of 7
Responsive Design
Fundamentals ofWeb Development
In a responsive design, the page “responds” to
changes in the browser size that go beyond the width
scaling of a liquid layout.
One of the problems of a liquid layout is that images
and horizontal navigation elements tend to take up a
fixed size, and when the browser window shrinks to
the size of a mobile browser, liquid layouts can
become unusable. In a responsive layout, images will
be scaled down and navigation elements will be
replaced as the browser shrinks,
Responsive Design
Example
Fundamentals ofWeb Development
Responsive Design
Example
Fundamentals ofWeb Development
There are four key components that make responsive
design work.
1. Liquid layouts
2. Scaling images to the viewport size
3. Setting viewports via the <meta> tag
4. Customizing the CSS for different viewports using
media queries
Responsive designs begin with a liquid layout, that is,
one in which most elements have their widths
specified as percentages. Making images scale in size
is actually quite straightforward, in that you simply
need to specify the following rule:
img {
max-
‐
width: 100%;
}
Fundamentals ofWeb Development
Responsive Design
Liquid Layout
A key technique in
creating responsive
layouts makes use of the
ability of current mobile
browsers to shrink or
grow the web page to fit
the width of the screen.
Responsive Design
Setting Viewports
Fundamentals ofWeb Development
If the developer has created a responsive site that will scale to
fit a smaller screen, she may not want the mobile browser to
render it on the full-‐sizeviewport. The web page can tell the
mobile browser the viewport size to use via the viewport
<meta> element
<html>
<head>
<meta name="viewport" content="width=device-‐width" />
Fundamentals ofWeb Development
Responsive Design
Setting Viewports
Responsive Design
Setting Viewports
Fundamentals ofWeb Development
Media Queries
The other key component of responsive designs is CSS
media queries. A media query is a way to apply style
rules based on the medium that is displaying the file.
You can use these queries to look at the capabilities of
the device, and then define CSS rules to target that
device.
Fundamentals ofWeb Development
Media Queries
Fundamentals ofWeb Development
Contemporary responsive sites will typically provide
CSS rules for phone displays first, then tablets, then
desktop monitors, an approach called progressive
enhancement, in which a design is adapted to
progressively more advanced devices
Media Queries
Browser features you can Examine with Media Queries
Feature Description
width Width of the viewport
height Height of the viewport
device-‐width Width of the device
device-‐height Height of the device
orientation Whether the device is portrait or landscape
color The number of bits per color
[HP1]Au: Should these go in monospace font? HP
Fundamentals ofWeb Development
Media Queries
Media queries in action
Fundamentals ofWeb Development
CSS FRAMEWORKS
Fundamentals ofWeb Development
Section 7 of 7
A CSS framework is a pre-‐created set of CSS classes or
other software tools that make it easier to use and
work with CSS.
There are two main types of CSS framework:
• Grid systems
• CSS preprocessors.
Fundamentals ofWeb Development
CSS Frameworks
This is hard!
Grid systems make it easier to create multicolumn
layouts. Some of the most popular are
• Bootstrap (twitter.github.com/bootstrap)
• Blueprint (www.blueprintcss.org)
• 960 (960.gs)
Print designers typically use grids as a way to achieve
visual uniformity in a design. In print design, the very
first thing a designer may do is to construct, for
instance, a 5-
‐or 7-
‐or 12-
‐
column grid. The rest of the
document, whether it be text or graphics, will be
aligned and sized according to the grid
Fundamentals ofWeb Development
Grid Systems
Frameworks do the heavy lifting
Grid Systems
Frameworks do the heavy lifting
Fundamentals ofWeb Development
Grid Systems
960 code
Fundamentals ofWeb Development
Grid Systems
Bootstrap code
Fundamentals ofWeb Development
Example Pure Bootstrap Layouts
Just pull yourself up partner
Fundamentals ofWeb Development
CSS Preprocessors
Fundamentals ofWeb Development
CSS preprocessors are tools that allow the developer
to write CSS that takes advantage of programming
ideas such as variables, inheritance, calculations, and
functions.
Most sites make use of some type of color scheme,
perhaps four or five colors. Many items will have the
same color.
CSS Preprocessors
Fundamentals ofWeb Development
What you Learned
Positioning
Elements
Approaches to
CSS Layout
Responsive
Design
1 Normal Flow
2
4 Multicolumn
Layouts
6
3 Floating
Elements
5
7 CSS
Frameworks
Fundamentals ofWeb Development

More Related Content

Similar to Chapter05-Presentation.pptx

Cross Browser Issues - few solutions inspired by smashing magazine
Cross Browser Issues - few solutions inspired by smashing magazineCross Browser Issues - few solutions inspired by smashing magazine
Cross Browser Issues - few solutions inspired by smashing magazine
Prabhakaran Mani
 
Web Programming Basic topic.pptx
Web Programming Basic topic.pptxWeb Programming Basic topic.pptx
Web Programming Basic topic.pptx
ShouravPodder3
 
css.pdf
css.pdfcss.pdf
Exp13 write up
Exp13 write upExp13 write up
Exp13 write up
Ankit Dubey
 
Cascading Style Sheets CSS
Cascading Style Sheets CSS Cascading Style Sheets CSS
Cascading Style Sheets CSS
Asif Shahzad
 
Web Design & Development - Session 3
Web Design & Development - Session 3Web Design & Development - Session 3
Web Design & Development - Session 3
Shahrzad Peyman
 
Better Page Object Handling with Loadable Component Pattern
Better Page Object Handling with Loadable Component PatternBetter Page Object Handling with Loadable Component Pattern
Better Page Object Handling with Loadable Component Pattern
Sargis Sargsyan
 
Chapter6
Chapter6Chapter6
Chapter6
DeAnna Gossett
 
Page layout with css
Page layout with cssPage layout with css
Page layout with css
Er. Nawaraj Bhandari
 
9781111528705_PPT_ch07.ppt
9781111528705_PPT_ch07.ppt9781111528705_PPT_ch07.ppt
9781111528705_PPT_ch07.ppt
SimonChirambira
 
Chapter15-Presentation.pptx
Chapter15-Presentation.pptxChapter15-Presentation.pptx
Chapter15-Presentation.pptx
GFRomano
 
A practical guide to building websites with HTML5 & CSS3
A practical guide to building websites with HTML5 & CSS3A practical guide to building websites with HTML5 & CSS3
A practical guide to building websites with HTML5 & CSS3
Darren Wood
 
Designing for the web - 101
Designing for the web - 101Designing for the web - 101
Designing for the web - 101
Ashraf Hamdy
 
CSS3 Flex Layout
CSS3 Flex LayoutCSS3 Flex Layout
CSS3 Flex Layout
Neha Sharma
 
CSS tutorial chapter 3
CSS tutorial chapter 3CSS tutorial chapter 3
CSS tutorial chapter 3
jeweltutin
 
Parallax effect in css by Khubaib
Parallax effect in css by KhubaibParallax effect in css by Khubaib
Parallax effect in css by Khubaib
Khubaib Ahmad Kunjahi
 
はじめてのWKInterfaceController
はじめてのWKInterfaceControllerはじめてのWKInterfaceController
はじめてのWKInterfaceController
toyship
 

Similar to Chapter05-Presentation.pptx (20)

Cross Browser Issues - few solutions inspired by smashing magazine
Cross Browser Issues - few solutions inspired by smashing magazineCross Browser Issues - few solutions inspired by smashing magazine
Cross Browser Issues - few solutions inspired by smashing magazine
 
Web Programming Basic topic.pptx
Web Programming Basic topic.pptxWeb Programming Basic topic.pptx
Web Programming Basic topic.pptx
 
css.pdf
css.pdfcss.pdf
css.pdf
 
Exp13 write up
Exp13 write upExp13 write up
Exp13 write up
 
Cascading Style Sheets CSS
Cascading Style Sheets CSS Cascading Style Sheets CSS
Cascading Style Sheets CSS
 
Web Design & Development - Session 3
Web Design & Development - Session 3Web Design & Development - Session 3
Web Design & Development - Session 3
 
Lecture2 CSS 3
Lecture2   CSS 3Lecture2   CSS 3
Lecture2 CSS 3
 
Ppt ch07
Ppt ch07Ppt ch07
Ppt ch07
 
Ppt ch07
Ppt ch07Ppt ch07
Ppt ch07
 
Better Page Object Handling with Loadable Component Pattern
Better Page Object Handling with Loadable Component PatternBetter Page Object Handling with Loadable Component Pattern
Better Page Object Handling with Loadable Component Pattern
 
Chapter6
Chapter6Chapter6
Chapter6
 
Page layout with css
Page layout with cssPage layout with css
Page layout with css
 
9781111528705_PPT_ch07.ppt
9781111528705_PPT_ch07.ppt9781111528705_PPT_ch07.ppt
9781111528705_PPT_ch07.ppt
 
Chapter15-Presentation.pptx
Chapter15-Presentation.pptxChapter15-Presentation.pptx
Chapter15-Presentation.pptx
 
A practical guide to building websites with HTML5 & CSS3
A practical guide to building websites with HTML5 & CSS3A practical guide to building websites with HTML5 & CSS3
A practical guide to building websites with HTML5 & CSS3
 
Designing for the web - 101
Designing for the web - 101Designing for the web - 101
Designing for the web - 101
 
CSS3 Flex Layout
CSS3 Flex LayoutCSS3 Flex Layout
CSS3 Flex Layout
 
CSS tutorial chapter 3
CSS tutorial chapter 3CSS tutorial chapter 3
CSS tutorial chapter 3
 
Parallax effect in css by Khubaib
Parallax effect in css by KhubaibParallax effect in css by Khubaib
Parallax effect in css by Khubaib
 
はじめてのWKInterfaceController
はじめてのWKInterfaceControllerはじめてのWKInterfaceController
はじめてのWKInterfaceController
 

Recently uploaded

Home assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdfHome assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdf
Tamralipta Mahavidyalaya
 
The Roman Empire A Historical Colossus.pdf
The Roman Empire A Historical Colossus.pdfThe Roman Empire A Historical Colossus.pdf
The Roman Empire A Historical Colossus.pdf
kaushalkr1407
 
1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx
JosvitaDsouza2
 
The Accursed House by Émile Gaboriau.pptx
The Accursed House by Émile Gaboriau.pptxThe Accursed House by Émile Gaboriau.pptx
The Accursed House by Émile Gaboriau.pptx
DhatriParmar
 
Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345
beazzy04
 
Guidance_and_Counselling.pdf B.Ed. 4th Semester
Guidance_and_Counselling.pdf B.Ed. 4th SemesterGuidance_and_Counselling.pdf B.Ed. 4th Semester
Guidance_and_Counselling.pdf B.Ed. 4th Semester
Atul Kumar Singh
 
Unit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdfUnit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdf
Thiyagu K
 
Acetabularia Information For Class 9 .docx
Acetabularia Information For Class 9  .docxAcetabularia Information For Class 9  .docx
Acetabularia Information For Class 9 .docx
vaibhavrinwa19
 
Introduction to AI for Nonprofits with Tapp Network
Introduction to AI for Nonprofits with Tapp NetworkIntroduction to AI for Nonprofits with Tapp Network
Introduction to AI for Nonprofits with Tapp Network
TechSoup
 
A Strategic Approach: GenAI in Education
A Strategic Approach: GenAI in EducationA Strategic Approach: GenAI in Education
A Strategic Approach: GenAI in Education
Peter Windle
 
Thesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.pptThesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.ppt
EverAndrsGuerraGuerr
 
Digital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and ResearchDigital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and Research
Vikramjit Singh
 
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
EugeneSaldivar
 
Overview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with MechanismOverview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with Mechanism
DeeptiGupta154
 
The Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official PublicationThe Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official Publication
Delapenabediema
 
Lapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdfLapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdf
Jean Carlos Nunes Paixão
 
Francesca Gottschalk - How can education support child empowerment.pptx
Francesca Gottschalk - How can education support child empowerment.pptxFrancesca Gottschalk - How can education support child empowerment.pptx
Francesca Gottschalk - How can education support child empowerment.pptx
EduSkills OECD
 
2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...
Sandy Millin
 
The approach at University of Liverpool.pptx
The approach at University of Liverpool.pptxThe approach at University of Liverpool.pptx
The approach at University of Liverpool.pptx
Jisc
 
Operation Blue Star - Saka Neela Tara
Operation Blue Star   -  Saka Neela TaraOperation Blue Star   -  Saka Neela Tara
Operation Blue Star - Saka Neela Tara
Balvir Singh
 

Recently uploaded (20)

Home assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdfHome assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdf
 
The Roman Empire A Historical Colossus.pdf
The Roman Empire A Historical Colossus.pdfThe Roman Empire A Historical Colossus.pdf
The Roman Empire A Historical Colossus.pdf
 
1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx
 
The Accursed House by Émile Gaboriau.pptx
The Accursed House by Émile Gaboriau.pptxThe Accursed House by Émile Gaboriau.pptx
The Accursed House by Émile Gaboriau.pptx
 
Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345
 
Guidance_and_Counselling.pdf B.Ed. 4th Semester
Guidance_and_Counselling.pdf B.Ed. 4th SemesterGuidance_and_Counselling.pdf B.Ed. 4th Semester
Guidance_and_Counselling.pdf B.Ed. 4th Semester
 
Unit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdfUnit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdf
 
Acetabularia Information For Class 9 .docx
Acetabularia Information For Class 9  .docxAcetabularia Information For Class 9  .docx
Acetabularia Information For Class 9 .docx
 
Introduction to AI for Nonprofits with Tapp Network
Introduction to AI for Nonprofits with Tapp NetworkIntroduction to AI for Nonprofits with Tapp Network
Introduction to AI for Nonprofits with Tapp Network
 
A Strategic Approach: GenAI in Education
A Strategic Approach: GenAI in EducationA Strategic Approach: GenAI in Education
A Strategic Approach: GenAI in Education
 
Thesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.pptThesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.ppt
 
Digital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and ResearchDigital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and Research
 
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
 
Overview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with MechanismOverview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with Mechanism
 
The Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official PublicationThe Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official Publication
 
Lapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdfLapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdf
 
Francesca Gottschalk - How can education support child empowerment.pptx
Francesca Gottschalk - How can education support child empowerment.pptxFrancesca Gottschalk - How can education support child empowerment.pptx
Francesca Gottschalk - How can education support child empowerment.pptx
 
2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...
 
The approach at University of Liverpool.pptx
The approach at University of Liverpool.pptxThe approach at University of Liverpool.pptx
The approach at University of Liverpool.pptx
 
Operation Blue Star - Saka Neela Tara
Operation Blue Star   -  Saka Neela TaraOperation Blue Star   -  Saka Neela Tara
Operation Blue Star - Saka Neela Tara
 

Chapter05-Presentation.pptx

  • 1. FFunundadammeennttaalslso o f fW W e e b b Randy C onnolly and Ricardo Hoar Fundamentals of Web Development Textbook to be published by Pearson Ed in early 2 http://www.funwebdev.c 01 4 Fundamentals of Web Development © 2015 Pearson http://www.funwebdev.com Advanced CSS: Layout Chapter 5
  • 2. Positioning Elements Approaches to CSS Layout Responsive Design Objectives 1 Normal Flow 2 4 Multicolumn Layouts 6 3 Floating Elements 5 7 CSS Frameworks Fundamentals ofWeb Development
  • 3. NORMAL FLOW Fundamentals ofWeb Development Section 1 of 7
  • 4. Normal flow refers here to how the browser will normally display block-‐level elements and inline elements from left to right and from top to bottom • Block-‐level elements are each contained on their own line • <p>, <div>, <h2>, <ul>, and <table> • Inline elements do not form their own blocks but instead are displayed within lines • as <em>, <a>, <img>, and <span> Fundamentals ofWeb Development Normal Flow If it’s so normal why have I never heard of it?
  • 7. There are actually two types of inline elements: replaced and nonreplaced. • Replaced inline elements are elements whose content and thus appearance is defined by some external resource, such as <img> and the various form elements. • Nonreplaced inline elements are those elements whose content is defined within the document, which includes all the other inline elements. Fundamentals ofWeb Development Inline Elements Two types
  • 8. Working Together Block level and in-line elements example Fundamentals ofWeb Development
  • 9. It is possible to change whether an element is block-‐ level or inline via the CSS display property. Consider the following two CSS rules: span { display: block; } li { display: inline; } These two rules will make all <span> elements behave like block-‐level elements and all <li> elements like inline (that is, each list item will be displayed on the same line). Fundamentals ofWeb Development Take control You can override defaults
  • 10. POSITIONING ELEMENTS Fundamentals ofWeb Development Section 2 of 7
  • 11. It is possible to move an item from its regular position in the normal flow, and • move an item outside of the browser viewport so it is not visible • position it so it is always visible in a fixed position while the rest of the content scrolls. The position property is used to specify the type of positioning Fundamentals ofWeb Development Positioning Elements Move it a little left…
  • 12. Positioning Its mostly relative – to something Fundamentals ofWeb Development Value Description absolute The element is removed from normal flow and positioned in relation to its nearest positioned ancestor. fixed The element is fixed in a specific position in the window even when the document is scrolled. relative The element is moved relative to where it would be in the normal flow. static The element is positioned according to the normal flow. This is the default.
  • 13. In relative positioning an element is displaced out of its normal flow position and moved relative to where it would have been placed The other content around the relatively positioned element “remembers” the element’s old position in the flow; thus the space the element would have occupied is preserved Fundamentals ofWeb Development Relative Positioning Relative to what
  • 14. Relative Positioning Relatively simple Example Fundamentals ofWeb Development
  • 15. Absolute Positioning Absolutely! Fundamentals ofWeb Development When an element is positioned absolutely, it is removed completely from normal flow. Unlike with relative positioning, space is not left for the moved element, as it is no longer in the normal flow. absolute positioning can get confusing
  • 16. Absolute Positioning Absolutely great example Fundamentals ofWeb Development
  • 17. Absolute Positioning Absolutely relative? Fundamentals ofWeb Development A moved element via absolute position is actually positioned relative to its nearest positioned ancestor container
  • 18. Absolute Positioning A bit tricky Fundamentals ofWeb Development
  • 19. Z-Index So, like the last topic? Fundamentals ofWeb Development When overlapping elements items closest to the viewer (and thus on the top) have a larger z-‐index • only positioned elements will make use of their z-‐ index • simply setting the z-‐indexvalue of elements will not necessarily move them on top or behind other items.
  • 22. Elements with fixed positioning do not move when the user scrolls up or down the page Fixed Position Place your annoying ads here Fundamentals ofWeb Development
  • 23. FLOATING ELEMENTS Fundamentals ofWeb Development Section 3 of 7
  • 24. • It is possible to displace an element out of its position in the normal flow via the CSS float property • An element can be floated to the left or floated to the right • When an item is floated, it is moved all the way to the far left or far right of its containing block and the rest of the content is “re-‐flowed” around the floated element Fundamentals ofWeb Development Floating Elements Out of position
  • 25. Value Description left The left-‐handedge of the element cannot be adjacent to another element. right The right-‐handedge of the element cannot be adjacent to another element. both Both the left-‐hand and right-‐hand edges of the element cannot be adjacent to another element. none The element can be adjacent to other elements. Fundamentals ofWeb Development Floating Elements Edge(s) not adjacent
  • 27. Notice that a floated block-‐level element must have a width specified, if you do not, then the width will be set to auto, which will mean it implicitly fills the entire width of the containing block, and there thus will be no room available to flow content around the floated item. Fundamentals ofWeb Development Floating Elements Details
  • 28. It should be reiterated that a floated item moves to the left or right of its container (also called its containing block). Fundamentals ofWeb Development Floating within a container Containing block rules
  • 29. Floating within a container Fundamentals ofWeb Development
  • 30. Floating within a container Zoom Fundamentals ofWeb Development
  • 31. Floating Multiple Items side by side Fundamentals ofWeb Development When you float multiple items that are in proximity, each floated item in the container will be nestled up beside the previously floated item All other content in the containing block (including other floated elements) will flow around all the floated elements
  • 32. Floating side by side Example Fundamentals ofWeb Development
  • 33. You can stop elements from flowing around a floated element by using the clear property The Clear Property Its very clear Fundamentals ofWeb Development
  • 34. Another problem that can occur with floats is when an element is floated within a containing block that contains only floated content. In such a case, the containing block essentially disappears Containing Floats Problem Fundamentals ofWeb Development
  • 35. One solution would be to float the container as well, but depending on the layout this might not be possible. A better solution would be to use the overflow property Containing Floats Solution Fundamentals ofWeb Development
  • 36. Overlaying and Hiding Elements Fundamentals ofWeb Development One of the more common design tasks with CSS is to place two elements on top of each other, or to selectively hide and display elements. Positioning is important to both of these tasks. Positioning is often used for smaller design changes, such as moving items relative to other elements within a container In such a case, relative positioning is used to create the positioning context for a subsequent absolute positioning move
  • 37. Positioning Context A Helpful thing to learn Fundamentals ofWeb Development
  • 38. Positioning Context A realistic example Fundamentals ofWeb Development
  • 39. Hiding elements Fundamentals ofWeb Development Two different ways to hide elements in CSS: 1. using the display property • The display property takes an item out of the flow: it is as if the element no longer exists 2. using the visibility property • The visibility property just hides the element, but the space for that element remains.
  • 40. Hiding elements Two ways to hide: display and visibility Fundamentals ofWeb Development
  • 41. Using :hover to make thumbnails Fundamentals ofWeb Development Next slide shows how the combination of absolute positioning, the :hover pseudo-‐class, and the visibility property can be used to display a larger version of an image
  • 42. Using :hover to make thumbnails Fundamentals ofWeb Development
  • 43. CONSTRUCTING MULTICOLUMN LAYOUTS Section 4 of 7 Fundamentals ofWeb Development
  • 44. Constructing Multicolumn Layouts Fundamentals ofWeb Development There is unfortunately no simple and easy way to create robust multicolumn page layouts. There are tradeoffs with each approach: • Using Floats to Create Columns • Using Positioning to Create Columns
  • 45. Using Floats to create Columns Fundamentals ofWeb Development The most common way to create columns of content is using floats. • The first step is to float the content container that will be on the left- ‐ hand side. Remember that the floated container needs to have a width specified.
  • 46. Using Floats to create Columns Fundamentals ofWeb Development
  • 47. Using Floats to create Columns Fundamentals ofWeb Development The other key step is changing the left-‐margin so that it no longer flows back under the floated content.
  • 48. Using Floats to create Columns Fundamentals ofWeb Development
  • 49. Using Floats for Columns 3 Column Example Fundamentals ofWeb Development
  • 50. Using Positioning to Create Columns Fundamentals ofWeb Development Positioning can also be used to create a multicolumn layout. Typically, the approach will be to absolute position the elements that were floated in the examples from the previous section
  • 51. Using Positioning to Create Columns Fundamentals ofWeb Development
  • 52. Positioning discussion Positives Fundamentals ofWeb Development Notice that with positioning it is easier to construct our source document with content in a more SEO-‐ friendly manner; in this case, the main <div> can be placed first.
  • 54. Positioning discussion Challenges Fundamentals ofWeb Development What would happen if one of the sidebars had a lot of content and was thus quite long? • In the floated layout, this would not be a problem at all, because when an item is floated, blank space is left behind. • But when an item is positioned, it is removed entirely from normal flow, so subsequent items will have no “knowledge” of the positioned item.
  • 56. APPROACHES TO CSS LAYOUT Fundamentals ofWeb Development Section 5 of 7
  • 57. Approaches to CSS Layout Fundamentals ofWeb Development One of the main problems faced by web designers is that the size of the screen used to view the page can vary quite a bit. • 21-‐inch wide screen monitor that can display 1920x1080 pixels • older iPhone with a 3.5 screen and a resolution of 320x480 px Satisfying both users can be difficult; the approach to take for one type of site content might not work as well with another site with different content.
  • 58. Approaches to CSS Layout Fundamentals ofWeb Development Most designers take one of two basic approaches to dealing with the problems of screen size. • Fixed Layout • Liquid Layout • Hybrid Layout
  • 59. In a fixed layout, the basic width of the design is set by the designer, typically corresponding to an “ideal” width based on a “typical” monitor resolution The advantage of a fixed layout is that it is easier to produce and generally has a predictable visual result. Fixed layouts have drawbacks. • For larger screens, there may be an excessive amount of blank space to the left and/or right of the content. • It is also optimized for typical desktop monitors; however, as more and more user visits are happening via smaller mobile devices Fundamentals ofWeb Development Fixed Layout It isn't even broken
  • 60. Fixed Layout Notice the fixed size Fundamentals ofWeb Development
  • 61. Problem with fixed layouts Fundamentals ofWeb Development
  • 62. In a liquid layout (also called a fluid layout) widths are not specified using pixels, but percentage values. Advantage: •adapts to different browser sizes, Disadvantages: • Liquid layouts can be more difficult to create because some elements, such as images, have fixed pixel sizes • the line length (which is an important contributing factor to readability) may become too long or too short Fundamentals ofWeb Development Liquid Layout Liquidy goodness
  • 64. A hybrid layout combines pixel and percentage measurements. • Fixed pixel measurements might make sense for a sidebar column containing mainly graphic advertising images that must always be displayed and which always are the same width. • percentages would make more sense for the main content or navigation areas, with perhaps min and max size limits in pixels set for the navigation areas Fundamentals ofWeb Development Hybrid Layout Such a smug feeling
  • 65. RESPONSIVE DESIGN Fundamentals ofWeb Development Section 6 of 7
  • 66. Responsive Design Fundamentals ofWeb Development In a responsive design, the page “responds” to changes in the browser size that go beyond the width scaling of a liquid layout. One of the problems of a liquid layout is that images and horizontal navigation elements tend to take up a fixed size, and when the browser window shrinks to the size of a mobile browser, liquid layouts can become unusable. In a responsive layout, images will be scaled down and navigation elements will be replaced as the browser shrinks,
  • 68. Responsive Design Example Fundamentals ofWeb Development There are four key components that make responsive design work. 1. Liquid layouts 2. Scaling images to the viewport size 3. Setting viewports via the <meta> tag 4. Customizing the CSS for different viewports using media queries
  • 69. Responsive designs begin with a liquid layout, that is, one in which most elements have their widths specified as percentages. Making images scale in size is actually quite straightforward, in that you simply need to specify the following rule: img { max- ‐ width: 100%; } Fundamentals ofWeb Development Responsive Design Liquid Layout
  • 70. A key technique in creating responsive layouts makes use of the ability of current mobile browsers to shrink or grow the web page to fit the width of the screen. Responsive Design Setting Viewports Fundamentals ofWeb Development
  • 71. If the developer has created a responsive site that will scale to fit a smaller screen, she may not want the mobile browser to render it on the full-‐sizeviewport. The web page can tell the mobile browser the viewport size to use via the viewport <meta> element <html> <head> <meta name="viewport" content="width=device-‐width" /> Fundamentals ofWeb Development Responsive Design Setting Viewports
  • 73. Media Queries The other key component of responsive designs is CSS media queries. A media query is a way to apply style rules based on the medium that is displaying the file. You can use these queries to look at the capabilities of the device, and then define CSS rules to target that device. Fundamentals ofWeb Development
  • 74. Media Queries Fundamentals ofWeb Development Contemporary responsive sites will typically provide CSS rules for phone displays first, then tablets, then desktop monitors, an approach called progressive enhancement, in which a design is adapted to progressively more advanced devices
  • 75. Media Queries Browser features you can Examine with Media Queries Feature Description width Width of the viewport height Height of the viewport device-‐width Width of the device device-‐height Height of the device orientation Whether the device is portrait or landscape color The number of bits per color [HP1]Au: Should these go in monospace font? HP Fundamentals ofWeb Development
  • 76. Media Queries Media queries in action Fundamentals ofWeb Development
  • 77. CSS FRAMEWORKS Fundamentals ofWeb Development Section 7 of 7
  • 78. A CSS framework is a pre-‐created set of CSS classes or other software tools that make it easier to use and work with CSS. There are two main types of CSS framework: • Grid systems • CSS preprocessors. Fundamentals ofWeb Development CSS Frameworks This is hard!
  • 79. Grid systems make it easier to create multicolumn layouts. Some of the most popular are • Bootstrap (twitter.github.com/bootstrap) • Blueprint (www.blueprintcss.org) • 960 (960.gs) Print designers typically use grids as a way to achieve visual uniformity in a design. In print design, the very first thing a designer may do is to construct, for instance, a 5- ‐or 7- ‐or 12- ‐ column grid. The rest of the document, whether it be text or graphics, will be aligned and sized according to the grid Fundamentals ofWeb Development Grid Systems Frameworks do the heavy lifting
  • 80. Grid Systems Frameworks do the heavy lifting Fundamentals ofWeb Development
  • 83. Example Pure Bootstrap Layouts Just pull yourself up partner Fundamentals ofWeb Development
  • 84. CSS Preprocessors Fundamentals ofWeb Development CSS preprocessors are tools that allow the developer to write CSS that takes advantage of programming ideas such as variables, inheritance, calculations, and functions. Most sites make use of some type of color scheme, perhaps four or five colors. Many items will have the same color.
  • 86. What you Learned Positioning Elements Approaches to CSS Layout Responsive Design 1 Normal Flow 2 4 Multicolumn Layouts 6 3 Floating Elements 5 7 CSS Frameworks Fundamentals ofWeb Development