Lecture #11: Exploring HTML and CSS CS106E Spring 2018, Young

In this lecture we take a look at Cascading Style Sheets (CSS). We learn some of the benefits to using CSS and study the actual mechanics of writing CSS rules. We look at different selectors, which allow us to determine which HTML elements a rule will affect. We also take a quick tour of the different CSS properties that can be used to format a webpage.

As CSS allows us to change colors, we examine different techniques available to us for specifying colors in CSS. We take a closer look at how to link from one webpage to another, learning when to create an absolute link vs. a relative link. We also learn how to style links using pseudo-classes. We end with a look at how to place images on a webpage and how to use CSS box properties on them.

Cascading Style Sheets As we saw in the last lecture, modern webpages use HTML to provide semantic information about the meaning of text, such as what is a major heading vs. what is a paragraph, whereas they use CSS to provide presentation information. This will provide us with several very important advantages:

 We can write a single CSS rule that effects all HTML elements of a particular type. This means that if we want to switch all

headers from Red to Blue, we don’t have to go through the HTML looking for all the

headers. We change it once in a single location and they all are instantly updated.  In fact, as we’ll discover, we can place our CSS information in a separate file from our HTML. This means we can write a single set of CSS rules and use it for every HTML file on our website. If we want to change the look of our website, we change that single file and instantly everything is updated.  In addition separating our presentation from our semantic information will make it easier to create different presentation types, such as one set of rules for laptop-sized screens and a different set for mobile phones.

We’ll break our discussion into three parts. First, we’ll discuss how to include CSS information in your website. Next, we’ll discuss how to select which elements on a webpage will be affected by specific CSS rules. Finally, we’ll take a look at what sorts of appearance changes we can actually specify with CSS.

The and end tag in your section of your HTML file. o Write your CSS rules between the end tag.

CSS Rules Whether we’re using an external style sheet or an internal