Documente Academic
Documente Profesional
Documente Cultură
css: selectors,
classes & ids
HTML + CSS Workshop
Instructor: Erika Tarte
Rhode Island School of Design
Spring 2011
webpage
from web content to webpage
In addition to content, webpages contain hidden information that help browsers interpret
structure, meaning, style, interactions, etc.
Most of the visible information takes place in the body of the HTML document, while most
of the hidden formation happens in the head of the HTML document.
<html>
<head>
<title>Document Title</title>
</head>
<body>
...
</body>
</html>
css
what’s css?
Purpose
Format
Inline Styles
Internal styles
External styles
Cascading
style rules are applied in order
last definition takes precedence over the first
Order of priority
1 browser default lowest priority
2 external styles
3 internal styles
4 inline styles highest priority
linking a css file to your html file
The only change in the HTML file is to add a line of code at the top:
You can name the file anything you want (webstyles.css, printstyles.css, awesome.css)
Include the <link> tag just before the </head> tag in your HTML.
basic html webpage w/ link to css file
<html>
<head>
<title>Document Title</title>
</head>
<body>
...
</body>
</html>
linking your first file demo
2 Add this line to your HTML, right before the </head> tag:
There are many style properties, don’t worry about memorizing them!
selector {
property: value;
property: value;
}
css syntax
property: value;
property: value;
}
css syntax
selector {
property: value; Propert y is a display characteristic you are writing a
rule for. Each selector can have multiple properties, and
property: value; some selectors have very specif ic properties.
}
css syntax
selector {
property: value; Value is the display characteristic that you want to apply
to the property
property: value;
}
css syntax
sandwich {
cheese: cheddar;
bread: rye;
condiment: mustard;
condiment-style: spicy-brown;
}
css syntax
h1 {
font-family: Helvetica;
font-size: 36px;
font-weight:bold;
text-transform:uppercase;
color:#000000;
}
classes & ids
html class & id attributes
These 2 attributes give you more control over the elements while using CSS
.button {
font-size: 12px;
color: #ff0000;
text-decoration: none;
}
#button1 {
font-size: 12px;
color: #ff0000;
text-decoration: none;
background-color: #ffff00;
}
html class & id attributes
.button {
font-size: 12px;
color: #ff0000;
text-decoration: none;
}
#button1 {
font-size: 12px;
color: #ff0000;
text-decoration: none;
background-color: #ffff00;
}
css class & id selectors
.button {
font-size: 12px;
color: #ff0000;
text-decoration: none;
}
#button1 {
font-size: 12px;
color: #ff0000;
text-decoration: none;
background-color: #ffff00;
}
css class & id selectors
.button {
font-size: 12px;
color: #ff0000;
text-decoration: none;
}
#button1 {
background-color: #ffff00;
}
Color
color values
hexadecimal or “hex"
encoded value of rgb
black: #000000
white: #FFFFFF
rgb value
hexadecimal (hex) value
css property: color
h1 {
color: rgb(255,255,255);
color: #ffffff;
}
css property: background-color
h1 {
color: #ffffff;
background-color: #000000;
}
typography
fonts
Browsers only display fonts installed on the user’s computer (with some recent exceptions)
h1 {
color: #ffffff;
background-color: #000000;
font-family: Akkurat, Helvetica, sans-serif;
}
css property: font-size
h1 {
color: #ffffff;
background-color: #000000;
font-family: Akkurat, Helvetica, sans-serif;
font-size: 72px;
}
css property: font-weight
h1 {
color: #ffffff;
background-color: #000000;
font-family: Akkurat, Helvetica, sans-serif;
font-size: 72px;
font-weight: normal;
}
css property: letter-spacing
h1 {
color: #ffffff;
background-color: #000000;
font-family: Akkurat, Helvetica, sans-serif;
font-size: 72px;
font-weight: normal;
letter-spacing: 4px;
}
css property: text-transform
h1 {
color: #ffffff;
background-color: #000000;
font-family: Akkurat, Helvetica, sans-serif;
font-size: 72px;
font-weight: normal;
letter-spacing: 4px;
text-transform: uppercase;
}
ONE LAST INGREDIENT
spans & divs
They give you more control over the presentation layer of your website
<div id=”header”>
<h1>Name of Website</h1>
</div>
<div id=”articles”>
<h2>Article Title</h2>
<p>Paragraph of text</p>
</div>
spans & divs
<div id=”header”>
<h1>Name of Website</h1>
</div>
<div id=”articles”>
<h2>Article Title</h2>
</div>
spans & divs
<div id=”header”>
</div>
<div id=”articles”>
<h2>Article Title</h2>
</div>