Class 2
Girl Develop It is here to provide affordable and accessible programs to learn software through mentorship and hands-on instruction.
Some "rules":
Thank you to our wonderful TAs!
Course website: http://anything.codes
Instructor contact info: lizs@girldevelopit.com
Your Content
+ HTML: Structure
+ CSS: Presentation
= Your Website
A website is a way to present your content to the world, using HTML to structure that content, and CSS to make it look good.
All colored text, positioning, sizes
<p>This paragraph should have red text.</p>
p {
color: red;
}
This paragraph should have red text.
Without CSS, your HTML pages would look boring ☺
selector {
property: values;
}
You can add multiple property-value pairs to a rule, each ending with a semicolon:
body {
color: lightblue;
background-color: black;
text-transform: uppercase;
}
Just like HTML, CSS ignores whitespace. All you need is for each rule to be in the correct format.
Best: ✔
p {
font-size: 22px;
text-align: center;
color: red;
}
Decent:
p{font-size:22px;text-align:center;color:red;}
Not-so-great:
p {
font-size:22px;
text-align : center;
color: red;
}
The base format of a rule is selector{property:value;}
It doesn't matter where whitespace goes, as long as the format is correct
3 ways
1. Inline
<p style="color:red;font-size:12px;">Some text.</p>
2. Embedded
<head>
<style type="text/css">
p {
color: red;
font-size: 12px;
}
</style>
</head>
3. External
<head>
<link rel="stylesheet" href="css/styles.css" />
</head>
3. External
Now we can begin styling!
Enter the element's tag name to target those elements:
p {
color: aqua;
}
p { } in CSS corresponds to <p></p> in HTML
The following selects all image elements:
img {
width: 600px;
}
img { } in CSS corresponds to <img /> in HTML
The color property changes the color of the text.
p {
color: red;
color: #ff0000;
color: rgb(255, 0, 0);
color: rgba(255, 0, 0, 0.7);
}
Options:
There are 140 reserved color names, including: black, blue, aqua, fuchsia, grey, green, lime, maroon, navy, olive, purple, red, and teal
See a full list »
The background-color property changes the color of the background
body {
background-color: black;
background-color: #000000;
background-color: rgb(0, 0, 0);
background-color: rgba(0, 0, 0, 0.7);
}
To target elements that are descended from another element, use a selector for the ancestor, then a space, then a selector for the descendant:
HTML:
<div>
Buy one get one
<strong>free</strong>
<p>
Offer valid
<strong>today</strong>
only
</p>
</div>
CSS:
div strong {
background-color: yellow;
color: blue;
}
Result:
Offer valid today only
Let's get stylin'
The font-family property defines which font is used
body {
font-family: Helvetica;
font-family: "Helvetica Neue";
font-family: Arial;
font-family: sans-serif;
}
If a font name is more than one word, it goes in quotation marks (like "Helvetica Neue").
Preferred ✔: Use a prioritized list. The page will load whichever font it recognizes first in the list:
body {
font-family: Helvetica, "Helvetica Neue", Arial, sans-serif;
}
Helpful site: CSSFontStack.com »
The font-size property specifies the size of the font.
p {
font-size: 16px;
font-size: 1em;
font-size: 100%;
}
Options include:
The default <body></body> size is 16px
Usually 16px = 1em = 100%
px versus em versus %
Pixels are a fixed-size unit — they don't change relative to their ancestor's font size. Percentages and "em"s are scalable and relative to their ancestor's font size.
The font-style property sets italic styling for text
The font-weight property sets text boldness
h4 {
font-style: normal;
font-style: italic;
font-style: oblique;
font-weight: normal;
font-weight: bold;
}
Use font-variant to make small-caps text
h1 {
font-variant: normal;
font-variant: small-caps;
}
An Example of 'small-caps' Text
The line-height property specifies text line height
p {
font-size: 10px;
line-height: 20px;
line-height: 2em;
line-height: 2;
}
Use text-transform to make text lowercase, capitalized, or uppercase
h1 {
text-transform: lowercase;
text-transform: capitalize;
text-transform: uppercase;
}
an Example of 'lowercase' Text
an Example of 'capitalize' Text
an Example of 'uppercase' Text
The text-align property aligns text to the left, right, or center
p {
text-align: left;
text-align: right;
text-align: center;
}
Let's style some text elements with:
Enter a period (.)
followed directly by the class attribute's value
to target all elements with that class:
HTML:
<p class="warning">Lorem ipsum</p>
<span class="warning">Dolor sit amet</p>
CSS:
.warning {
color: red;
}
Result:
Lorem ipsum
Dolor sit amet
.red { } in CSS corresponds to <tagname class="red"></tagname> in HTML
Using Multiple Classes
Assign multiple classes to an element by separating each class with a space in the HTML:
HTML:
<p class="green bordered">Cowabunga!</p>
<p class="green">said Michaelangelo</p>
CSS:
.green {
color: green;
}
.bordered {
border-width: 3px;
border-style: dashed;
border-color: fuchsia;
}
Result:
Cowabunga!
said Michaelangelo
Since the first <p></p> element is targeted by both the .green and .bordered CSS rules, it is both green and bordered.
To target elements with a specific ID, use the hashtag (#), followed by the ID attribute's value:
HTML:
<div id="featured">
<a href="result1.html">
The One Featured Search Result's Title
</a>
<p>
A description of this search result
</p>
</div>
CSS:
#featured {
background-color: #F5E17F;
}
You can assign multiple classes to an element, but ...
ID should only apply to one element on the page
Why? IDs are unique
A Practical Example
Using Classes or IDs
The descendant and ancestor selectors don't have to be tag names; they can be classes, IDs, etc.
HTML:
<ul id="intro">
<li>
We are an
<span class="fancy-text">amazing</span>
team of developers
</li>
<li>
Located in
<span class="fancy-text">beautiful</span>
Cambridge, MA
</li>
</ul>
CSS:
#intro .fancy-text {
background-color: yellow;
color: blue;
font-style: italic;
}
Result:
To select an element with a specific class and tag name, use the tag name, followed by a period (.), then the class attribute's value:
HTML:
<p class="red">Lorem ipsum</p>
<span class="red">Dolor sit amet</span>
CSS:
span.red {
color: red;
}
Result:
Lorem ipsum
Dolor sit amet
Make sure there are no spaces in between your tag name, period, and class!
Why are these three rules so different?
.class div {
color: red;
}
div .class {
color: green;
}
div.class {
color: orange;
}
What does the cascading in Cascading Style Sheets mean?
Styles "cascade" down until changed
HTML:
<p>Paragraph 1</p>
<p class="red">Paragraph 2</p>
<p class="red" id="special">Paragraph 3</p>
CSS:
p{
color: blue;
font-family: Impact;
}
.red{
color: red;
}
#special{
font-family: Arial;
}
Result:
Paragraph 1
Paragraph 2
Paragraph 3
Coding Page Layouts — Beyond The Basics
We'll also start working on our project!
If you haven't already, try to use each of the properties and selectors discussed in the lecture today and save your HTML and CSS files.