CSS Chapter 2
CSS Chapter 2
Chapter 2
Layout, Comments, Colors, and Backgrounds
Layout
Example
WEB PAGE
HTML Layout Elements and Techniques
• Websites often display content in multiple columns (like
a magazine or a newspaper).
Example
HTML Layout Elements
• HTML has several semantic elements that
define the different parts of a web page:
HTML5 Semantic Elements
• <header> - Defines a header for a document or
a section
• <nav> - Defines a set of navigation links
• <section> - Defines a section in a document
• <article> - Defines an independent, self-
contained content
HTML Layout Elements
• <aside> - Defines content aside from the
content (like a sidebar)
• <footer> - Defines a footer for a
document or a section
• <details> - Defines additional details that
the user can open and close on demand
• <summary> - Defines a heading for the
<details> element
HTML Layout Techniques
• There are four different techniques to create multicolumn
layouts. Each technique has its pros and cons:
• CSS framework
• CSS float property
• CSS flexbox
• CSS grid
CSS framework
• A CSS framework is a library allowing for easier, more
standards-compliant web design using the Cascading Style
Sheets language.
• Most of these frameworks contain at least a grid.
• More functional frameworks also come with more features and
additional JavaScript based functions, but are mostly design
oriented and focused around interactive UI patterns.
• This detail differentiates CSS frameworks from other JavaScript
frameworks.
CSS Float Layout
• It is common to do entire web layouts using the CSS float
property.
• Float is easy to learn - you just need to remember how the float
and clear properties work.
• Disadvantages: Floating elements are tied to the document flow,
which may harm the flexibility.
The float Property
• The float property is used for positioning and formatting content e.g. let an
image float left to the text in a container.
• The float property can have one of the following values:
• left - The element floats to the left of its container
• right - The element floats to the right of its container
• none - The element does not float (will be displayed just where it occurs in the text).
This is default
• In its simplest use, the float property can be used to wrap text around
images.
The float Property
• Example - float: right;
img {
float: right;
}
[class*="col-"] {
float: left;
padding: 15px;
border: 1px solid red;
}
Building a Responsive Grid-View
Each row should be wrapped in a <div>. The number of columns inside a row should always
add up to 12:
<div class="row">
<div class="col-3">...</div> <!-- 25% -->
<div class="col-9">...</div> <!-- 75% -->
</div>