CSS and Styling

Lecture Overview

What is CSS and why do we use it?

CSS Syntax

CSS Selectors

Element Selectors

p {
    text-align: center;
    color: yellow;
}

Id Selectors

#headshot {
    background: green;
    border: 1px solid red;
}

Class Selectors

.projects {
    text-align: center;
}

Grouping Selectors

h1, h2, p {
    text-align: center;
    color: red;
}

Descendant Selectors

ul li {
    margin: 10px;
}

How to insert CSS

External Style Sheet

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

Internal Style Sheet

<head>
    <style>
        body { background-color: blue; }
        p { color: white; }
    </style>
</head>

Inline Style

<h1 style="font-size: 48px;">My headline</h1>

How CSS is applied

Cascading

p {
  color: red;
  font-weight: bold;
  font-size: 18px;
}

p {
  color: blue;
}
<p>I’m blue, 18px, and bold.</p>

Inheritance

p {
  color: red;
  font-weight: bold;
  font-size: 18px;
}

span {
  font-style: italic;
}
<p>I’m red, 18px, and bold.
  <span>I am those and also italic.</span>
</p>

CSS Specificity

Inline styles

<h1 style="color: #ffffff;">

IDs

#headshot {
    background: green;
    border: 1px solid red;
}

Classes, attributes, and pseudo-classes

.project{
    font-family: Tahoma;
    font color: #4F0E42;
}
a:hover{
    color: purple;
}

Elements and pseudo-elements

h2{
    font-family: Comic Sans, sans-serif;
    font color: #DFAEB4;
}

Specificity Chart

CSS Styling with Fonts, Size, and Colors

Font-family

body {
    /* A font family name and a generic family name */
    font-family: "Arial", sans-serif;
    font-family: "Times New Roman", serif;

    /* A generic family name */
    font-family: serif;
}

Difference Between Serif and Sans-serif

Font-Size

p {
    /* <length> values */
    font-size: 12px;

    /* <percentage> values */
    font-size: 80%;
}

Font

p {
  font: italic bold 12px "Arial", sans-serif;
}

Color

p {color: red;}

Background-Color

p {
    background-color: black;
    background-color: #000000;
    background-color: rgba(0,0,0);
}

Text-Align

h1 {
    text-align: center;
}

p {
    text-align: left;
}

.right {
    text-align: right;
}

div {
    text-align: justify;
}

A list of all the CSS properties