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

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

Reading 2.2 Cascading Style Sheets

CSS: The Basics CISC 282 September 20, 2014

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

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

CSC309 Programming on the Web week 3: css, rwd

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

Chapter 3 Style Sheets: CSS

Assignments (4) Assessment as per Schedule (2)

Cascading Style Sheets (CSS)

CSS 1: Introduction. Chapter 3

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

CSS - Cascading Style Sheets

Cascading Style Sheets Level 2

Client-Side Web Technologies. CSS Part I

CSS.

CSS. Shan-Hung Wu CS, NTHU

Appendix D CSS Properties and Values

HTML/XML. HTML Continued Introduction to CSS

Introduction to WEB PROGRAMMING

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

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

Web Design and Development Tutorial 03

Web Site Design and Development Lecture 13

CSS: Cascading Style Sheets

CSS. Selectors & Measurments. Copyright DevelopIntelligence LLC

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

CSS: Cascading Style Sheets

COMS 359: Interactive Media

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

CSS Cascading Style Sheets

BIM222 Internet Programming

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

Styles, Style Sheets, the Box Model and Liquid Layout

CMPT 165 INTRODUCTION TO THE INTERNET AND THE WORLD WIDE WEB

Adding CSS to your HTML

Three Ways to Use CSS:

INTRODUCTION TO CSS. Topics MODULE 5

Session 4. Style Sheets (CSS) Reading & References. A reference containing tables of CSS properties

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

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

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

Block & Inline Elements

Web Information System Design No.4 Put Style to Web Documents. Tatsuya Hagino

Tutorial 3: Working with Cascading Style Sheets

Web Development & Design Foundations with HTML5

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

Cascading style sheets, HTML, DOM and Javascript

DAY 4. Coding External Style Sheets

Web Programming and Design. MPT Senior Cycle Tutor: Tamara Week 2

INFORMATICA GENERALE 2014/2015 LINGUAGGI DI MARKUP CSS

Web Development & Design Foundations with HTML5

APPLIED COMPUTING 1P01 Fluency with Technology

Creating and Building Websites

INTRODUCTION TO CSS. Mohammad Jawad Kadhim

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

COSC 2206 Internet Tools. CSS Cascading Style Sheets

CSS FOUNDATIONS IN-DEPTH. The nitty-gritty of css...

8a. Cascading Style Sheet

Web Design and Development ACS-1809

ITNP43: HTML Lecture 5

Cascading Style Sheets. Overview and Basic use of CSS

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

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

Cascading Style Sheets CSCI 311

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

CSS. Location, Inheritance & the Cascade. Copyright DevelopIntelligence LLC

IDM 221. Web Design I. IDM 221: Web Authoring I 1

Introduction to Web Tech and Programming

CSS THE M\SS1NG MANUAL. David Sawyer McFarland. POGUE PRESS" O'REILLr Beijing Cambridge Farnham Köln Paris Sebastopol Taipei Tokyo

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

ITNP43: HTML Lecture 4

CSS Cascading Style Sheets

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

Chapter 4 CSS basics

Introducing Cascading Style Sheets. Cascading Style Sheet Basics Creating Styles Using Styles Manipulating Styles Text Formatting with CSS

Lab Introduction to Cascading Style Sheets

Class 3 Page 1. Using DW tools to learn CSS. Intro to Web Design using Dreamweaver (VBUS 010) Instructor: Robert Lee

Web Programming and Design. MPT Junior Cycle Tutor: Tamara Demonstrators: Aaron, Marion, Hugh

ID1354 Internet Applications

Cascading Style Sheets (Part 3): Images and Text. Mike Hamilton V.P. Product Evangelism MadCap Software

Cascade Stylesheets (CSS)

WEB DEVELOPMENT & DESIGN FOUNDATIONS WITH HTML5

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

Tutorial 4: Creating Special Effects with CSS

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

CSS Styles Quick Reference Guide

INTRODUCTION TO HTML5! CSS Styles!

FLOATING AND POSITIONING

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

HTML/CSS. HTML review and extra CSS review CSS Color

Controlling Appearance the Old Way

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

Objective % Select and utilize tools to design and develop websites.

ACSC 231 Internet Technologies

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

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

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

Cascading Style Sheets (CSS) Part 1 of 3: Introduction and overview

Transcription:

11 INTRODUCING CSS

OVERVIEW The benefits of CSS Inheritance Understanding document structure Writing style rules Attaching styles to the HTML document The cascade The box model CSS units of measurement

The Benefits of CSS Precise type and layout control Less work: Change look of the whole site with one edit Accessibility: Markup stays semantic Flexibility: The same HTML markup can be made to appear in dramatically different ways

Style Separate from Structure These pages have the exact same HTML source but different style sheets: (csszengarden.com)

How Style Sheets Work 1. Start with a marked up document (like HTML, but could be another XML markup language). 2. Write styles for how you want elements to look using CSS syntax. 3. Attach the styles to the document (there are a number of ways). 4. The browser uses your instructions when rendering the elements.

Style Rules Each rule selects an element and declares how it should display. h1 { color: green; } This rule selects all h1 elements and declares that they should be green. strong { color: red; font-style: italic; } This rule selects all strong inline elements and declares that they should be red and in an italic font.

Style Rule Structure A style rule is made up of a selector a declaration. The declaration is one or more property / value pairs.

Selectors There are many types of selectors. Here are just two examples: p {property: value;} Element type selector: Selects all elements of this type (p) in the document. #intro {property: value} ID selector (indicated by the # symbol) selects by ID value. In the example, an element with an id of intro would be selected.

Declarations The declaration is made up of a property/value pair contained in curly brackets { }: selector { property: value; } Example h2 { color: red; font-size: 2em; margin-left: 30px; opacity:.5; }

Declarations (cont d) End each declaration with a semicolon to keep it separate from the next declaration. White space is ignored, so you can stack declarations to make them easier to read. Properties are defined in the CSS specifications. Values are dependent on the type of property: Measurements Keywords Color values More

CSS Comments /* comment goes here */ Content between /* and */ will be ignored by the browser. Useful for leaving notes or section labels in the style sheet. Can be used within rules to temporarily hide style declarations in the design process.

Adding Styles to the Document There are three ways to attach a style sheet to a document: External style sheets A separate, text-only.css file associated with the document with the link element or @import rule Embedded style sheets Styles are listed in the head of the HTML document in the style element. Inline styles Properties and values are added to an individual element with the style attribute.

External Style Sheets The style rules are saved in a separate text-only.css file and attached via link or @import. Via link element in HTML: <head> <title>titles are require</title> <link rel="stylesheet" href="/path/example.css"> </head> Via @import rule in a style sheet: <head> <title>titles are required</title> <style> @import url("/path/example.css"); p {font-face: Verdana;} </style> </head>

Embedded Style Sheets Embedded style sheets are placed in the head of the document via the style element: <head> <title>titles are required</title> <style> /* style rules go here */ </style> </head>

Inline Styles Apply a style declaration to a single element with the style attribute: <p style="font-size: large;">paragraph text...</p> To add multiple properties, separate them with semicolons: <h3 style="color: red; margin-top: 30px;">Intro</h3>

Document Structure Documents have an implicit structure. We give certain relationships names, as if they re a family: All the elements contained in a given element are its descendents. An element that is directly contained within another element is the child of that element. The containing element is the parent of the contained element. Two elements with the same parent are siblings.

Inheritance Many properties applied to elements are passed down to the elements they contain. This is called inheritance. For example, applying a sans-serif font to a p element causes the em element it contains to be sans-serif as well:

Inheritance (cont d) Some properties inherit; others do not. Properties related to text usually inherit; properties related to layout generally don t. Styles explicitly applied to specific elements override inherited styles. You ll learn to use inheritance strategically to keep your style rules simple.

The Cascade The cascade refers to the system for resolving conflicts when several styles apply to the same element. Style information is passed down (it cascades down) until overwritten by a style rule with more weight. Weight is considered based on: Priority of style rule source Specificity of the selector Rule order

The Cascade: Priority Style rules from sources higher in this list override rules from sources listed below them. Any style marked as!important by the user (to accommodate potential accessibility settings) Any style marked!important by the author (of the web page) Author styles (style sheets created in web site production) User styles (added by the reader) User agent styles (browser defaults)

The Cascade: Specificity When two rules in a single style sheet conflict, the type of selector is used to determine which rule has more weight. For example, ID selectors are more specific than general element selectors. NOTE: Specificity will be discussed once we have covered more selector types.

The Cascade: Rule Order When two rules have equal weight, rule order is used. Whichever rule appears last wins. <style> p {color: red;} p {color: blue;} p {color: green;} </style> In this example, paragraphs would be green. Styles may come in from external style sheets, embedded style rules, and inline styles. The style rule that gets parsed last (the one closest to the content) will apply.

The Box Model Browsers see every element on the page as being contained in a little rectangular box. Block elements and inline elements participate in the box model. In this example, a blue border is added to all elements.

The Box Model (cont d) The box model is the foundation of CSS page layout. Apply properties such as borders, margins, padding, and backgrounds to element boxes. Position, move, grow, and shrink boxes to create fixed or flexible page layouts.

CSS Units of Measurement CSS provides a variety ways to specify measurements: Absolute units Have predefined meanings or real-world equivalents Relative units Based on the size of something else, such as the default text size or the size of the parent element Percentages Calculated relative to another value, such as the size of the parent element

Absolute Units With the exception of pixels, absolute units are not appropriate for web design: px in mm cm q pt pc pixel inches millimeters centimeters 1/4 millimeter points (1/72 inch) pica (1 pica = 12 points = 1/6 inch)

Relative Units Relative units are based on the size of something else: em a unit equal to the current font size ex x-height, equal to the height of a lowercase x rem root em, equal to the font size of the html element ch zero width, equal to the width of a zero (0) vw viewport width unit (equal to 1/100 of viewport width) vh viewport height unit (1/100 of viewport height) vmin viewport minimum unit (value of vh or vw, whichever is smaller) vmax viewport maximum unit (value of vh or vw, whichever is larger)

RELATIVE UNITS The rem Unit The rem (root em) unit is based on the font size of the html element, whatever that happens to be. Default in modern browsers: Root font size is 16 pixels, so a rem = a 16-pixel unit. If the root font size of the document changes, so does the size of a rem (and that s good for keeping elements proportional).

RELATIVE UNITS The em Unit The em unit is traditionally based on the width of a capital letter M in the font. When the font size is 16 pixels,1em = 16 pixels, 2em = 32 pixels, and so on. NOTE: Because they re based on the font size of the current element, the size of an em may not be consistent across a page.

RELATIVE UNITS Viewport Percentage Lengths (vw/vh) Viewport width (vw) and viewport height (vh) units are relative to the size of the viewport (browser window): vh = 1/100th width of viewport vh = 1/100th height of viewport They re useful for making an element fill the viewport or a specified percentage of it. This image will be 50% the width and height of the viewport: img { width: 50vw; height: 50vh; }

Browser Developer Tools Major browsers have built-in tools that aid development: HTML, CSS, and JavaScript inspectors Network speed reports Animation tools Other helpful features

Browser Developer Tools (cont d) Chrome DevTools (View > Developer > Developer Tools) Firefox, Safari, Opera, and Microsoft Edge also have developer tools.