Cascading Style Sheets (CSS) - Unit 1

Professional Learning Notes

Introduction to CSS

CSS (Cascading Style Sheets) describes how HTML elements are displayed. HTML provides structure while CSS provides presentation.

Analogy: HTML = Bricks & Walls, CSS = Paint & Decoration.

Ways to Apply CSS

  1. Inline CSS
  2. Internal CSS
  3. External CSS (Recommended)
<h1 style="color:red">Inline CSS</h1>

<style>
h1{color:blue;}
</style>

<link rel="stylesheet" href="style.css">

Basic CSS Syntax

selector{
 property:value;
}

Basic CSS Selectors

SelectorExamplePurpose
Elementh1{color:red;}Styles all matching elements
ID#special{...}Styles unique element
Class.box{...}Styles multiple elements

Span is an inline element used to style a small portion of text.

<p>This is a <span style="color:red;">red</span> word.</p>

Important CSS Properties

PropertyPurpose
colorText color
background-colorBackground color
font-sizeText size
font-familyFont family
text-alignAlignment
borderBorder
width/heightDimensions
margin/paddingSpacing
displayLayout
positionPositioning
border-radiusRounded corners

Colors

h1{
 color:white;
 background:blue;
 border:solid red 5px;
 border-radius:10px;
}

Display Property

Defines how an element is displayed.

ValueDescription
blockNew line, full width
inlineSame line
inline-blockInline with width/height
noneHidden
flexOne-dimensional layout
gridTwo-dimensional layout

Position Property

ValuePurpose
staticDefault
relativeRelative to original position
absoluteRelative to nearest positioned ancestor
fixedFixed during scrolling
stickyActs normal then sticks
Removing an element from the normal flow means other elements occupy its original space.

List & Table Properties

list-style-type: disc, circle, square, none

ul{
 list-style-type:square;
}

border-collapse merges adjacent table borders.

table{
 border-collapse:collapse;
}

Background Images

body{
 background-image:url("image.jpg");
 background-repeat:no-repeat;
 background-size:cover;
}

Other Properties

img{ border:groove 10px blue; }
button{ cursor:pointer; }
.hidden{ visibility:hidden; }