class: frontpage
- Recap
- Resets and Boilerplates
- The
float
Strike Back and The Return of The Clearfix (pun intended) 🥁 - Building grids
- CSS Positioning
- CSS Units
- Lab
There are a lot of annoying default styles that are inconsistent across browsers. Sometimes we might want to remove them all so we have a blank canvas.
* {
margin: 0;
padding: 0;
}
One approach: https://meyerweb.com/eric/tools/css/reset/reset.css
My preference: https://necolas.github.io/normalize.css/
float
s are weird!
When floating elements, the parent container will collapse in height if it only contains floating elements.
This is because the floating elements have floated out of the container and the container doesn't know how to correctly calculate the height.
To work around this, we use the "clearfix" technique which is like putting a wedge in the top of the container and a wedge in the bottom of the container and forcing it open so it can correctly calculate the height.
Add this snippet to your CSS so you can clearfix collapsing containers
.clearfix:before,
.clearfix:after {
content: ' ';
display: table;
}
.clearfix:after {
clear: both;
}
To prevent a container from collapsing we add the clearfix class to the container in the HTML
<div class="main-content clearfix">...</div>
Imagine we have lots of pages that all use a combination of 1, 2, 3 and 4 columns for the layout
Could we use someting in CSS to standardise this?
Yes. class
selectors are perfect for building grids as they can be repeated on many different elements.
We write a very small amount of CSS which is then reused many times throughout a page and throughout a project.
floats
flex
- Precise placement of elements
- Tweak position of elements
- Not for layout
- Mostly for tackling complex design
CSS position
can take 1 of 4 values.
static
is the default and does not have to be set.
-
static
-
relative
-
absolute
-
fixed
- Move elements
relative
to themselves - Create a parent container
- Position elements absolutely inside
- Set the absolute co-ordinates of an element to be positioned
top
,right
,bottom
,left
- Use
px
,%
,em
and any other CSS unit
- Fix an element in place, regardless of scroll
- Set co-ordinates of where to fix an element
- Position is set relative to the body
z-index
controls the stacking order.- The
z-axis
comes out of the screen towards you - It’s a bit like Photoshop layers
z-index
only works for position other than static
Relative lengths represent a measurement in terms of some other distance. Depending on the unit, this can be the size of a specific character, the line height, or the size of the viewport.
It can be divided in:
- Font-relative lengths
- Viewport-percentage lengths
Font-relative lengths define the length value in terms of the size of a particular character or font attribute in the font currently in effect in an element or its parent.
Note: These units, especially
em
andrem
, are often used to create scalable layouts, which maintain the vertical rhythm of the page even when the user changes the font size.
em
: represents the calculatedfont-size
of the element. If used on the font-size property itself, it represents the inherited font-size of the element.rem
: Represents the font-size of the root element (typically<html>
). When used within the root element font-size, it represents its initial value (a common browser default is 16px, but user-defined preferences may modify this).
Viewport-percentage lengths define the length value relative to the size of the viewport, i.e., the visible portion of the document.
Note: If the
<html>
and<body>
elements are set asoverflow:auto
, space taken by scrollbars is not subtracted from the viewport, whereas it will be subtracted if set asoverflow:scroll
.**
vh
: equal to 1% of the height of the viewport's initial containing block.vw
equal to 1% of the width of the viewport's initial containing block.
Relaxr was really impressed by your work last week and wants you to continue development on their landing page.
Download the starter code
- Use flexbox in your CSS to achieve a two-column layout
- Use the correct
Open Sans
Google Font typeface to style the text denoted in the design file and according to the JPEG provided - Use proper filename conventions (lowercase, .html)
- Use a single external CSS stylesheet to style all pages
- Use a background image for the headers
- Add a hover effect to all the links using pseudo-classes
- Integrate drop caps using pseudo-classes
- Link the "Blog" link in the header to the page you've built for this assignment
- Link the "About" link in the header to the you built last week
class: frontpage