Skip to content

Commit 08328c7

Browse files
committed
Rework course 1 session 3
1 parent eab9053 commit 08328c7

8 files changed

+232
-142
lines changed

_sessions/c1s3/1_why_is_css_hard.md

+46
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
---
2+
title: What's hard about CSS?
3+
---
4+
5+
You've seen quite a bit of CSS now; it all seems quite straightforward - you write some css, tweak it 'til it looks good and you're done! In theory this is exactly how CSS works and is why CSS is brilliant.
6+
7+
<div style="display: block;margin-left: auto; margin-right: auto; width: 200px;">
8+
<img src="/assets/cat_pic.jpg" class='img-polaroid' width='200px'>
9+
</div>
10+
11+
Unfortunately, the realities are not quite so straightforward. Different browsers will render CSS with subtle differences. Take a look at the cat picture above. The styling is relatively simple - all we've done is add a border and a shadow. The following CSS will probably do this in your browser:
12+
13+
{% highlight css %}
14+
.img-polaroid {
15+
padding: 4px;
16+
border: 1px solid rgba(0, 0, 0, 0.2); /* transparent black border */
17+
box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
18+
}
19+
{% endhighlight %}
20+
21+
However, to get this effect in all browsers you need the following:
22+
23+
{% highlight css %}
24+
.img-polaroid {
25+
padding: 4px;
26+
background-color: #fff;
27+
border: 1px solid #ccc; /* grey border for browsers that can't do transparency */
28+
border: 1px solid rgba(0, 0, 0, 0.2); /* put the transparency after for browsers that do */
29+
-webkit-box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1); /* some browers only understand webkit box shadow */
30+
-moz-box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1); /* others need this */
31+
box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
32+
}
33+
{% endhighlight %}
34+
35+
**Just because your site looks good in Chrome, doesn't mean it will look good in Internet Explorer.** Making your site look good (or even presentable) in multiple browsers takes time, effort and experience.
36+
37+
### What else is hard about CSS?
38+
39+
About 5 years ago, 'all' you would have had to worry about is the cross-browser display issues. Since then, the mobile web has exploded and you have another (far more important) concern: how will your site look when viewed on a mobile?
40+
41+
Making webpages that look good when viewed at multiple different sizes is a whole new level of complexity.
42+
43+
### Should I just give up then?
44+
45+
You might be the sort of person who relishes this sort of challenge - if so, great! If not, help is at hand ...
46+

_sessions/c1s3/2_twitter_bootstrap.md

+109
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
---
2+
title: Twitter Bootstrap
3+
---
4+
5+
[Twitter Bootstrap](http://getbootstrap.com) is set of CSS (& Javascript) files, released by the makers of Twitter.
6+
7+
Twitter Bootstrap is a set of **ready-made CSS files** that provide solutions to **common presentation requirements** in a **cross-browser and responsive** way. To make use of Twitter Bootstrap, you need to do two things:
8+
9+
1. Link to the Twitter Bootstrap stylesheet in the `head` of your html page.
10+
2. Attach the relevant Twitter Bootstrap class to you html element.
11+
12+
### An example: making a stripy table
13+
14+
Suppose you want a Zebra-esque table like this fine specimen:
15+
16+
<table class='table table-striped'>
17+
<tbody>
18+
<tr>
19+
<td>I am a</td>
20+
<td>Zebra table!</td>
21+
</tr>
22+
<tr>
23+
<td>Look at my</td>
24+
<td>stripes.</td>
25+
</tr>
26+
<tr>
27+
<td>Do you find them</td>
28+
<td>beautiful?</td>
29+
</tr>
30+
<tr>
31+
<td>Do you find them</td>
32+
<td>mesmerising?</td>
33+
</tr>
34+
<tr>
35+
<td>Wooaahh ..</td>
36+
<td>.. such stripiness!</td>
37+
</tr>
38+
39+
</tbody>
40+
</table>
41+
42+
You have a look at the [Twitter Bootstrap table documentation](http://getbootstrap.com/css/#tables) and discover that you need to add the `table table-striped` class to the `<table>` tag:
43+
44+
{% highlight html %}
45+
<table class="table table-striped">
46+
...
47+
</table>
48+
{% endhighlight %}
49+
50+
This will apply the relevant CSS rules from the bootstrap CSS file. If you're interested, you can go into Developer Tools and view the rules that apply e.g.
51+
52+
{% highlight css %}
53+
/* from line 1950 of bootstrap.css */
54+
55+
.table-striped tbody tr:nth-child(odd) td,
56+
.table-striped tbody tr:nth-child(odd) th {
57+
background-color: #f9f9f9;
58+
}
59+
{% endhighlight %}
60+
61+
### Responsive design
62+
63+
**Responsive design** means designing your sites so that they look good on all screen sizes.
64+
65+
Twitter Bootstrap promotes a 'mobile first' philosophy, encouraging you to design your site so that it looks good at all sizes from the very beginning. It provides a lot of useful CSS that helps you to do this.
66+
67+
We're not really going to cover responsive design in depth in class, but the Bootstrap docs do a good job of explaining what's possible. Take a look at the [grid system](http://getbootstrap.com/css/#grid) as an example.
68+
69+
{% exercise %}
70+
The aim of the rest of this session will be to create the website for ["Sam's Sarnies"](http://code61.github.io/bootstrap_exercise/) using Twitter Bootstrap.
71+
72+
<ol markdown="1">
73+
<li markdown="1">
74+
Clone down the repository for the bootstrap exercise: [https://github.com/code61/bootstrap_exercise.git](https://github.com/code61/bootstrap_exercise.git)
75+
</li>
76+
<li markdown="1">
77+
Open `bootstrap_exercise/index.html` in your browser.
78+
</li>
79+
<li markdown="1">
80+
Go to the [Bootstrap](http://getbootstrap.com) website (it's hosted at github, like your `first_site`) and click the `Download Bootstrap` button (not the Download Source).
81+
</li>
82+
<li markdown="1">
83+
Unzip and copy the `dist` folder into the `bootstrap_exercise` folder.
84+
</li>
85+
<li markdown="1">
86+
Open `index.html` in Sublime Text and Chrome.
87+
</li>
88+
<li markdown="1">
89+
Add a link to the twitter bootstrap stylesheet into `index.html`
90+
91+
{% highlight html %}
92+
<link href='dist/css/bootstrap.css' rel='stylesheet'>
93+
{% endhighlight %}
94+
Note that you're using a document-relative link to a file two subfolders down.
95+
96+
</li>
97+
<li markdown="1">
98+
Refresh the page in Chrome. Notice how the fonts have changed.
99+
</li>
100+
<li markdown="1">
101+
Add the following line to the `head` section:
102+
103+
{%highlight html %}
104+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
105+
{% endhighlight %}
106+
as suggested in the `CSS / Overview` section of the [Bootstrap docs](http://getbootstrap.com/css/#overview-mobile).
107+
</li>
108+
</ol>
109+
{% endexercise %}

_sessions/c1s3/4_twitter_bootstrap.md

-36
This file was deleted.

_sessions/c1s3/5_bootstrap_layout.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ Bootstrap works on a grid layout, with 12 columns (by default). You can create a
4141
The number after the `col-sm-` determines how many of the 12 grid columns that page column takes up. The `sm` bit determines the width at which the columns will collapse on top of each other (which is useful when viewing your site on a phone). For more information see the [Grid system docs](http://getbootstrap.com/css/#grid).
4242

4343
{% exercise %}
44-
1. Add a `&lt; div class="container" &gt;` around the page content.
44+
1. Add a `div class='container'` around the page content.
4545
2. Create a row at the top of the page, with two columns, with the left twice as wide as the right. Put the `h1` in the left column and the `img src='images/sandwich.png' ` on the right.
4646
3. Create a row with three equal colums to hold each of 'The Buzz' `div`s.
4747
{% endexercise %}

_sessions/c1s3/6_more_bootstrap.md

+12-10
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,20 @@ Skim through the [typography section](http://getbootstrap.com/css/#type) of the
1717
Check out the [buttons section](http://getbootstrap.com/css/#buttons) (CSS > Buttons).
1818

1919
{% exercise %}
20-
1. Change the 'Send' button to a success button:
21-
22-
&lt;button class='btn btn-success' &gt;Send&lt;\button&gt;
23-
20+
<ol markdown="1">
21+
<li markdown="1">Change the 'Send' button to a success button:
22+
{% highlight html %}
23+
<button class='btn btn-success' >Send</button>
24+
{% endhighlight %}
2425
You might also need `btn-small` in the Recent Activity section.
25-
26+
</li>
27+
<li markdown="1">
2628
2. Make the social links at the bottom in to large buttons (we'll colour them later):
27-
28-
&lt;button class='btn btn-lg' &gt;Send&lt;\button&gt;
29-
29+
{% highlight html %}
30+
<button class='btn btn-lg' >Send</button>
31+
{% endhighlight %}
32+
</li>
33+
</ol>
3034
{% endexercise %}
3135

3236
### Images
@@ -38,5 +42,3 @@ Have a look at the [image section](http://getbootstrap.com/css/#images) of the B
3842
2. You can center the image by adding the [helper class](http://getbootstrap.com/css/#helper-classes-center) `center-block`.
3943
2. Change the main sandwich image into a `img-responsive`, as described in the [responsive images section](http://getbootstrap.com/css/#overview-responsive-images). Try resizing your browser and see how it changes size.
4044
{% endexercise %}
41-
42-
###

_sessions/c1s3/7_modifying_bootstrap.md

+58-44
Original file line numberDiff line numberDiff line change
@@ -10,55 +10,69 @@ If you're going to modify Bootstrap **don't touch the Bootstrap files**. Instead
1010

1111

1212
{% exercise %}
13-
14-
1. Create a file called `main.css` and write the following CSS:
15-
16-
#social-buttons button {
17-
color: white;
18-
}
19-
.btn-twitter {
20-
background-color: #00acee;
21-
border-color: #009ad5;
22-
}
23-
24-
.btn-facebook {
25-
background-color: #4868ac;
26-
border-color: #314776;
27-
}
28-
29-
.btn-pinterest {
30-
background-color: #b62f26;
31-
border-color: #b62f26;
32-
}
33-
34-
2. Link this file into the `head` of `index.html` **underneath your link to bootstrap**.
35-
3. What happens? Notice how in the first rule we've selected only those buttons that exist inside an element with `id=social-buttons`.
13+
<ol markdown="1">
14+
<li markdown="1">
15+
Create a file called `main.css` and write the following CSS:
16+
{% highlight css %}
17+
#social-buttons button {
18+
color: white;
19+
}
20+
.btn-twitter {
21+
background-color: #00acee;
22+
border-color: #009ad5;
23+
}
24+
25+
.btn-facebook {
26+
background-color: #4868ac;
27+
border-color: #314776;
28+
}
29+
30+
.btn-pinterest {
31+
background-color: #b62f26;
32+
border-color: #b62f26;
33+
}
34+
{% endhighlight %}
35+
</li>
36+
<li markdown="1">
37+
Link this file into the `head` of `index.html` **underneath your link to bootstrap**.
38+
</li>
39+
<li markdown="1">
40+
What happens? Notice how in the first rule we've selected only those buttons that exist inside an element with `id=social-buttons`.
41+
</li>
42+
</ol>
3643
{% endexercise %}
3744

3845
### Changing the background
3946

4047
{% exercise %}
41-
1. Change the background of the `jumbotron` to be the image `fruit-and-veg.png` by adding the css
42-
43-
.jumbotron {
44-
min-height: 600px;
45-
background-image: url('images/fruit-and-veg.jpg');
46-
background-size: cover;
47-
background-attachment: fixed;
48-
}
49-
50-
2. This doesn't look quite right. The problem is that the jumbotron is it is inside the `div class="container"`. You can change this by moving it inside:
51-
52-
&lt;div class="jumbotron"&gt;
53-
&lt;div class="container"&gt;
54-
55-
&lt;/div&gt;
56-
&lt;/div&gt;
57-
58-
Similarly you will now need to create new `container`s inside the `div id="buzz"` and `div id="mission"`.
59-
60-
3. Change the background color of the `mission` section to `rgba(32, 35, 41, 0.9)` and the font colour to `#ddd`
61-
48+
<ol markdown="1">
49+
<li markdown="1">
50+
Change the background of the `jumbotron` to be the image `fruit-and-veg.png` by adding the css
51+
{% highlight css %}
52+
.jumbotron {
53+
min-height: 600px;
54+
background-image: url('images/fruit-and-veg.jpg');
55+
background-size: cover;
56+
background-attachment: fixed;
57+
}
58+
{% endhighlight %}
59+
</li>
60+
61+
<li markdown="1">
62+
This doesn't look quite right. The problem is that the jumbotron is it is inside the `div class='container'`. You can change this by moving it inside:
63+
{% highlight html %}
64+
<div class="jumbotron">
65+
<div class="container">
66+
67+
</div>
68+
</div>
69+
{% endhighlight %}
70+
Similarly you will now need to create new `container`s inside the `div id='buzz'` and `div id='mission'`.
71+
</li>
72+
<li markdown="1">
73+
Change the background color of the `mission` section to `rgba(32, 35, 41, 0.9)` and the font colour to `#ddd`
74+
</li>
75+
</ol>
6276
{% endexercise %}
6377

6478

0 commit comments

Comments
 (0)