CSS Box Model
CSS Box Model
CSS
Box Model
Table of Contents
Goal of the day ............................................................................................................................ 3
The main goal is to control the design of the web pages to make them more attractive1. After
completing the lab, you will be able to:
• Part I: Finish the activity started in Lecture 4 (we will focus on option b) + Kahoot!
• Part II: Have fun with CSS Diner while you get hands-on experience working with
selectors.
• Part III: Follow the instructions to change the heroes’ pages.
• Part IV: Upload all your exercises from Lab4 to your Folk Site.
• https://developer.mozilla.org/en-US/docs/Web/CSS/Child_selectors
• https://www.w3schools.com/html/html_classes.asp
• https://www.w3schools.com/css/css_boxmodel.asp
• https://www.w3schools.com/cssref/pr_text_text-align.asp
• https://developer.mozilla.org/en-US/docs/Web/CSS/vertical-align
• https://www.w3schools.com/cssref/pr_class_display.asp
1 Attractive: Ok, I know, the term "attractive" may be quite subjective, so let's just accept this
statement as true; even if the final result does not look very nice from your point of view... Beauty
canon over time :-S
PART I: Lecture’s activity + Kahoot!
Use the solution from the first part of the activity (https://s.ntnu.no/l4a1s). Download the
screenshots from https://s.ntnu.no/intro-css-2-options.
Student activity
Use code from previous activity:
• Observe screenshot for option b and make a list of changes you observe
• Modify the files to implement the page you see in the screenshot
• Upload to your folk site
• (optional) share the link in teams (we look at a couple of the solutions and discuss
them)
Exercise 1.1
Create a new CSS-file (“style.css”) and store it in the root folder. Then, link it to the file
“heroes/ant-man/index.html”.
The card is divided in two columns. Give the first <div> a class called “left”, and the second a
class called “right”
Can you reuse CSS rules and override them to achieve the expected result? How?
Exercise 1.4
Find the <aside> for Ant Man’s best friend. Give this <aside> the same as in exercise 1.3. The
result should look like this:
Exercise 1.5
Give all the other hero pages the same styling as in the exercises above.
Groot:
Hulk:
Iron Man:
Rocket Racoon:
If you have completed 100% of the task, CONGRATULATIONS! It is not easy if you have never
done it before!
Exercise 2 – DRY!
We want to change the background colour of the navigation menu to black.
Exercise 2.1
We need to change the background colour of the header as well as the colour of the text.
Open all the index.html files, find the <style> tag in the <head> and locate the CSS rule with
the selector #header.
DRY (don’t repeat yourself) is one of the most famous principles of software development
and we will use it here to improve our current code.
Exercise 2.3
Finally, we will make the navigation menu a bit more readable.
• Find the proper CSS rule in “style.css” to config the <li> inside the <nav>
• Add a margin of 0.5em to the right of each <li>
• Save the page and check the changes
Before:
After:
Exercise 2.4 (bonus)
We are done with today’s tasks but here you have a bonus exercise showing a teaser for
pseudo-elements (more in future classes).
• Open “style.css” and paste the following CSS rule before the rule with the selector
“#header a”. Save the changes and check the results.
font-weight: bold;
color: yellow;
Double check you are following the naming conventions2 for you learn in the previous.