Skip to Main Content

TCLC Summer Camp 2017

CSS With Floaties On

CSS targets HTML tags with description

Comparing HTML tags to CSS selectors
Target this HTML tag... with this CSS selector
<div>...</div> div
<p>...</p> p
<hl>...</hl> h1
<ul>...</ul> ul

Anatomy of CSS

Note the use of curly brackets, colons, and semi-colons for separating the elements...

selector {
  property: value;
  property2: value2;
}
  • Selector =  The HTML tag you are targeting for description.
  • Property = The aspect of the selector you want to change.
  • Value = The details of the change.
  • Each property: value combination is called a declaration. 

Examples

Let's say we want a certain amount of spacing around our page header (h1). This is done with the margin property. There are two ways of describing this in CSS. First the fully described method...

h1 {margin-top: 5px;
margin-right: 10px;
margin-bottom: 5px;
margin-left: 10px;}

Many CSS properties also have a shorthand method for values...

h1 {margin: 10px 20px 10px 20px;}

Which translates as...

h1 {margin: top right bottom left;}

The numbers are always clockwise from the top -- top/right/bottom/left

For further exploration... if values repeat, the values statement can be shortened even further.

This CSS code would now describe every single H1 in the website in the same way. But what if we want them to look in different ways in the same site?

Contact information goes here