DTC 355

Module Overview:

Week 5 — Cascading Style Sheets (CSS)

This week we will explore how to apply styles to our websites using CSS. Specifically, we will look at different ways to adding stylesheets to our HTML, selectors like IDs and classes, "the cascade", inheritance, specificity, and applying specific common CSS properties.

Content

Applying CSS

There are 3 ways to apply CSS: inline, embedded, and externally.

Inline

Inline stlyes can be applied at the element level in the HTML document by adding the "style" attribute. While this can be handy in a pinch or when testing, it is not best practice for applying styles across an entire site.

<section style="border:1px solid red;"></section>

Embedded

Embedded styles are applied inside the head. This can be handy when dealing with a single page, but removes the ability to create global styles that work across an entire site.

<head>
    <style>
        section {
              border: 1px solid red;
         }
    </style>
</head>

External

Styles can also be applied through an external CSS file that is linked in the HTML file. This gives us the greatest amount of flexibility and ability to control the entire website's CSS on every page. This will be the primary way we apply styles in this class.

<head>
    <link rel="stylesheet" type="text/css" href="css/styles.css">
</head>

Format:
selector {
    property: value; }

Examples:
section {
    color: #ffffff;
}

#hero {
    background-color: rgb(0,0,0);
}

Selectors

  • name element: h1, p
  • name class or id: .stanza, #bio
  • context: #bio img, .stanza h3
  • pseudo-classes: p::first-letter, p:first-of-type, p:first-of-type:first-letter
  • link-styles: a:link, a:hover

CSS Principles

  • The cascade
  • Inheritance
  • Specificity
  • !important

CSS Units

  • Zero: 0
  • Pixels: 50px
  • Percentages: 50%
  • Em: 1.15em
  • Rem: 2rem
  • Viewport: 100vh or 100vw

Formatting Text

  • color
  • font-family
  • font-size
  • font-weight
  • font-style
  • text-decoration
  • text-transform
  • text-align
  • letter-spacing
  • line-height
  • text-shadow

Display Property

When we need to change the display behavior of an element, perhaps to change an inline element to a block level element or to hide an element, we can use the CSS display property.

display: block, inline, none, inline-block, (flex, grid)

Web Color

  • Hexidecimals: #000000
  • RGB: rgb(0,0,0)
  • RGBA: rgba(0,0,0,1)

Assignments

Due:Feb 13

Codeacademy: Learn CSS: Flexbox and Grid

  • Complete the Learn CSS: Flexbox and Grid
  • After completing the course, navigate to your user profile.
  • Take a screenshot of your profile screen that includes both your username and course completion.
  • If the course provides a certificate to completing that includes your name, you may use that instead.
  • In Slack, submit your screenshot or certificate in the turn-in thread.
  • Partial work is not accepted for Codeacademy learning.

Due:Feb 16

Explainer CSS, part 1

Using your prototype, write CSS to begin to apply your design to your HTML.

The section will not be graded on the quality of your design, but on the quality of your CSS code and how well you have applied it to your HTML. Your design will not be complete at this stage. That is okay.

  • In your 'explainer' folder, create a new folder and name it 'css'
  • In your text editor, create a new file and call it 'reset.css', then save it to the 'css' folder in your 'explainer' folder
  • Copy and paste the Eric Meyers CSS reset into the 'reset.css' file
  • Create another new file and call it 'styles.css', then save it to the 'css' folder in your 'explainer' folder
  • Link both stylesheets in the head of your HTML
  • In the 'styles.css' file, begin writing the CSS for your website. Add any neccessary IDs or classes to your HTML as you go
  • You should add a minimum of 16 different CSS properties for this phase
  • If your design has columns or content sitting side by side, you will this step for now. We will be applying layout & positioning CSS next week
  • Push your changes to GitHub.
  • Add your name in the Slack turn-in.