====== Web Development Lesson 3 - Lists ======
===== Simple Lists =====
==== Objectives ====
In this exercise you will create a bulleted list and a numbered list and learn some list-specific formatting rules.
===== Setup =====
* Open a new [[https://jsfiddle.net|jsfiddle]] tab.
* Populate the HTML section with headings for 'Recipe', 'Ingredients' and 'Method'.
===== Numbered List =====
* Let's look at the Method first. Most recipes show the method as a numbered list since it's important to do the steps in order.
Pancake Recipe
Ingredients
Method
* Run the code now and see that the browser automatically places a number at the beginning of each line, starting with '1'.
* The Method
Method
- Mix ingredients
- Heat pan
- Pour mix into pan
- Cook 1 minute on each side
- Serve
* What do you notice when you run the code? The numbers change automatically so that 'heat pan' becomes '2' and everything afterwards is incremented.
===== Bullet List =====
* Now let's look at the ingredients. The order of the ingredients doesn't matter, so they're not usually numbered.
Ingredients
- 100g flour
- 2 eggs
- 300ml milk
* Run the code and see that instead of a number, we have a dot (or bullet) in front of each item.
* It's as easy as this to create a list. Now let's see what we can do to change their appearance.
===== CSS =====
* Add the following style attribute to the method.
* Run the code and notice that the bullets move to the right. They're moving 'inside' the
* This style creates a solid red border with a width of 1 pixel around the list element.
* Now you can see that the bullets are 'inside' the border, while the numbers of the ordered list are outside the border.
* Notice that you have to add the border style to each of the elements you want to apply it to. That gets hard to manage when you want to do it more than a few times, especially if you want to change them multiple times to see which you like best. There's a better way.
* In the CSS pane at the top right, enter the following code.
li {
border: solid red 1px;
}
* Run the code and see that the border is applied to every instance of
* Run the code and see that the specific list item now has a thicker blue border. It takes priority over the general rule because it's more specific.
===== CSS for Lists =====
* Add the following style for the unordered list.
ul {
list-style-type: square;
}
* Notice that the bullet shape changed. Other options for list-style-type are disc and circle.
* We can also change the style for ordered lists.
* Some options are upper-roman and lower-alpha. Try these to see which ones you like.
ol {
list-style-type: upper-roman;
}
===== Final Code =====
If you get to this point and something isn't quite right, or you'd like to check your code, here is the code we've been working on.
* [[https://techschool.murraygunn.id.au/webdev/classes/lists/1/en.php|HTML]]
* [[https://techschool.murraygunn.id.au/webdev/classes/lists/1/css.php|CSS]]
* [[https://jsfiddle.net/maganthro/t17oqcxu/25/|Full jsfiddle]]
[[en:web_development:lists:multilevel_lists|Next: Multi-level Lists]]