Intro to HTML & CSS
FAQ's
Introductions
What will I take away from today?
HTML & CSS Fundamentals
After both classes, what will I be able to do?
- Read and understand HTML & CSS
- Know what you can do with HTML & CSS
- Have an understanding of how these technologies work together
- Have a great frame of reference for building simple websites
What technologies do web developers use to build websites?
The big 3:
HTML, CSS, JavaScript
I just want to blog, can't I just
use WordPress?
Sure! But the flexibility that comes with knowing how to code is invaluable.
Tools like WordPress can become constraining.
Terms & Concepts
What's the Internet?
Computers talking to each other.
(more computers)
What's a website?
Basically, a collection of text files in a folder on a computer somewhere.
What happens when I load a website?
- Server: a computer connected to the internet which provides files when requested (in our case, the files for our website)
- Client: a computer (your computer) connected to the internet, which asks a server for some files
2 main pieces involved in accessing a website
The flow of data
Scenario: you load facebook.com
Your browser uses the internet to ask Facebook's server for the website
Facebook's server sends the files back to your browser
Your browser reads the files, and interprets the code inside them to display the website (as Facebook intended for it to look) on your screen.
What is a browser?
What types of code make up a website?
- HTML - a language to tell a web browser how to lay out the structure and content of your website
- CSS - a language to tell a web browser how to style the content of your website (color, size, shape, etc)
- JavaScript - a programming language which allows you to add interactive features to your website
Who is involved in the process of creating websites?
- Designers
- Project Managers
- Developers
HTML
What is HTML?
-
A standardized markup language to structure the contents of web documents
- Describes the document to a web browser
Markup?
A language with specific syntax that instructs a web browser how to display a page.
<example> Some text on my webpage </example>
What does HTML markup look like?
Pieces of HTML markup are called "Tags"
Tags are invisible to the user
<p>Welcome to my site!</p>
Wrap all the content on your website in tags
Two matching tags are called elements.
Tags are just the parts with brackets.
Elements are the tags plus everything inside the tags.
HTML tags form the structure the browser needs to present your content to a viewer of your website.
Syntax is critical
<p Some text> </p>
<p>Some text</div>
<p> Some text
Missing end tag :(
Ensure all elements have an opening and closing tag
<p>Some text</p>
There are many possible tags
All tags are pre-defined
i.e. you'll need to learn what they are.
Some tags have specific uses
- <a> - only tag that can create a link to another page
- <img > - only tag that can display images on a page
Many are for general use
- <span> and <p> are usually used for text
- <div> is usually when you want to group elements in the same area
Some common HTML tags
<div> <span>Hi there!</span> <span>more text</span> </div>
Tags are often nested
Bare HTML Document
<!DOCTYPE html>
<html>
<head> </head>
<body> </body>
</html>
<!doctype html>
Tells the browser that this file has HTML in it.
<html>
Contains all HTML elements
<head></head>
Contains "meta" tags which provide general information about the content of the page
<body></body>
Contains all potentially visible content on the page.
A simple complete HTML page
<!DOCTYPE html>
<html>
<head>
<title> Dan's Website </title>
</head>
<body>
<h1> Hello world, here's a website </h1>
<p> by Dan </p>
</body>
</html>
Block elements
Block elements begin on a new line and flow down the page
Inline elements
Inline elements flow exactly like text does.
Common Elements
- paragraph (<p>)
- lists (<ul>)
- headings (<h2>)
- divs (<div>)
- links (<a>)
- spans (<span>)
- images(<img />)
HTML
- a header
- a sidebar
- a main area for content
- a footer
CSS
CSS
CSS
CSS
-
Size
-
Spacing
-
Color
- Position in the browser window
It would be pretty messy to have all of our CSS mixed into our HTML.
CSS - why?
<h1>Hello!</h1> +
h1 { color: red; }
CSS - how?
=
or
selector { property:value; property:value; }
Defining CSS Rules
selector{ property: value; property: value; }
One more piece of HTML...
Tags by themselves aren't
very useful.
Attributes
- Attributes let you assign names to the elements on your page.
- Attributes can be applied to all HTML elements
Two main attributes for styling
ID attribute: unique- can only be on one element
p {
color: red;
font-size: 14px;
}
#photo-gallery { width: 500px; height: 400px; }
Some example CSS Rules
text within it red, and the size of it 14 pixels"
500px wide, and 400px tall"
Back to attributes...
Attributes.
Selectors
an HTML element in order to apply styles to it.
You can group selectors!
CSS
dgribbin@me.com
slides.com/dangribbin
Wrap up
Want to learn more?
Tomorrow!
JavaScript
Don't worry, we'll take things easy.
JavaScript makes our websites truly interactive.
But we need to learn the absolute basics before we get there.
- A scripting language
- Not visible to a website user
- What makes it possible for a user to interact with the website and vice-versa
-
Used to create web applications you've used (Gmail, Google Maps, Facebook)
JavaScript is...
-
The best way to make your website interactive and rich.
-
All browsers use it.
- It's fast.
JavaScript - Why?
Variables
A letter or word that can store a value.
that are in a variable.
Variable names must start with a letter or an underscore.
Variables - why?
certain values in your code so you can access them later.
var firstName, lastName, age;
firstName = "Joe";
lastName = "Bean";
age = 27;
How to create a variable
var firstName ="Joe"; var lastName = "Bean"; var age = 27;
Or, in one step
var firstName = "Joe"; firstName = "Dan";
Changing a variable's value
you can change it.
var firstName = "Joe"; var strAge = "27";
var intAge = 27;
var yearOfBirth = 1985;
What's the difference between strAge and intAge? Type.
Types of variables:
Strings and Integers
integers (only numbers)
Numeric Operations
"27"+"16"; → "2716" 27 + 16; → 43
"hello" + "world"; → "helloworld"
Functions
A function defines a block of code
that can be reused.
Functions
-
Let you break your code into chunks
-
Make maintaining your code much easier
Something with a function...
What if we wanted to do the same thing many times in our code?
-
Write it again every time we need it
-
What if we wanted to change it?
-
What if we wanted to change it?
- Write it once and reuse it
function sayMyName(){
alert("Dan");
}
sayMyName();
Creating a function
Declare the function
Call it
Another example of a function
function addNumbers(){ var num1 = 1; var num2 = 2; var num3 = num1 + num2; alert(num3); }
Putting JavaScript on a web page
<script type="text/javascript"> alert("hello world!"); </script>
Ok, enough for now.
Some useful info about JavaScript!
-
jQuery
-
Dojo
-
YUI
-
ExtJS
$('#photo-gallery').show();
$('#photo-gallery').hide();
jQuery
Next week...
Brainery- Intro to Web 1
By Dan Gribbin
Brainery- Intro to Web 1
- 1,000