|
| 1 | + |
| 2 | + |
| 3 | +# Module Exercise: HTML & CSS |
| 4 | + |
| 5 | +## Learning Goals |
| 6 | + |
| 7 | +In this exercise, the goal is to apply as many as possible of the concepts you've just learned: |
| 8 | + |
| 9 | +- when and how to use different HTML tags, |
| 10 | +- how to structure HTML page and add the content to it using *block and inline elements*, and |
| 11 | +- how to style it. |
| 12 | + |
| 13 | +## Getting started |
| 14 | + |
| 15 | +Follow these **[guidelines](https://docs.google.com/presentation/d/1I7-9zlELCSTqDevrfEfi_S6bf0BoByqOPqMw6QWUDgc/edit?usp=sharing)** on how to *start and hand in* the exercise so your TAs can check it. |
| 16 | + |
| 17 | + |
| 18 | +## Instructions |
| 19 | + |
| 20 | +### Introduction |
| 21 | + |
| 22 | +In this exercise, you will clone the landing page of **[NPM](https://www.npmjs.com/) website**. NPM stands for a Node Package Manager, and you will be using it heavily throughout this course. |
| 23 | + |
| 24 | +Our goal is to get as close as possible to this: |
| 25 | + |
| 26 | + |
| 27 | + |
| 28 | + |
| 29 | + |
| 30 | + |
| 31 | +You can see the larger version of this picture [here](https://s3-eu-west-1.amazonaws.com/ih-materials/uploads/upload_7c45ec577a3e16793ae4e0abfeb80df9.png). If you're struggling to see the details, feel free to zoom in to 200%. |
| 32 | +Although it doesn't look too complicated, we will have to apply quite a few styles on our web page: set a background color on different elements, set a font weight (bold, normal), and position elements using our newly acquired skills in flexbox. |
| 33 | + |
| 34 | +We will divide our work into two parts: |
| 35 | +- part I - create a webpage with no styles, just add HTML and |
| 36 | +- part II - add styles and make it perfect. 🎨 |
| 37 | + |
| 38 | +So let's get started! |
| 39 | + |
| 40 | + |
| 41 | +### Starter Code |
| 42 | + |
| 43 | +The `starter-code` folder contains the `index.html` file with all the necessary text already provided. Also, in the starter-code, you can find the `images` folder with all the required images to successfully finish the exercise. |
| 44 | + |
| 45 | +### Part I - pure HTML (no styles applied) |
| 46 | + |
| 47 | +It might seem like a joke, but this is our goal in this iteration: |
| 48 | + |
| 49 | + |
| 50 | + |
| 51 | + |
| 52 | + |
| 53 | +<br><br> |
| 54 | +The very first step is deciding **how to structure the page and picking the correct *semantic* tags**. In general, picking the right tags will make your job easier in the next step when the time comes to do some styling. |
| 55 | + |
| 56 | +Our recommendation is to try to keep it as simple as possible. Try to identify the different sections, and add `id`'s or `classes` to each `<div>`, `<section>`, `<ul>`, or `<header>` block elements to identify these elements. Here is suggested guideline but you might have something on your mind that is different from this - bring it up. |
| 57 | + |
| 58 | + |
| 59 | + |
| 60 | + |
| 61 | + |
| 62 | +#### HTML 1 | `<header>` & `<nav>` |
| 63 | +Your task in this iteration will be to create the `header` and `nav`, which are the first two elements of the page. As you can see on the image above, the first element inside the body is `header` and it is composed of two divs: |
| 64 | +- the upper div contains another div with image and some text, and besides this, it has *nav* tag with list displayed horizontally |
| 65 | +- the bottom div has the logo, search bar (which is *form*) and some buttons all the way left. |
| 66 | + |
| 67 | + |
| 68 | + |
| 69 | +However, remember, on the image above styles are already applied so our final result won't be quite the same. |
| 70 | + |
| 71 | +We could try to represent this part of the website with the following: |
| 72 | + |
| 73 | +```htmlmixed |
| 74 | +<header> |
| 75 | + <div> |
| 76 | + <div> |
| 77 | + <img class="blackHeart" src="LINK TO IMAGE GOES HERE" alt="black heart"> |
| 78 | + <span> Nifty Penguin Magic </span> |
| 79 | + </div> |
| 80 | + <nav> |
| 81 | + <ul> |
| 82 | + <li> <a href="#"> npm Enterprise </a> </li> |
| 83 | + <li> <a href="#"> Products </a> </li> |
| 84 | + <li> <a href="#"> Solutions </a> </li> |
| 85 | + <li> <a href="#"> Resources </a> </li> |
| 86 | + <li> <a href="#"> Docs </a> </li> |
| 87 | + <li> <a href="#"> Support </a> </li> |
| 88 | + </ul> |
| 89 | + </nav> |
| 90 | + </div> |
| 91 | +
|
| 92 | + <div> |
| 93 | + <!-- add logo, search bar and buttons (or links and style them as buttons later) --> |
| 94 | + </div> |
| 95 | + </header> |
| 96 | +``` |
| 97 | + |
| 98 | +When done, you should get something similar to this: |
| 99 | + |
| 100 | + |
| 101 | +You're ready to move to the next iteration. :raised_hands: |
| 102 | + |
| 103 | +#### HTML 2 | Content Sections |
| 104 | + |
| 105 | +Take a look at the image with market HTML elements on it one more time, and you can see we have three sections below the header. Create `section` tags and give each of them `id`s so you can identify them quickly. |
| 106 | + |
| 107 | +The content for each of these sections is already in the *index.html* but you have to organize it properly making sure there are headings, paragraphs, divs, etc. |
| 108 | + |
| 109 | +**All images can be found in your `images` folder!** |
| 110 | + |
| 111 | +You can see the final result on the gif at the beginning of this exercise. |
| 112 | + |
| 113 | +The time has come! Let's add some styles and make it pretty! :nail_care: |
| 114 | + |
| 115 | +### Part II - CSS/styles |
| 116 | + |
| 117 | +#### CSS 1 | Setup |
| 118 | + |
| 119 | +As you might recall, the first thing we have to do to add styles to our page is to create a `style.css` file and link it to our `index.html`. |
| 120 | + |
| 121 | +So let's begin by creating a new file, in the same folder as our HTML file, and name it `style.css`. Now, link the file to the *index.html*. |
| 122 | + |
| 123 | +*Hint*: In case you need to refresh your memory on how to do this, check *Introduction to CSS* lesson. |
| 124 | + |
| 125 | + |
| 126 | +*Hint2*: You might want to consider adding the following line to your CSS, just to confirm that you have linked it correctly: |
| 127 | + |
| 128 | +```css |
| 129 | +body{ |
| 130 | + background-color: red; |
| 131 | +} |
| 132 | +``` |
| 133 | +Refresh the page in Chrome, and if your *style.css* is linked properly, the page should turn red. (*You can delete the *background-color* property we added as a test once you have confirmed it's working.*) :wink: |
| 134 | + |
| 135 | +:::info |
| 136 | +Before we move forward, add at the very top of your *style.css* file the following lines: |
| 137 | + |
| 138 | +```css |
| 139 | +@import url('https://fonts.googleapis.com/css?family=Poppins'); |
| 140 | + |
| 141 | +body { |
| 142 | + font-family: 'Poppins'; |
| 143 | +} |
| 144 | +``` |
| 145 | +::: |
| 146 | + |
| 147 | +This will be the default font you will be using on the entire webpage. |
| 148 | + |
| 149 | +Now we are ready to start adding some styles to our page. |
| 150 | + |
| 151 | + |
| 152 | +#### CSS 2 | The Header and the navbar |
| 153 | + |
| 154 | +In the first part of this exercise, you created the header and inside it the navbar. Now we have to add some styles to make it more like this: |
| 155 | + |
| 156 | + |
| 157 | + |
| 158 | +We'll help you style the part of the code we previously provided for you - the upper *div* of the *header* tag. |
| 159 | + |
| 160 | +```css |
| 161 | +header > div { |
| 162 | + padding: 0 25px; |
| 163 | + display: flex; |
| 164 | + justify-content: space-between; |
| 165 | + align-items: center; |
| 166 | + border-bottom: 1px solid lightgray; |
| 167 | +} |
| 168 | + |
| 169 | +nav { |
| 170 | + width: 600px; |
| 171 | +} |
| 172 | + |
| 173 | +nav ul { |
| 174 | + list-style: none; |
| 175 | + display: flex; |
| 176 | + justify-content: space-between; |
| 177 | + align-items: center; |
| 178 | +} |
| 179 | + |
| 180 | +nav a { |
| 181 | + text-decoration: none; |
| 182 | + color: black; |
| 183 | +} |
| 184 | + |
| 185 | + |
| 186 | +.blackHeart { |
| 187 | + width: 20px; |
| 188 | + margin-right: 1rem; |
| 189 | +} |
| 190 | +``` |
| 191 | + |
| 192 | +*Help*: |
| 193 | +- *form label color*: rgba(0,0,0,.05) |
| 194 | +- *form input color*: rgba(0,0,0,.05) |
| 195 | +- *form button background color*: #fb3e44 |
| 196 | +- *form button letters color*: white |
| 197 | + |
| 198 | + |
| 199 | +As you can see, a lot of *flexbox* is involved - if needed, revise the lesson again or sneak peek into the official docs (use your Google skills) or use this [resource](https://flexbox.help/) as a help. |
| 200 | + |
| 201 | +Make sure to use flexbox at any time where you need to position elements on a specific place - practice as much as possible: the more you understand now, the easier will be later. |
| 202 | + |
| 203 | + |
| 204 | +#### CSS 3 | section 1 |
| 205 | + |
| 206 | + |
| 207 | + |
| 208 | + |
| 209 | + |
| 210 | + |
| 211 | +In this section, as you can see everything is *centered*. You can add some flexbox rules to the *id* you attached to this section such is *display: flex;* and *justify-content: center;*. But this is just the beginning - you still have to set *align-items* and *flex-direction*. |
| 212 | + |
| 213 | +*Help*: |
| 214 | +- suggested height for this section: 600px |
| 215 | +- background color: rgba(232,217,217,.3) |
| 216 | +- "See plans" button background color: #FB3B49 |
| 217 | +- "See plans" button box shadow: 8px 8px 0 rgba(251,59,73,.2) |
| 218 | + |
| 219 | + |
| 220 | + |
| 221 | +#### CSS 4 | section 2 |
| 222 | + |
| 223 | + |
| 224 | + |
| 225 | + |
| 226 | +This section has pretty much the same layout as the previous - some code to be reused :wink:. |
| 227 | + |
| 228 | +*Help*: |
| 229 | +- *heading background color*: rgba(255,204,53,.4) |
| 230 | +- to get the transform of the yellow background in the left-hand direction use: *transform: skew(9deg,0deg);* |
| 231 | +- to get it in the opposite direction of the letters, the way we need it on the page, use: *font-style: italic;* |
| 232 | +- to additionally fine-tune the position of each element, use *margin* property. |
| 233 | + |
| 234 | +Again use a lot of flexbox to get the right position of elements - direction, justify-content, align-items. |
| 235 | + |
| 236 | +**Inspect elements to get the right size of the font for each of them**. However, this is not a crucial thing, so don't spend too much time on it - focus on positioning primary. |
| 237 | + |
| 238 | + |
| 239 | +#### CSS 5 | section 3 |
| 240 | + |
| 241 | + |
| 242 | + |
| 243 | +*Help*: |
| 244 | +- color of the letters in each heading in this section: #ED1C24 |
| 245 | +- "Create an Org" box shadow: 8px 8px 0 rgba(128,83,35,.2) |
| 246 | +- "Create an Org" letters color: white |
| 247 | + |
| 248 | + |
| 249 | +## Summary |
| 250 | + |
| 251 | +In this exercise, you've built a clone of a piece of the npm home page. This site is very complexed so if you managed to make it look anything like the original, good job! :trophy: |
| 252 | + |
| 253 | +This concludes the HTML / CSS module. Next up is JavaScript, so get some rest, drink some coffee, and get ready to learn the muscles that make things move on a web page. |
| 254 | + |
| 255 | +We are proud of you! Happy coding! :heart: |
0 commit comments