Reading 2.2 Cascading Style Sheets

Similar documents
HTML/XML. HTML Continued Introduction to CSS

Review Question 1. Which tag is used to create a link to another page? 1. <p> 2. <li> 3. <a> 4. <em>

Appendix D CSS Properties and Values

Introduction to Web Design CSS Reference

Introduction to Web Design CSS Reference

CSS: The Basics CISC 282 September 20, 2014

CMPT 165 INTRODUCTION TO THE INTERNET AND THE WORLD WIDE WEB

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

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

CSS. Lecture 16 COMPSCI 111/111G SS 2018

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

Session 3.1 Objectives Review the history and concepts of CSS Explore inline styles, embedded styles, and external style sheets Understand style

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

CSS Lecture 16 COMPSCI 111/111G SS 2018

COSC 2206 Internet Tools. CSS Cascading Style Sheets

Controlling Appearance the Old Way

8/19/2018. Web Development & Design Foundations with HTML5. Learning Objectives (1 of 2) Learning Objectives (2 of 2)

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

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

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

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

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

Cascading Style Sheet Quick Reference

Admin. Midterm 1 on. Oct. 13 th (2 weeks from today) Coursework:

Cascade Stylesheets (CSS)

Web Design and Development Tutorial 03

Introduction to Cascading Style Sheets

Assignments (4) Assessment as per Schedule (2)

CSS for Styling CS380

Introduction to Web Tech and Programming

INTERNATIONAL UNIVERSITY OF JAPAN Public Management and Policy Analysis Program Graduate School of International Relations

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

CSS Styles Quick Reference Guide

ACSC 231 Internet Technologies

Tutorial 3: Working with Cascading Style Sheets

Adding CSS to your HTML

INFORMATICA GENERALE 2014/2015 LINGUAGGI DI MARKUP CSS

CSC 443: Web Programming

Cascading Style Sheets (CSS)

escuela técnica superior de ingeniería informática

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

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

Networks and Web for Health Informatics (HINF 6220) Tutorial 8 : CSS. 8 Oct 2015

Web Development & Design Foundations with HTML5

CSS مفاهیم ساختار و اصول استفاده و به کارگیری

CSS Cascading Style Sheets

CSS: Formatting Text. CSS for text processing: font-family. Robert A. Fulkerson

Web Development & Design Foundations with HTML5

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

Lecture B3 Style : Algorithmic Thinking. Computing and Art : Nature, Power, and Limits CC 3.12: Fall 2007

CASCADING STYLESHEETS

Lab Introduction to Cascading Style Sheets

Introduction to CSS. Fijihosting.com Introduction to CSS page 1. What are style sheets? Lovely! How do I use them?

Wanted! Introduction. Step 1: Styling your poster. Activity Checklist. In this project, you ll learn how to make your own poster.

Chapter 7 Typography, Style Sheets, and Color. Mrs. Johnson

CSS.

ICT IGCSE Practical Revision Presentation Web Authoring

Chapter 3 Style Sheets: CSS

.hedgehog { background-image: url(backyard.jpg); color: #ffff99; height: 6in; width: 12in; } .tube {

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

CSS Selectors. element selectors. .class selectors. #id selectors

Creating A Website - Part 1: Web Design principles, HTML & CSS. CSS Color Values. Hexadecimal Colors. RGB Color

WEB DEVELOPMENT & DESIGN FOUNDATIONS WITH HTML5

Cascading Style Sheets. Overview and Basic use of CSS

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

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

1 of 7 11/12/2009 9:29 AM

Using CSS in Web Site Design

ID1354 Internet Applications

EECS1012. Net-centric Introduction to Computing. Lecture 3: CSS for Styling

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

CSS worksheet. JMC 105 Drake University

Introduction to WEB PROGRAMMING


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

Fundamentals of Web Programming a

Web Site Design and Development Lecture 5

Introduction to using HTML to design webpages

CSE 154 LECTURE 3: MORE CSS

BIM222 Internet Programming

UNIVERSITI TEKNOLOGI MALAYSIA TEST 1 SEMESTER II 2012/2013

Using Dreamweaver CS6

Three Ways to Use CSS:

CSCB20 Week 7. Introduction to Database and Web Application Programming. Anna Bretscher Winter 2017

Module 2 (VII): CSS [Part 4]

Creating and Building Websites

CSc 337 LECTURE 3: CSS

Methods for configuring Cascading Style Sheets. Applying style to element name selectors. Style Rule Basics. CMPT 165: Cascading Style Sheets

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

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

By Ryan Stevenson. Guidebook #3 CSS

2005 WebGUI Users Conference

Shane Gellerman 10/17/11 LIS488 Assignment 3

Anatomy of a Style. Cascaded Style Sheets - CSS. CSS Presentation Description Language. Measurement Specification

Outline. Link HTML With Style Sheets &6&7XWRULDO &66 ;+70/ (GZDUG;LD

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

Styles, Style Sheets, the Box Model and Liquid Layout

ITNP43: HTML Lecture 5

DAY 4. Coding External Style Sheets

Transcription:

Reading 2.2 Cascading Style Sheets By Multiple authors, see citation after each section What is Cascading Style Sheets (CSS)? Cascading Style Sheets (CSS) is a style sheet language used for describing the look and formatting of a document written in a markup language. While most often used to style web pages and interfaces written in HTML and XHTML, the language can be applied to any kind of XML document. CSS is designed primarily to enable the separation of document content from document presentation, including elements such as the layout, colors, and fonts. This separation can improve content accessibility, provide more flexibility and control in the specification of presentation characteristics, enable multiple pages to share formatting, and reduce complexity and repetition in the structural content (such as by allowing for tableless web design). CSS can also allow the same markup page to be presented in different styles for different rendering methods, such as on-screen, in print, by voice (when read out by a speech-based browser or screen reader) and on Braille-based, tactile devices. It can also be used to allow the web page to display differently depending on the screen size or device on which it is being viewed. While the author of a document typically links that document to a CSS file, readers can use a different style sheet, perhaps one on their own computer, to override the one the author has specified. CSS specifies a priority scheme to determine which style rules apply if more than one rule matches against a particular element. In this so-called cascade, priorities or weights are calculated and assigned to rules, so that the results are predictable. The CSS specifications are maintained by the World Wide Web Consortium (W3C). Source: Cascading Style Sheets. Wikipedia. Wikimedia Foundation, 26 Dec. 2013. Web. 30 Dec. 2013. <http://en.wikipedia.org/wiki/cascading_style_sheets>. 1

Applying CSS There are three ways to apply CSS to HTML: In-line, internal, and external In-line In-line styles are plonked straight into the HTML tags using the style attribute. They look something like this: <p style="color: red">text</p> This will make that specific paragraph red. But, if you remember, the best-practice approach is that the HTML should be a stand-alone, presentation free document, and so in-line styles should be avoided wherever possible. Internal Embedded, or internal, styles are used for the whole page. Inside the head element, the style tags surround all of the styles for the page. <!DOCTYPE html> <html> <head> <title>css Example</title> <style> p { color: red; a { color: blue; </style>... This will make all of the paragraphs in the page red and all of the links blue. Although preferable to soiling our HTML with inline presentation, it is similarly usually preferable to keep the HTML and the CSS files separate, and so we are left with our savior 2

External External styles are used for the whole, multiple-page website. There is a separate CSS file, which will simply look something like: p { color: red; a { color: blue; If this file is saved as style.css in the same directory as your HTML page then it can be linked to in the HTML like this: <!DOCTYPE html> <html> <head> <title>css Example</title> <link rel="stylesheet" href="style.css"> Selectors, Properties, and Values Whereas HTML has tags, CSS has selectors. Selectors are the names given to styles in internal and external style sheets. In this CSS Beginner Tutorial we will be concentrating on HTML selectors, which are simply the names of HTML tags and are used to change the style of a specific type of element. For each selector there are properties inside curly brackets, which simply take the form of words such as color, font-weight or background-color. A value is given to the property following a colon (NOT an equals sign) and semi-colons separate the properties. body { font-size: 14px; color: navy; This will apply the given values to the font-size and color properties to the body selector. So basically, when this is applied to an HTML document, text between the body tags (which is the content of the whole window) will be 14 pixels in size and navy in color. 3

Lengths and Percentages There are many property-specific units for values used in CSS, but there are some general units that are used by a number of properties and it is worth familiarizing yourself with these before continuing. px (such as font-size: 12px) is the unit for pixels. em (such as font-size: 2em) is the unit for the calculated size of a font. So 2em, for example, is two times the current font size. pt (such as font-size: 12pt) is the unit for points, for measurements typically in printed media. % (such as width: 80%) is the unit for wait for it percentages. Other units include pc (picas), cm (centimeters), mm (millimeters) and in (inches). When a value is zero, you do not need to state a unit. For example, if you wanted to specify no border, it would be border: 0. Note: px in this case, doesn t actually necessarily mean pixels - the little squares that make up a computer s display - all of the time. Modern browsers allow users to zoom in and out of a page so that, even if you specify fontsize: 12px, or height: 200px, for example, although these will be the genuine specified size on a non-zoomed browser, they will still increase and decrease in size with the user s preference. It s a good thing. Trust me. Colors The following values, to specify full-on as red-as-red-can-be, all produce the same result: red rgb(255,0,0) rgb(100%,0%,0%) #ff0000 #f00 Predefined color names include aqua, black, blue, fuchsia, gray, green, lime, maroon, navy, olive, orange, purple, red, silver, teal, white, and yellow. transparent is also a valid value. Note: With the possible exception of black and white, color names have limited use in a modern, well-designed web sites because they are so specific and limiting. 4

The three values in the RGB value are from 0 to 255, 0 being the lowest level (no red, for example), 255 being the highest level (full red, for example). These values can also be a percentage. Hexadecimal (previously and more accurately known as sexadecimal ) is a base-16 number system. We are generally used to the decimal number system (base-10, from 0 to 9), but hexadecimal has 16 digits, from 0 to f. The hex number is prefixed with a hash character (#) and can be three or six digits in length. Basically, the three-digit version is a compressed version of the six-digit (#ff0000 becomes #f00, #cc9966 becomes #c96, etc.). The three-digit version is easier to decipher (the first digit, like the first value in RGB, is red, the second green and the third blue) but the six-digit version gives you more control over the exact color. color and background-color Colors can be applied by using color and background-color (note that this must be the American English color and not colour ). A blue background and yellow text could look like this: h1 { color: yellow; background-color: blue; These colors might be a little too harsh, so you could change the code of your CSS file for slightly different shades: body { font-size: 14px; color: navy; h1 { color: #ffc; background-color: #009; You can apply the color and background-color properties to most HTML elements, including body, which will change the colors of the page and everything in it. 5

Text You can alter the size and shape of the text on a web page with a range of properties. font-family This is the font itself, such as Times New Roman, Arial, or Verdana. The user s browser has to be able to find the font you specify, which, in most cases, means it needs to be on their computer so there is little point in using obscure fonts that are only sitting on your computer. There are a select few safe fonts (the most commonly used are Arial, Verdana and Times New Roman), but you can specify more than one font, separated by commas. The purpose of this is that if the user does not have the first font you specify, the browser will go through the list until it finds one it does have. This is useful because different computers sometimes have different fonts installed. So font-family: arial, helvetica, serif, will look for the Arial font first and, if the browser can t find it, it will search for Helvetica, and then a common serif font. Note: if the name of a font is more than one word, it should be put in quotation marks, such as fontfamily: "Times New Roman". font-size The size of the font. Be careful with this - text such as headings should not just be an HTML paragraph (p) in a large font - you should still use headings (h1, h2 etc.) even though, in practice, you could make the font-size of a paragraph larger than that of a heading (not recommended for sensible people). font-weight This states whether the text is bold or not. Most commonly this is used as font-weight: bold or font-weight: normal but other values are bolder, lighter, 100, 200, 300, 400 (same as normal), 500, 600, 700 (same as bold), 800 or 900. Note: Play around with these font-weight values if you want see their effect but, keep in mind, that some older browsers become a little confused with anything other than bold and normal so we suggest sticking to those unless you re a typography ninja. 6

font-style This states whether the text is italic or not. It can be font-style: italic or font-style: normal. text-decoration This states whether the text has got a line running under, over, or through it. text-decoration: underline, does what you would expect. text-decoration: overline places a line above the text. text-decoration: line-through puts a line through the text ( strike-through ). This property is usually used to decorate links and you can specify no underline with textdecoration: none. Note: Underlines should only really be used for links. They are a commonly understood web convention that has lead users to generally expect underlined text to be a link. 7

text-transform This will change the case of the text. text-transform: capitalize turns the first letter of every word into uppercase. text-transform: uppercase turns everything into uppercase. text-transform: lowercase turns everything into lowercase. text-transform: none I ll leave for you to work out. So, a few of these things used together might look like this: body { font-family: arial, helvetica, sans-serif; font-size: 14px; h1 { font-size: 2em; h2 { font-size: 1.5em; a { text-decoration: none; strong { font-style: italic; text-transform: uppercase; Text spacing Before we move on from this introduction to styling text, a quick look at how to space out the text on a page: The letter-spacing and word-spacing properties are for spacing between letters or words. The value can be a length or normal. The line-height property sets the height of the lines in an element, such as a paragraph, without adjusting the size of the font. It can be a number (which specifies a multiple of the font size, so 2 will be two times the font size, for example), a length, a percentage, or normal. The text-align property will align the text inside an element to left, right, center, or justify. 8

The text-indent property will indent the first line of a paragraph, for example, to a given length or percentage. This is a style traditionally used in print, but rarely in digital media such as the web. p { letter-spacing: 0.5em; word-spacing: 2em; line-height: 1.5; text-align: center; Margins and Padding margin and padding are the two most commonly used properties for spacing-out elements. A margin is the space outside something, whereas padding is the space inside something. h2 { font-size: 1.5em; background-color: #ccc; margin: 20px; padding: 40px; This leaves a 20-pixel width space around the secondary header and the header itself is fat from the 40- pixel width padding. The four sides of an element can also be set individually. margin-top, margin-right, marginbottom, margin-left, padding-top, padding-right, padding-bottom and paddingleft are the self-explanatory properties you can use. 9

The Box Model Margins, padding and borders (see below) are all part of what s known as the Box Model. The Box Model works like this: in the middle you have the content area (let s say an image), surrounding that you have the padding, surrounding that you have the border and surrounding that you have the margin. It can be visually represented like this: You don t have to use all of these, but it can be helpful to remember that the box model can be applied to every element on the page, and that s a powerful thing! Borders Borders can be applied to most HTML elements within the body. To make a border around an element, all you need is border-style. The values can be solid, dotted, dashed, double, groove, ridge, inset and outset. border-width sets the width of the border, most commonly using pixels as a value. There are also properties for border-top-width, border-right-width, border-bottom-width and border-left-width. 10

Finally, border-color sets the color. h2 { border-style: dashed; border-width: 3px; border-left-width: 10px; border-right-width: 10px; border-color: red; This will make a red dashed border around all HTML secondary headers (the h2 element) that is 3 pixels wide on the top and bottom and 10 pixels wide on the left and right (these having over-ridden the 3 pixel wide width of the entire border). Putting It All Together The code below covers all of the CSS methods covered in this document. If you save this as your CSS file and look at the HTML file then you should now understand what each CSS property does and how to apply them. The best way to fully understand all of this is to mess around with the HTML and the CSS files and see what happens when you change things. body { font-family: arial, helvetica, sans-serif; font-size: 14px; color: black; background-color: #ffc; margin: 20px; padding: 0; /* This is a comment, by the way */ p { line-height: 21px; h1 { color: #ffc; background-color: #900; font-size: 2em; margin: 0; margin-bottom: 7px; padding: 4px; font-style: italic; text-align: center; letter-spacing: 0.5em; border-bottom-style: solid; border-bottom-width: 0.5em; 11

border-bottom-color: #c00; h2 { color: white; background-color: #090; font-size: 1.5em; margin: 0; padding: 2px; padding-left: 14px; h3 { color: #999; font-size: 1.25em; img { border-style: dashed; border-width: 2px; border-color: #ccc; a { text-decoration: none; strong { font-style: italic; text-transform: uppercase; li { color: #900; font-style: italic; table { background-color: #ccc; Article Source: Griffiths, Patrick. "CSS Beginner Tutorial." HTML, CSS, and JavaScript Tutorials, References, and Articles. HTML Dog, n.d. Web. 30 Dec. 2013. <http://www.htmldog.com/guides/css/beginner/>. 12