GithubHelp home page GithubHelp logo

2019-spring-03-css-layout's Introduction

CoderBabez

Week Three - CSS Layouts

Objectives

Use flexbox to create a complex site layout with rows and columns.

Vocab

  • Box Model
  • Divs
  • Parent Elements
  • Child Elements
  • Flexbox

Review

  1. What tags are used on this page?
  2. What styles are used on this page?
  3. How does the html page know about the styles?

alt text

Intro

Last week we started exploring using CSS to add styles to our pages. This week we're going to continue with CSS to work on layout - or moving elements to specific positions on the page using CSS.

Lesson - CSS and Layouts:

  1. When you look at HTML, imagine every element having a box drawn around it. In CSS, the term "box model" is used when talking about design and layout. The CSS box model is essentially a box that wraps around every HTML element. It consists of: margins, borders, padding, and the actual content.

alt text

  1. Sometimes we want to group these boxes together into larger boxes that can be styled as a single section. When we want to do that, we can use the <div> tag. Think of the div tag a blank slate / empty box.

  2. When we nest tags inside of each other (like with a div), we call the outer element the parent and the inner element the child.

alt text

  1. The ability to group items together like this becomes especially useful when we want to create complex layouts like rows and columns. There are a few ways to do this in CSS. The most common way to create layouts is something called a "float", but today we're going to use a new CSS method called "flexbox". Flexbox is more modern, and is probably what most sites will use in the future, even though some older browsers don't support it.

  2. In flexbox, the parent element tells the child elements how to behave.

<div class=”parent”>
	<div class=”child”>
		<img ...>
	</div>
</div>

This CSS is telling all of the elements inside of the parent tag to appear in a centered column.

parent {
	display: flex;
	flex-direction: column;
	align-items: center;
}

Look at the flexbox cheat sheet below for more flexbox rules you can use!

FlexBox Cheat Sheet

display: sets the flex container

  • flex

flex-direction: sets the main axis for the content

  • row
  • row-reverse
  • column
  • column-reverse

justify-content: defines how items are aligned along the main axis.

  • flex-start
  • flex-end
  • space-around
  • space-between
  • center

align-items: defines how items are aligned along the secondary or cross axis.

  • flex-start
  • flex-end
  • center
  • stretch

flex-wrap: tells us if the content should wrap, or try to fit on one line

  • nowrap
  • wrap
  • wrap-reverse

Practice Together

  1. Open up the index.html file in the practice folder of this repo
  2. Use flexbox to make the boxes centered in a column on the page
  3. Use flexbox to make the boxes in a column on the right side of the page
  4. Use flexbox to reverse the order of the boxes in a row in the vertical center of the page. All of the items should have even space around them.

Practice on Your Own:

Go to the superhero supply shop repo and follow the homework instructions!

Final Thoughts

Today we learned how we can use CSS to add style and layouts to our pages. Next week we’ll do our first big review project and make our own portfolio pages.

2019-spring-03-css-layout's People

Contributors

becsegal avatar megknoll avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.