CSS BASICS. selector { property: value; }

Similar documents
CSS worksheet. JMC 105 Drake University

Introduction to Multimedia. MMP100 Spring 2016 thiserichagan.com/mmp100

CSS means Cascading Style Sheets. It is used to style HTML documents.

HTML/XML. HTML Continued Introduction to CSS

1 Creating a simple HTML page

**Method 3** By attaching a style sheet to your web page, and then placing all your styles in that new style sheet.

Make a Website. A complex guide to building a website through continuing the fundamentals of HTML & CSS. Created by Michael Parekh 1

CS 1100: Web Development: Client Side Coding / Fall 2016 Lab 2: More HTML and CSS

Unveiling the Basics of CSS and how it relates to the DataFlex Web Framework

Reading 2.2 Cascading Style Sheets

CSS Cascading Style Sheets

Assignments (4) Assessment as per Schedule (2)

Study Guide 2 - HTML and CSS - Chap. 6,8,10,11,12 Name - Alexia Bernardo

2. Write style rules for how you d like certain elements to look.

The internet is a worldwide collection of networks that link millions of computers. These links allow the computers to share and send data.

Introduction to HTML & CSS. Instructor: Beck Johnson Week 2

Lab 4 CSS CISC1600, Spring 2012

ADDING CSS TO YOUR HTML DOCUMENT. A FEW CSS VALUES (colour, size and the box model)

HTML and CSS: An Introduction

CREATING A WEBSITE USING CSS. Mrs. Procopio CTEC6 MYP1

Microsoft Expression Web Quickstart Guide

Welcome Please sit on alternating rows. powered by lucid & no.dots.nl/student

By Ryan Stevenson. Guidebook #3 CSS

Cascading Style Sheets Level 2

Introduction to WEB PROGRAMMING

Client Side JavaScript and AJAX

Using Dreamweaver CS6

To link to an external stylesheet, the link element is placed within the head of the html page:

The building block of a CSS stylesheet. A rule consists of a selector and a declaration block (one or more declarations).

Layout with Layers and CSS

Three Ways to Use CSS:

Cascading Style Sheet

An attribute used in HTML that is used for web browsers screen reading devices to indicate the presence and description of an image Module 4

CSS Cascading Style Sheets

Dreamweaver CS3 Lab 2

Index. alt, 38, 57 class, 86, 88, 101, 107 href, 24, 51, 57 id, 86 88, 98 overview, 37. src, 37, 57. backend, WordPress, 146, 148

Downloads: Google Chrome Browser (Free) - Adobe Brackets (Free) -

Introduction, Notepad++, File Structure, 9 Tags, Hyperlinks 1

CSS Design and Layout Basic Exercise instructions. Today's exercises. Part 1: Arrange Page into Sections. Part 1, details (screenshot below)

COSC 2206 Internet Tools. CSS Cascading Style Sheets

HTML & CSS for Library Professionals

In the early days of the Web, designers just had the original 91 HTML tags to work with.

Using Dreamweaver CC. 6 Styles in Websites. Exercise 1 Linked Styles vs Embedded Styles

<body bgcolor=" " fgcolor=" " link=" " vlink=" " alink=" "> These body attributes have now been deprecated, and should not be used in XHTML.

Unit 5 Web Publishing Systems Page 1 of 13 Part 4 HTML Part 4

HTML & CSS. Rupayan Neogy

ORB Education Quality Teaching Resources

Groupings and Selectors

ITNP43: HTML Lecture 4

<style type="text/css"> <!-- body {font-family: Verdana, Arial, sans-serif} ***set font family for entire Web page***

Before you begin, make sure you have the images for these exercises saved in the location where you intend to create the Nuklear Family Website.

The default style for an unordered (bulleted) list is the bullet, or dot. You can change the style to either a square or a circle as follows:

Title and Modify Page Properties

Building Your Website

Let s start with the document tree

Introduction to using HTML to design webpages

Shane Gellerman 10/17/11 LIS488 Assignment 3

CSS Tutorial Part 1: Introduction: A. Adding Style to a Web Page (3 options):

3.1 Introduction. 3.2 Levels of Style Sheets. - The CSS1 specification was developed in There are three levels of style sheets

- The CSS1 specification was developed in CSS2 was released in CSS2.1 reflects browser implementations

This document provides a concise, introductory lesson in HTML formatting.

Dreamweaver CS5 Lab 2

CSS. Lecture 16 COMPSCI 111/111G SS 2018

How to lay out a web page with CSS

CSS WHAT IS IT? HOW DOES IT WORK? (LOOK N GOOD)

HTML & CSS. SWE 432, Fall 2017 Design and Implementation of Software for the Web

Lesson 1 HTML Basics. The Creative Computer Lab. creativecomputerlab.com

HTML and CSS a further introduction

CSS Lecture 16 COMPSCI 111/111G SS 2018

HTMLnotesS15.notebook. January 25, 2015

3.1 Introduction. 3.2 Levels of Style Sheets. - HTML is primarily concerned with content, rather than style. - There are three levels of style sheets

Creating a CSS driven menu system Part 1

HTML and CSS COURSE SYLLABUS

Azon Master Class. By Ryan Stevenson Guidebook #8 Site Construction 1/3

CSS: The Basics CISC 282 September 20, 2014

ICT IGCSE Practical Revision Presentation Web Authoring

5 Snowdonia. 94 Web Applications with C#.ASP

TUTORIAL MADCAP FLARE Tripane and PDF

Part 3: Images & form styling NOMZAMO S WEBSITE

BIM222 Internet Programming

Title: Jan 29 11:03 AM (1 of 23) Note that I have now added color and some alignment to the middle and to the right on this example.

HTML/CSS Lesson Plans

- HTML is primarily concerned with content, rather than style. - However, tags have presentation properties, for which browsers have default values

COMP519 Web Programming Lecture 6: Cascading Style Sheets: Part 2 Handouts

Using Dreamweaver CS6

Teach Yourself HTML5 & CSS 3: Week 5 Task 13 - Anchors Part 3

Cascading Style Sheets (CSS)

Using Dreamweaver CS6

ICT IGCSE Practical Revision Presentation Web Authoring

Creating a Job Aid using HTML and CSS

The Importance of the CSS Box Model

The Benefits of CSS. Less work: Change look of the whole site with one edit

CS Multimedia and Communications REMEMBER TO BRING YOUR MEMORY STICK TO EVERY LAB!

c122jan2714.notebook January 27, 2014

- The CSS1 specification was developed in CSSs provide the means to control and change presentation of HTML documents

Introduction to Web Programming and Design

CSS 1: Introduction. Chapter 3

Unit 10 - Client Side Customisation of Web Pages. Week 5 Lesson 1 CSS - Selectors

Beginning HTML. A tag is a command written between angle brackets (the less than and greater than symbols). Ex. <html>

FRONTPAGE STEP BY STEP GUIDE

Transcription:

GETTING STARTED 1. Download the Juice-o-Rama 11-01 zip file from our course dropbox. 2. Move the file to the desktop. You have learned two ways to do this. 3. Unzip the file by double clicking it. You will be working from this unzipped folder for the rest of class, so you may throw away the zip file once you have created the folder from it. 4. Open the folder Juice-o-Rama 11-01. 5. Open the two html files in TextEdit. The first, index.html is in the root folder. The second, elixirs.html is in the elixirs subfolder. 6. Open the two html files in Google Chrome as well. Remember, you are not able to edit in the browser, but you can use it to see how changes in your code look. 7. Click back to TextEdit 8. In the head of index.html, place your cursor between the opening and closing style tags. These tags surround any css code we include to change the appearance of our website.

CSS BASICS CSS relies on selectors, properties and values. A selector+properties+values=a CSS rule A css selector is the name of the html element (or other part of our html code more on that later) to which we want to apply style. More often than not, what you type for a selector will be the same as the elements you used in your html, such as body, h1 or p. Unlike html tags, css selectors are not surrounded by angle brackets. A css property is the code that tells the browser in general which type of style you want to apply. Properties are things like color, font, margins, borders, etc. A css value is the code that tells the browser how, specifically, you want the style to look. CSS selectors are easy to remember. You already know most of them from HTML. CSS properties and values are harder, especially since there are hundreds of individual codes. Don't freak out. You are not expected to remember all of these. If you're not sure what property or value to use, visit this website: http://htmldog.com/reference/cssproperties/. You can also just search in Google. Typing something like "change font css" in the Google search bar will more than likely pull up the instructions you need. CSS code is always written in the following format: selector { property: value; } VERY IMPORTANT REMINDERS You can have multiple properties and values inside the curly brackets for a particular selector, but each must follow the format property: value; CSS properties and values are often one word, but in the case that they are made up of more than one word, there CANNOT be spaces in between those words. Instead, use a dash (not an underscore) CSS code must be written in between the opening and closing style tags in the head of an html document OR in an appropriately coded external style sheet. For now, let's focus on using style tags.

ADDING CSS IN THE STYLE TAGS 1. Type your first selector in between the style tags in the head of index.html. The first selector we will choose for most websites is "body". CSS rules applied to the body selector affect everything, because, after all, body is the parent element of all content. We use "body" rather than "html" because "html" is also the parent of "head", and we don't style the head. FYI, the order in which you type css rules does matter, but for now don't worry too much about it. 2. After the selector name (body in this case) type a right-facing curly bracket { 3. Hit return twice and type a left-facing curly bracket }. It's a good idea to get in the habit of establishing opening and closing brackets for CSS right away, just like we set opening and closing tags for HTML. If you forget a curly bracket, your CSS won't work. 4. Put your cursor on the empty line between the two curly brackets. I recommend hitting tab to indent all of your CSS properties and values, since it makes them easier to read. Remember, the browser ignores returns, tabs and most spaces in HTML and CSS files. 5. Type the name of the CSS property you wish to apply to the body selector. We are going to start by setting the background color. If you don't know the CSS property code to set background color, look it up on HTML Dog or Google. 6. Type a colon : and one space after the CSS property code. 7. Establish the following value for the CSS property for background color: #BAE398. We will be using hex codes like this for most of our colors. To use a hex code in CSS, type a number sign # and the six digit alpha numeric code generated by a color picker like http://www.colorpicker.com/. 8. After the value, type a semi-colon ; 9. Save the index.html file (command S), and then click over to index.html on Google Chrome and refresh the page (command R). You should see that the background is now light green. 10. Click on elixirs.html on Google Chrome and refresh the page. What happened? 11. On a new line below the body rule in juice.css, type a second selector so that you can apply style to your paragraphs (if you don't know the selector for the paragraph element, look it up). 12. Type opening and closing curly brackets separated by a line space. 13. Type the property code for selecting font (if you don't know, look it up) followed by the required punctuation, and then, for the value, write a list of preferred fonts in this order: Helvetica Neue, Helvetica, Verdana and, finally, the general category of sans-serif. If you structure the list correctly (something you probably want to research a little), the browser will try to find each font in order. If it finds Helvetica Neue on the end user's computer, it will use that. If not, it will move on to Helvetica, and so forth. The general sans-serif category at the end is a catch-all fallback. End the list with the proper CSS punctuation. 14. Within the same curly brackets for the paragraph selector, hit return for a fresh line and type a second property and value to define the font size as medium. 15. Save the file, and then return to Google Chrome and refresh your two pages. What happened?

INTERNAL VS. EXTERNAL STYLE The previous steps demonstrate one of the great weaknesses of writing CSS in the head of an html page, a process referred to as internal styling. With internal styling, the CSS only affects the HTML page on which it appears. If you have two pages in a website, you would have to copy and paste the CSS into the head of each to get them to look the same. No big deal right? Maybe not for two pages, but how about three? Or five? Or 100? Not only would you have to copy and paste over and over again, but every time you wanted to make a change, you would have to revise each page one by one. This way lies madness. Fortunately, CSS is designed with a way around this issue. Instead of placing style in the head, you can write a line of code that links your HTML pages to an external style sheet. Then you can write the CSS just once on that sheet and it will be applied to any linked HTML page. Changes can likewise be made just on the external style sheet. Neato keen! CREATING AN EXTERNAL STYLE SHEET 1. While in TextEdit, create a new file File>New 2. Save the new file as juice.css. Pay attention to this new file extension. We are using CSS not HTML because this will be an external style sheet, and CSS is the language of style. 3. Copy the CSS you wrote in the previous steps into your new TextEdit document. There is no need to transfer style tags, since the entire juice.css file is CSS. Your code should look like this: body { background-color: #BAE398; } p { font-family: "Helvetica Neue", Helvetica, Verdana, sans-serif; font-size: medium; } 4. Save the file. 5. Return to Google Chrome and refresh your two pages. What happened?

LINKING YOUR HTML AND EXTERNAL CSS In refreshing Chrome, you should have seen no change to the pages because right now your HTML documents are totally ignorant that juice.css exists. To get the HTML to recognize the CSS file, you have to put a new line of code into the head of each HTML document. This code utilizes an element you haven't seen before: the link element. 1. In TextEdit, remove the style tags from the index.html file. We don't need them anymore since we're going external, baby! 2. Where the style tags were in the head of index.html (between the head tags and under the title tags), you insert the link element. Like img, link is an empty element whose purpose is to point the browser someplace else. In this case, we're pointing to our external style sheet juice.css. Also like the img element, link requires attributes: three as a matter of fact. The first required attribute is type which tells the browser the relationship what type of file we're linking to the HTML file. In this case, we use type="text/css" because the file we're linking is a plain text file of CSS code. The second required attribute is rel, which tells the browser the relationship of the file we're linking to the HTML file. In this case, the rel="stylesheet" because the file we're linking is, of course, a stylesheet. The third required attribute is one you know and love: href. This does exactly the same thing as with the <a> element, it gives a hypertext reference. In other words, it provides directions to the browser on what path it needs to take to find the file we're linking. The total line you will add in place of the style tags in index.html is this: <link type="text/css" rel="stylesheet" href="juice.css"> Don't forget, link is an empty element, so there is NO CLOSING TAG. 3. Save the index.html file, and then go back to Google and refresh index.html. If you wrote your code correctly, you should see no change because the external code is the same as what we wrote earlier internally. That will change soon. 4. Return to TextEdit, and replace the style tags in elixir.html with the link element. Save the file. 5. In Google, refresh elixir.html. Most of you probably find there's no change. Can you figure out why? Hint: check the path you've told the browser to follow to get from elixir.html to juice.css. 6. Have you save your files lately? Save often to prevent heartache.

ELEMENTAL MASTER OF ORGANIZATION Now that we've got mad external style sheet skillz, we can easily add more css rules (rules = selector + properies + values) to both our pages at once using juice.css. First however, we are going to add an element each of our html files that, as we move forward, will be crucially important: the div element. Div stands for division, and by itself, it doesn't change the way our page displays. Rather, it is an element we use to create sections within our code that we can later control. The content that goes within div is made up of other html elements like h1, h2, p, ul, ol, img and a. Incidentally, there can be multiple divs in a page; how many and where they're placed depends on how you want to group things. Typically, web designers include at least one, called the container or main div. The container div sits just inside the body tags. The code for a page therefore looks like this: <html> <head> <title>titile of Page</title> <link rel="stylesheet" href="your_path_here.css"> </head> <body> <div><!--container--> All the marked-up content. </div><!--container--> </body> </html> So what's with the funny <!--container--> tags? <!--insert words here--> is the way we put a comment into HTML. The browser won't display the text or add any structure based on this code. We add it simply to help clarify things for us as the designer. So why did I include it here? Because it's very important to label your divs, or things get complicated later on. Remember all those messy layers that grew in your Project 1 Photoshop files? Yeah, unlabeled divs are that multiplied by six hoarders and a tangled mess of Christmas lights. ADD A CONTAINER DIV 1. Click on index.html in TextEdit. 2. Just under the opening <body> tag, add an opening <div> tag and a comment tag labeling this as the container <!--container--> 3. Just above the closing <body> tag, add a closing <div> tag and a comment tag labeling this as the container <!--container--> 4. Repeat these steps for the elixirs.html page. 5. Save the files and refresh both in Google Chrome. You should see no change... yet.

PRETTYING UP JUICE-O-RAMA VIA THE DIV Time for the fun part. Now that we have an external style sheet, link tags and container divs, we can really unleash the power of CSS to turn our drab website into something striking and professional. 1. Rename the p selector to div on your juice.css. We're doing this because we want the fontfamily and font-size we set earlier to apply to all the elements in our div... for now. 2. Add the following properties and values between the div selector curly brackets: Make the background color white Fill the background with the image background_image.png 3. Save your file, and then refresh your pages in Google Chrome. You should see that a faded out image of fruit is now covering the page. You can no longer see the light green except on the edges and the bottom. 4. Now open the browser window as wide as you can get it. What happens to the image when it runs out of space? 5. I'm personally not a big fan of the tiling or repetition that occurs with background images in CSS, but, fortunately, you can control that behavior with the background-size property. There are several possible values for this (look it up if you're curious), but we're going to set the value to cover. This will adjust the image size in proportion to the window size. 6. Save the file and test out the effect in Google Chrome. 7. Our design already looks much improved thanks to the background image, but let's take advantage of the div organization to create contrasting styles. Since the div is a section within the body, we can set it apart visually. For starters, let's create margins. Remember that margins are space around the outside of an element (outside the border, whether that border is visible or invisible). Within the div selector curly brackets set a 50px left margin, a 50 px right margin and a 20px top margin. 8. Save the file and test out the effect in Google Chrome. 9. Now that we have margins, let's add some padding. You may remember that padding is similar to margins in that it is space at the edges of an element. However, while margins are outside the border, padding is inside, between the border and the content. We could definitely use some space between our div border and all our text, which is currently crunched to the edge. Let's add padding all around this time written as a percentage of the total page size. Add padding at left, top and right with a value of 1% and at the bottom with a value of 5%. 10. Save the file and test out the effect in Google Chrome. 11. All this talk of borders makes me wonder what it would look like if we added one to the div. Make a border with a size of 5 px, a style that is a solid line and a color that recalls the blueberries in our background photo. 12. Finally for the div selector, our paragraph text feels a little crowded. Let's make it easier to read by changing the spacing between lines. This property name is a little tricky, so do some research. We will set the value as a percentage: 140% to be exact. In this case, 140% is in relation not to our page size but to the default line spacing set by the browser. 13. Have you save your files lately? Save often to prevent heartache.

GOING FURTHER WITH SELECTORS Of course, not all our style has to be applied to all our elements via the body and div selectors. We can also pinpoint specific elements. 1. Let's set our heading text apart from our paragraph and unordered list text. To do this, we can use multiple selectors for a single list of properties. On a new line below the div rules, type: h1, h2 { } Much like the way you separate e-mail address in a message you're sending to multiple people, separate multiple selectors in a CSS rule with a comma and a space. All properties and values put in the brackets above will be applied to both our h1s and h2s. 2. Set the following properties and values for h1 and h2: font family in order of preference: Palatino, Georgia, Times, serif. font color to match the dark, red berry colored drink in the image on our home page. 3. Save the file and test out the effect in Google Chrome. 4. You can set rules for h1 and h2 separately in addition to having them share properties. However, to do this, you need to make a new rule with just one selector. Hit return to get to a fresh line and then add the following properties and values for h1 only: font size to 200% (this is in relation to the default font size, which is medium). make the font all uppercase using CSS. align the text in the center of the page. 5. Save the file and test out the effect in Google Chrome. 6. Now let's deal with our unordered lists. All those bullets on elixirs.html are making my eyes hurt, so let's get rid of them. Add the appropriate property and value. 7. Once the bullets are gone, let's add some space in between each of the separate lists so the menu items are more readable. To do this, add bottom padding of 10px to the ul selector. 8. Finally, let's give the lists a style to set them apart. Let's make them italic. 9. Save the file and test out the effect in Google Chrome.