1 of 48

#INCLUDE

Create For Community

Tech Cohort Workshop 2

INCLUDE

2 of 48

Agenda

Today we hope to cover the following topics:

  • Navigate sandbox/practice repo
  • Overview of Units + Tags
  • Quick Review of Padding + Margin + Border
  • Quick Review of Responsiveness
  • Block-level VS Inline Styling
  • In-depth on FlexBox
  • Positioning
  • CSS Transitions

INCLUDE

3 of 48

INCLUDE

HTML Tags

4 of 48

Using the right tags helps with Search Engine Optimization (SEO)

Please refer to the links for in depth descriptions :)

  • Codebrainer Blog
  • W3Schools

INCLUDE

5 of 48

INCLUDE

HTML Attributes

6 of 48

Attributes

Attributes provide additional information about HTML elements and are always specified in the start tag. They are in ‘name=value’ pairs

Examples we commonly use:

  • <img src=’’>: define path to image
  • <img alt=’’> : accessibility name for image
  • <div id=’’> : species an id & must be unique
  • <a href=’’> : specifies a link
  • <div onClick=’’> script to run when clicked

INCLUDE

7 of 48

INCLUDE

CSS Units

8 of 48

Absolute Units

Absolute units specify a FIXED length value and won’t change if screen size does.

Some examples include:

  • px (Only one we use; multiples of 8px)
  • pc
  • cm
  • mm

We typically use px for width, height, borders, paddings, and margins.

INCLUDE

9 of 48

Relative Units

Simply put, relative units are relative to other containers/boxes and are better for responsiveness.

Some examples include:

  • rem(the one we want to use)
  • em
  • %
  • fr

We will be using rem for font-size, NEVER px!

% can also be used for widths and heights

INCLUDE

10 of 48

Viewport Units

Viewport units are easy to understand and represent the size of the viewable screen (your browser window).

Some examples include:

  • vh (okay)
  • vw (NEVER use!)
    • Reason: Scrollbar has extra width & vw can generate that extra space, which pushes elements off screen

INCLUDE

11 of 48

INCLUDE

Padding + Margin + Border

12 of 48

Padding

Padding creates space between an element’s content and its border.

  • SPACE WITHIN THE BOX

padding-top: 50px;

padding-right: 30px;

padding-bottom: 50px;

padding-left: 80px;

padding: 15px; //apply to all four sides

padding: 8px 16px; //top & bottom, left & right

padding: 8px 4px 4px; //top, left & right, bottom

INCLUDE

13 of 48

Margin

Margin creates space between element and other elements

  • SPACE OUTSIDE OF BOX

margin-top: 50px;

margin-right: auto; //will push element left

margin-bottom: 50px;

margin-left: 80px;

margin: 15px; //apply to all four sides

margin: 8px 16px; //top & bottom, left & right

margin: 8px 4px 4px; //top, left & right, bottom

INCLUDE

14 of 48

Border

Border creates lines that surround the box

border: solid; //style

border: 2px dotted; // width|style

border: medium dashed green; // width|style|color

Can customize each side of the border (left, right, top, and bottom)

INCLUDE

15 of 48

Box-Sizing

Box-sizing sets the total width and height.

box-sizing: content-box; //width and height ONLY include content

box-sizing: border-box; // width and height include the content, padding, and border, but NOT margin

INCLUDE

16 of 48

Overflow Property

INCLUDE

Overflow specifies whether to clip the content or to add scrollbars when the content of an element is too big to fit in the specified area.

overflow: visible;

overflow: hidden;

overflow: scroll;

overflow: auto;

17 of 48

INCLUDE

Hands-On Example Time

18 of 48

INCLUDE

Block & Inline Elements

19 of 48

Display Values

INCLUDE

Every HTML element has a default display value:

  • Block
    • always starts on a new line
    • takes up the full width available
  • Inline
    • do NOT start on a new line
    • only takes up as much width as necessary

How can we modify this so block-level elements can become in-line?

20 of 48

Display Property

INCLUDE

One solution is to change the display property, but what if we want to modify layout and spacing for a container’s children all at once?

21 of 48

INCLUDE

Flexbox

22 of 48

What is it?

INCLUDE

Flexbox is a one-dimensional layout method for arranging items in rows or columns. Items flex (expand) to fill additional space or shrink to fit into smaller spaces.

23 of 48

Terminology

INCLUDE

The parent container is referred to as the flex-container while the children are called flex-items.

Flex-containers can also be flex-items if encased in another container.

24 of 48

Flex-direction

INCLUDE

Items within a flex container can be placed in a row or a column (and reversed).

By default, flex-direction is set to row.

display: flex;

flex-direction: row;

25 of 48

Axes

INCLUDE

Flex containers have two axes, the main axis and the cross axis that change depending on the flex-direction

Row -> main-axis is horizontal, cross-axis is vertical

Column -> main-axis is vertical, cross-axis is horizontal

26 of 48

Positioning Items

INCLUDE

Positioning items along the main-axis involves using the justify-content property.

div {

display: flex;

justify-content: center;

}

27 of 48

Positioning Items

INCLUDE

Positioning items along the cross-axis involves using the align-items property.

div {

display: flex;

align-items: center;

}

28 of 48

Gap

INCLUDE

If you want to space your flex-items by a specific amount, you can use the gap, row-gap, and column-gap properties.

div {

display: flex;

row-gap: 40px;

col-gap: 20px;

}

29 of 48

Grow, Shrink, Basis

INCLUDE

These properties are applied to the flex-items (children) rather than the flex-container (parents). They define how an item should take up extra space.

.flex-item {

flex-grow: 1;

flex-shrink: 1;

flex-basis: 200px;

flex: 1 1 200px; //grow | shrink | basis

}

30 of 48

INCLUDE

Hands-On Example Time

31 of 48

INCLUDE

Positioning

32 of 48

What is it?

INCLUDE

Allows control over how elements are placed and how they behave in the document flow.

Types:

(default) (important) (important) (lowkey fun) (big no-no)

div { position: absolute; }

33 of 48

relative vs absolute

INCLUDE

  • Elements are offset from their normal (default) positions.
  • The element still takes up space in the document flow.

  • Positioned relative to the nearest ancestor with a specified position property.
  • Elements are taken out of the document flow.

34 of 48

INCLUDE

Offset defined using properties top, bottom, left, right.

1

2

3

5px

30%

-25px

+ve -ve

+ve

-ve

10px

-ve

+ve

-ve +ve

35 of 48

INCLUDE

Hands-On Example Time

36 of 48

INCLUDE

Media Queries

37 of 48

Media Queries

INCLUDE

Used to conditionally apply styles.

A media query computes to true when the media type (criteria) matches the device in use.

One HTML-CSS for all devices: code and style for one, implement changes for others.

Example:

If the screen size is 700px or less, change flex direction.

.teal_boxes { //laptop/ipad dimensions

display: flex;

flex-direction: row;

}

...

@media screen and (max-width: 700px){

.teal_boxes { //for mobile phones

flex-direction: column;

}

}

38 of 48

Media Queries

  • Part of CSS
  • Used for “Responsive Design”
    • Important because people browse websites on all sorts of devices
  • Specifies when to change CSS properties depending on criteria (usually screen size)
  • Syntax:

@media screen and (max/min-width: size){}

Select any elements/classes you want to change within just like a normal CSS selector!

INCLUDE

39 of 48

INCLUDE

CSS Transitions

40 of 48

Transformations & Transitions

INCLUDE

We don’t expect you guys to memorize any of this but it’s good to know what CSS is capable of.

Follow along with the interactive guides:

https://www.joshwcomeau.com/css/transforms/

https://www.joshwcomeau.com/animation/css-transitions/

41 of 48

INCLUDE

Create a Branch

42 of 48

INCLUDE

Take-Home Assignment

43 of 48

Assignment: “About me” Page!

  • For git CLI practice try this and take a peek at the CSS Selectors Game
  • Using HTML: HTML Elements + Structure,
  • Before you start, make sure you think about the box model and how you want to implement structure on your page
  • When you’re ready, jump right in!
    • Don’t worry about making it too nice, but if you want to it’ll be great practice

INCLUDE

44 of 48

“About me” Page Inspo

INCLUDE

45 of 48

GitHub

  • Our expectations for GitHub usage:
    • NEVER work directly on main, ALWAYS create branches
    • Pull early (especially before you begin coding!)
    • Commit early, commit often (not after 100+ lines of code)
    • Push often (we want to see your progress)
    • DO NOT push into main, create Pull Requests (PR’s)

INCLUDE

46 of 48

Resources

INCLUDE

47 of 48

INCLUDE

Thanks for Listening!!

48 of 48

What To Turn In

INCLUDE

You will be in charge of creating the footer + skills section of your portfolio page. We will show you how to use react-icons. Skeleton code has been provided for you but these are basic templates, so get creative & add more content! AIM TO MAKE IT RESPONSIVE!!

Figma

npm install react-icons --save