From 30419b2c90432f360f3b914ab70708367bb68f94 Mon Sep 17 00:00:00 2001
From: Heather Payne
( Interactive code slides thanks to
CoderDeck. Also, thanks to Pearl Chen and Mark Reale for creating the foundation for today's content. )
( Interactive code slides thanks to
@@ -234,7 +234,7 @@ CSS (Cascading Style Sheets) is what makes websites look nice. While HTML tells the browser what different parts of the page are, CSS says what those pieces should look like. While HTML tells the browser what different parts of the page are, CSS says what those pieces should look like. For example, p means paragraph in HTML. If we wanted to make all of our paragraphs red and underlined, we'd do something like: To indicate that we're adding CSS to blank.html, we need to find the opening and closing A CSS rule is made up of a selector and one or more declarations A selector tells the browser what element(s) we are styling. It looks like this: The above selector will select all The above selector will select all A property tells the browser what we are modifying (ex. font, colour, size) A value tells the browser how to modify the property (ex. Arial, green, small) A declaration looks like this: The value (the part after the colon) is specific to the property type Check outhttp://colorpicker.com for more awesome colours! Let's change the font to a sans-serif like Helvetica: The font-family property accepts a list of font names: the first font is your first-choice font, the next ones are fallbacks in case that font is not available. Not all fonts are commonly available, so try to stick to 'web-safe' fonts like: If we want to make our We can write a selector in our css to target the element we added a class to using a And then apply the styles we want to only the item with the class: Your HTML should look something like this: And your CSS should look something like this: Add a class of "favourite" to each of the four images. Add some styles to your images, using things like Add some styles to your images, using things like The CSS "Box Model" describes the way CSS styles the size and spacing of HTML elements. To understand the box model, we need to understand how the browser "sees" HTML elements. To the browser, every HTML element is a rectangular box. If we show the outlines of all the elements in an HTML document, it looks a bit like the next slide: If we show the outlines of all the elements in an HTML document, it looks a bit like the next slide: There are two CSS properties for adding space around our elements: The This code adds 40px of space on every side of the element. This code adds 40px of space on every side of the element. This code adds 40px of space to every side of the element, but it does so within the border. This code adds 40px of space to every side of the element, but it does so within the border. The same goes for The The Add a class called Then write a selector in your CSS and apply the Then write a selector in your CSS and apply the This is because images are inline elements. Inline elements do not take up the full width of the page, they only take up as much space as the content requires. Most elements, like Because our logo element is only as wide as the image, we can't centre it relative to the page. Luckily, this is easy to fix: we just tell the Our site looks much better now, but now it's time to style the individual sections. We'll need a way to target each section independently, grouping elements within the same section together, creating a layout. Conveniently enough, HTML provides the Conveniently enough, HTML provides the >You can write a child selector to select only those tags which are children of another tag. We add a space between the parent and the child selector to specify: The above selector will select only those To target the Try increasing the Try increasing the Select the We want to align the profile image to the left, and allow the text to wrap around it. We do this using CSS Floats. Remember how all HTML elements are rectangular boxes stacked on top of each other? We have to break that stacking flow by floating the image to the side. This will cause the text after the image to move up beside it, because we've disrupted the flow of the rectangular boxes. This has 'floated' our image to the left, but there's a problem...can you figure out what it is? This has 'floated' our image to the left, but there's a problem...can you figure out what it is? Let's write a selector for the section we just created: And centre-align it: And centre-align it: And your CSS: And your CSS: And add a bunch of padding to all our sections: And add a bunch of padding to all our sections: We can also use our Since we're targeting both our And change the colour of our headings: Find the code in Step 3 of the instructions, and paste it into the Let's add a menu to the top of our document so our users can navigate. Menus are commonly marked up as lists with links inside each list item. There are two types of lists in HTML: ordered and unordered (numbered and bulleted).
- Since we don't need numbers, we'll use an unordered list, which is marked up with Since we don't need numbers, we'll use an unordered list, which is marked up with Each bullet or "list item" in an unordered list is marked up as an
- ( Interactive code slides thanks to
- CoderDeck. Also, thanks to Pearl Chen and Mark Reale for creating the foundation for today's content. )Introduction to HTML & CSS
-
I'm a H2 heading
Welcome to Ladies Learning Code's
Introduction to HTML & CSS
Speaking of CSS...
What is CSS?
p {
@@ -250,6 +250,7 @@ Let's add this to our HTML document
<style> tags between our opening and closing <head> tags.
+
<!doctype html>
+ <html>
<head>
<title>Ladies Learning Code HTML and CSS</title>
<style>
@@ -332,7 +333,7 @@
-HTML tags
</body>
</html>
HTML tags
</head>
<body>
</body>
-</html>
+</html>
<!DOCTYPE html>
<html>
@@ -366,7 +367,7 @@
+</html>
HTML tags
</head>
<body>
</body>
-</html>
@@ -501,8 +502,8 @@ A note about organization
CSS basics
- CSS basics
+
CSS is closely paired with HTML
CSS doesn't do anything on its own, it's the presentation layer on top of a content base
If HTML is the beams of the house, CSS is the layout, paint, and decorations
CSS Syntax
@@ -518,10 +519,10 @@ CSS Syntax
- h2 {}<h2> elements and apply our styles to them. Our styles will go between the curly brackets.
+ h2 {}<h2> elements and apply our styles to them. Our styles will go between the curly brackets.CSS Syntax
@@ -530,11 +531,11 @@ CSS Syntax
+ background-color: green;background-color: green;CSS Syntax
background-color: green;Adding CSS to HTML
</style>
</head>
<body>
-
+
</body>
</html>
@@ -626,7 +627,7 @@ Using Hex Codes
body {
color: #444444;
}
-
+
Styling Type with CSS
Styling Type with CSS, Part 2
+ Styling Type with CSS, Part 2
body {
color: #444444;
- font-family: Helvetica, Arial, sans-serif;
+ font-family: Helvetica, Arial, sans-serif;
}
Styling Type with CSS, Part 2
Changing Font Sizes
+ Changing Font Sizes
<h1> and <h2> tags a bit bigger:
h1 {
@@ -690,7 +691,7 @@ Changing Line Height
Styling Images
@@ -703,7 +704,7 @@ Styling Images
img {
border: 1px solid grey;
}
-
+
Targeting an Element with a Class
.
+
p.classname {}
-
+
p.classname {
color: red;
}
-Exercise: Style Profile Image
Solution: Style Profile Image
-<img class="profile" src="images/profile.jpg">
+<img class="profile" src="images/profile.jpg">
+ height:200px;
+}
+
img.profile {
border: 1px solid grey;
width: 200px;
- height:200px;
-}
-Adding More Classes
-
<img class="favourite" src="images/kitten.jpg" >
-width, height, and border.width, height, and border.More Stuff You Can Do
height: 200px;
border-radius: 50%;
}
-
+
Don't worry if it seems like there are a lot of CSS properties to remember. Keep looking them up on the internet and they'll sink in eventually. Even the pros have to look things up every once in a while :)
+ Don't worry if it seems like there are a lot of CSS properties to remember. Keep looking them up on the internet and they'll sink in eventually. Even the pros have to look things up every once in a while :)
This is the trickiest part of CSS, don't worry if it seems confusing at firs
Margin and Padding
background: pink;
}
-
Margins
margin, and paddingmargin property adds space around the element, outside of the border:
-
h2 {
margin: 40px;
-}
-
Padding
margin: 40px;
padding: 40px;
}
-
-
+
+
More on Margins and Padding
margin-top: 40px;
margin-bottom: 40px;
}
-
+
padding and border:
+
@@ -928,7 +929,7 @@
h2 {
padding-bottom: 40px;
border-left: 1px solid red;
}
-Solution: Box Model
padding: 5px;
margin: 10px;
}
-
+
@@ -940,8 +941,8 @@ Centering the Logo
img {
margin: 0 auto;
}
-
- 0 sets both the top margin and the bottom margin, and the auto sets both the left and right margins. 0 sets both the top margin and the bottom margin, and the auto sets both the left and right margins. Centering the Logo
logo to your logo <img> tag:
-
<img class="logo" src="images/logo.png">
-margin property:margin property:
+
@@ -970,8 +971,8 @@
img.logo {
margin: 0 auto;
}
-Nothing Happened!
- Nothing Happened, Part 2
+ Nothing Happened, Part 2
<h2>, <p>, or <ul> take up the whole width of the page, these are called block elements.<img> tag to behave like a block element instead, by setting the display property.Nothing Happened, Part 2
margin: 0 auto;
display: block;
}
-
+
Other Inline Elements
Layout: Section by Section
<section> tag. We'll wrap each section within a <section> tag and add a class to each one, so we can style each section using CSS.
+ <section> tag. We'll wrap each section within a <section> tag and add a class to each one, so we can style each section using CSS.
Banner Section
<img>
<h1>...</h1>
<p>...</p>
-</section>
-
+</section>
+
@@ -1021,15 +1022,15 @@ Banner Section CSS
<section> with a selector in your CSS
+section.banner {}
+
-section.banner {}
-
+
@@ -1040,7 +1041,7 @@
section.banner {
padding-top: 110px;
padding-bottom: 110px;
}
-Adding a background image
background-image property lets you specify a path to an image in much the same way as you would in an HTML <img> tag:
+
@@ -1066,7 +1067,7 @@
background-image: url('images/background.jpg');
-Solution: Add a background image
color: #ffffff;
text-align: center;
}
-
+
@@ -1095,8 +1096,8 @@ CSS Child Selectors
+section img {}
+
-section img {}
-<img> tags which are nested within <section> tags.CSS Child Selectors
CSS Child Selectors
<p> tag within the banner <section>, we use:
-
-section.banner p {}
-font-size of the selected <p> tag.font-size of the selected <p> tag.<h1> tag in the banner section in the same way and capitalize the text using text-transform: uppercase. Your CSS should look something like this:
+
@@ -1142,7 +1143,7 @@
section.banner p {
@@ -1116,7 +1117,7 @@ CSS Child Selectors
section.banner h1 {
text-transform: uppercase;
}
-The "About" Section
section.about {
background: url('images/pattern.png');
}
-
+
@@ -1158,7 +1159,7 @@ Centre-aligning the header
section.about h2 {
text-align: center;
}
-
+
@@ -1166,7 +1167,7 @@ Centre-aligning the header
CSS Floats
+
CSS Floats
img.profile {
float: left;
}
-
-
+
+
@@ -1195,7 +1196,7 @@ CSS Floats
section.about {
overflow: hidden;
}
-
+
@@ -1213,7 +1214,7 @@ Next Section: Favourites
<img class="favourite" src="images/kitten.jpg">
<img class="favourite" src="images/kitten.jpg">
</section>
-
+
@@ -1221,14 +1222,14 @@ Next Section: Favourites
Centre-aligning
-
-section.favourites {}
+section.favourites {}
+
@@ -1253,7 +1254,7 @@
section.favourites {
text-align: center;
}
-Solution: Contact Section
<a href="https://">...</a>
</section>
-
+
@@ -1275,7 +1276,7 @@
section.contact {
text-align: center;
@@ -1262,7 +1263,7 @@ Solution: Contact Section
section.contact img {
margin: 20px;
}
-Styling Multiple Sections at Once
<section class="about box"></section>
<section class="favourites box"></section>
<section class="contact box"></section>
-
+
@@ -1286,29 +1287,29 @@ Styling Multiple Sections
-
section.box {}
+
-
section.box {
padding: 50px 100px;
}
-Styling Multiple Sections, Continued
+ Styling Multiple Sections, Continued
box class to target the headings in each of these sections.<h2> and <h3> tags, we'll write a selector for both, separating them with a comma:
+
section.box h2, section.box h3 {}
-
+
section.box h2, section.box h3 {
color: #A8258D;
}
-Making our background image fixed
section.banner {
background-attachment: fixed;
}
-
+
Adding Custom Fonts
<head> of your HTML document (remember how the <head> section sends invisible instructions to our browser?)
+
@@ -1350,7 +1351,7 @@
<link href='http://fonts.googleapis.com/css?family=Oswald' rel='stylesheet' type='text/css'>
-Adding Custom Fonts, Part 2
h1, h2, h3 {
font-family: 'Oswald', sans-serif;
}
-
+
@@ -1360,14 +1361,14 @@ Adding a Menu
<ul></ul> tags to indicate where the list starts and ends.
+ <ul></ul> tags to indicate where the list starts and ends.
<li></li> tag nested within the <ul> tag.
+
@@ -1380,7 +1381,7 @@
<ul>
<li>One list item</li>
<li>Another list item</li>
</ul>
-Adding a Menu, Continued
<li><a href="#favourites">Favourites</a></li>
<li><a href="#contact">Contact</a></li>
</ul>
-
+
@@ -1397,7 +1398,7 @@ Adding a Menu, Continued
border-bottom: 1px solid #434A5C;
background: #ffffff;
}
-
+
@@ -1413,7 +1414,7 @@ Styling the Menu
display: inline-block;
padding: 20px 35px;
}
-
+
@@ -1428,7 +1429,7 @@ Styling the Menu Links
text-transform: uppercase;
font-family: 'Oswald', sans-serif;
}
-
+
@@ -1444,7 +1445,7 @@ Making the menu "sticky"
left: 0;
width: 100%;
}
-
+
@@ -1456,7 +1457,7 @@ Getting the links to work
<section id="about" class="about box"></section>
<section id="favourites" class="favourites box"></section>
<section id="contact" class="contact box"></section>
-
+
@@ -1481,13 +1482,13 @@ Your site may be beautiful, but it might not be very mobile-friendly. Luckil
Ladies Learning Code regularly offers "Intro to Mobile Web" workshops - perhaps we'll see you at the next one?
Check out our upcoming events across Canada here.
-
+
Thank you!
Introduction to HTML & CSS