Week 4.  Three ways to apply CSS: Inline CSS Internal style sheets ( header style information) External style sheets.

Slides:



Advertisements
Similar presentations
CSS Cascading Style Sheets. Objectives Using Inline Styles Working with Selectors Using Embedded Styles Using an External Style Sheet Applying a Style.
Advertisements

Cascading Style Sheets
CSS CSS Precise Aesthetic Control. Cascading Style Sheets Though they can be put in HTML header, usually a separate page that the HTML links to Contains.
Cascading Style Sheets. CSS stands for Cascading Style Sheets and is a simple styling language which allows attaching style to HTML elements. CSS is a.
Cascading Style Sheets Basics. Why use Cascading Style Sheets? Allows you to set up a series of rules for all pages in a site. The series may be changed.
© 2004, Robert K. Moniot Chapter 6 CSS : Cascading Style Sheets.
CSS BASICS. CSS Rules Components of a CSS Rule  Selector: Part of the rule that targets an element to be styled  Declaration: Two or more parts: a.
1 Pengantar Teknologi Internet W03: CSS Cascading Style Sheets.
Recognizing the Benefits of Using CSS 1. The Evolution of CSS CSS was developed to standardize display information CSS was slow to be supported by browsers.
กระบวนวิชา CSS. What is CSS? CSS stands for Cascading Style Sheets Styles define how to display HTML elements Styles were added to HTML 4.0 to.
© 2010, Robert K. Moniot Chapter 5 CSS : Cascading Style Sheets 1.
Week 7 Web Typography. 2 Understanding Type Design Principles.
SM5312 week 6: basic CSS syntax1 An Introduction to Cascading Style Sheets Basic CSS Syntax Nick Foxall.
XP 1 Working with Cascading Style Sheets Creating a Style for Online Scrapbooks Tutorial 7.
4.01 Cascading Style Sheets
CSS: Cascading Style Sheets. 2 History HTML tags were originally designed to define the content of a document. The layout of the document was supposed.
Principles of Web Design 6 th Edition Chapter 4 – Cascading Style Sheets.
Review: Three parts to a webpage: - Content - Structure  XHTML - Presentation  CSS In this chapter we will focus on introducing and examining the mechanics.
Cascading style sheets (CSS)
Dreamweaver -- CSS. Dreamweaver -- MX New icons are added in MX Most of the features commonly used in web design, and are same as FrontPage. New feature.
Cascading Style Sheets (CSS) 1.  What is CSS?  Why CSS?  How to write a CSS? 2.
Copyright © Terry Felke-Morris WEB DEVELOPMENT & DESIGN FOUNDATIONS WITH HTML5 Chapter 3 Key Concepts 1 Copyright © Terry Felke-Morris.
Cascading Style Sheets CSS.  Standard defined by the W3C  CSS1 (released 1996) 50 properties  CSS2 (released 1998) 150 properties (positioning)  CSS3.
Cascading Style Sheets. Defines the presentation of one or more web pages Similar to a template Can control the appearance of an entire web site giving.
Chapter 12 Cascading Style Sheets: Part II The Web Warrior Guide to Web Design Technologies.
Copyright © Terry Felke-Morris WEB DEVELOPMENT & DESIGN FOUNDATIONS WITH HTML5 7 TH EDITION Chapter 3 Key Concepts 1 Copyright © Terry Felke-Morris.
Today’s objectives  Review  CSS | Rules | Declarations  HTML Structure document  Class asignment.
 This presentation introduces the following: › 3 types of CSS › CSS syntax › CSS comments › CSS and color › The box model.
Today’s objectives  Review  CSS | Rules | Declarations  HTML Structure document  Class asignment.
Cascading Style Sheets Orientation Learning Web Design: Chapter 11.
CO1552 – Web Application Development Cascading Style Sheets.
Cascading Style Sheets Class 2, Lecture 2 Rachel A Ober
XP Tutorial 7New Perspectives on HTML and XHTML, Comprehensive 1 Working with Cascading Style Sheets Tutorial 7.
Lesson 03 // Cascading Style Sheets. CSS Stands for Cascading Style Sheets. We’ll be using a combination of Html and CSS to create websites. CSS is a.
Chapter 6 Introducing Cascading Style Sheets Principles of Web Design, 4 th Edition.
ECA225 Applied Interactive Programming Cascading Style Sheets, pt 1 ECA 225 Applied Online Programming.
Course created by Sarah Phillips BBCD Melbourne BAPDCOM Version 1 – April 2013.
Cascading Style Sheets Level 2. Course Objectives, Session 1 Level 1 Quick Review Chapter 8: Adding Graphics to Web Pages Chapter 9: Sprucing Up Your.
Cascading Style Sheets
Cascading Style Sheets CSS.  Standard defined by the W3C  CSS1 (released 1996) 50 properties  CSS2 (released 1998) 150 properties (positioning)  CSS3.
Cascading Style Sheets (CSS). A style sheet is a document which describes the presentation semantics of a document written in a mark-up language such.
Cascading Style Sheets Eugenia Fernandez IUPUI. CSS Purpose CSS allow you to specify the style in which your XML elements are displayed. CSS were originally.
XP Review 2 New Perspectives on JavaScript, Comprehensive1 Introducing Cascading Style Sheets Formatting Web Pages with CSS.
CS 174: Web Programming September 9 Class Meeting Department of Computer Science San Jose State University Fall 2015 Instructor: Ron Mak
CSS Fun damentals The Document Hierarchy Element Relationships The Box Model.
CNIT 132 – Week 4 Cascading Style Sheets. Introducing Cascading Style Sheets Style sheets are files or forms that describe the layout and appearance of.
Microsoft Expression Web 3 – Illustrated Unit D: Structuring and Styling Text.
Cascading Style Sheets Primary readings Presentations Explain & review projects with class mates.
Developing Web Applications with HTML and CSS “Selectors and Properties”
CSS: Cascading Style Sheets Part II. Style Syntax.
NASRULLAHIBA.  It is time to take your web designing skills to the next level with Cascading Style Sheets (CSS). They are a way to control the look and.
CH 12 CSS Style Sheets 1. Objective What is CSS? Selecting elements Different rules for different media Importing style sheets 2.
ECA 228 Internet/Intranet Design I Cascading Style Sheets.
Chapter 6 Introducing Cascading Style Sheets Principles of Web Design, Third Edition.
Chapter 11 & 12 CSS Style Sheets: Intro. Why CSS? Separate presentation from content – more accessible Less work – can change appearance of whole site.
Internet & World Wide Web How to Program, 5/e Copyright © Pearson, Inc All Rights Reserved.
CSS Introductions. Objectives To take control of the appearance of a Web site by creating style sheets. To use a style sheet to give all the pages of.
IS 360 Understanding CSS Selectors. Slide 2 Types of Selectors There are different types of selectors Each has a different level of “specificity” An element.
Internet & World Wide Web How to Program, 5/e 1. 2.
WEB FOUNDATIONS CSS Overview. Outline  What is CSS  What does it do  Where are styles stored  Why use them  What is the cascade effect  CSS Syntax.
IS 360 Declaring CSS Styles
Cascading Style Sheets
IS333: MULTI-TIER APPLICATION DEVELOPMENT
CSS Style Sheets: Intro
IS 360 Understanding CSS Selectors
Cascading Style Sheets
The Internet 10/20/11 CSS Layout
Presentation transcript:

Week 4

 Three ways to apply CSS: Inline CSS Internal style sheets ( header style information) External style sheets

 Add style declarations directly to elements by specifying values into style attributes This is a paragraph. This is another paragraph with more text.

 CSS rules placed inside the element within the document Internal Style Sheet Example p { color: red; } This is a paragraph. This is another paragraph with more text.

 CSS rules placed inside a separate file with a.css extension; file is referenced with a element in the document Internal Style Sheet Example This is a paragraph. This is another paragraph with more text.

 You won’t likely use inline CSS unless you want to override an internal or external style sheet (troubleshooting inheritance or cascade problems)  Inline style sheets better – all rules in one place for easy updating but, this only applies to that document  External style sheets are best – allows for styling many documents from one place and separates presentation from content

 Element selector: p  ID selector: #  Class selector:. HTML Chapter 1 Lorem ipsum CSS #chapter { font-size: 3.5em; }.summary { font-style: italic; } p {font-family: Arial, Helvetica, sans-serif; }

 Selects the right-hand element only if it’s a direct child of the left-hand element. Not supported in IE 6 or earlier CSS li > p { color: red; } HTML selects Lorem ipsum But not Lorem ipsum This is a child selector combinator

 Similar to child selector except right-hand element does not need to be direct child of left-hand element – it can select elements further down the DOM hierarchy CSS li p { color: red; } HTML selects Lorem ipsum and Lorem ipsum But not Lorem ipsum The white space is the descendant selector combinator

 Select every single element in a document * { border-color: red; }

 Select any element with the attribute specified in the square brackets. Can be just the attribute type or an attribute with a specific value CSS img[alt] { border-color: red; } img[src=“image.png”=] { border-color: red; } HTML

 This selects the right-hand element only if it has an instance of the element on the left-hand side next to it, on the same level of the DOM hierarchy. These selectors not support in IE6 or earlier h2 + p { color: red; } Heading A paragraph But not A paragraph Nor Heading A paragraph This is the adjacent sibling selector combinator

 Styles elements based on their states, typically link behaviour a:hover { color: red; } All links will change to the colour red when the mouse hovers over them

 Allows for styling of specific content parts of an element rather than the whole element p:first-letter { font-size: 300%; } Triples the size of the first letter of each paragraph p:first-line { font-weight: bold; } Bolds the first line of each paragraph

 Give multiple selectors the same style by listing them together separated by commas HTML Chapter 1 Lorem ipsum CSS #chapter,.summary { font-style: italic; } p, #chapter { color: rgb(240,128,96); }

 Create even more specific selectors by joining selectors HTML Chapter 1 Lorem ipsum CSS p.class { color: red; } h1#chapter { color: red; }

 Sometimes two or more conflicting styles may be applied to the same element  How do you resolve this conflict and decide which one actually gets applied?  You need to understand inheritance and the cascade

 Just as in genetics where traits can be inherited by children from their parents,  This is the mechanism by which certain properties can be passed from a parent element to its child elements  Without it you’d have to specify every property for every element every time you wrote a web page

 Much easier to specify the default font on the element knowing that all child elements of will inherit that property body { font-family: Georgia; } h1, h2, h3 { font-family: Helvetica; } /* This overrides the first rule because it is listed later in the code */

 Not all properties are inherited  e.g., margins, borders  Common sense should tell you what is and isn’t inheritable, or review the CSS 2.1 specification property summary table:

 The “Cascade” in Cascading Style Sheets (CSS)  The mechanism that determines the end result when when multiple conflicting and overlapping rules apply to the same element  Three concepts: Importance Specificity Source order

 Importance is important; if two declarations have the same importance then the specificity of the rule determines which one is applied  If two declarations have the same specificity, then the source order determines which rule wins

 Importance of a CSS declaration depends on where it is specified.  Conflicting rules are applied using the following order; later ones override earlier ones: User agent style sheets Normal declarations in author style sheets Normal declarations in user style sheets Important declarations in author style sheets Important declarations in user style sheets

 User agent style sheet Built-in browser style sheet (default properties)  User style sheet Not all browsers support this but users can add their own. Typically used to enhance accessibility  Author style sheet This is the “style sheet” that we normally think of Written by the web designer

 Normal declarations are normal declarations  Important declarations are just the opposite: important; these are declarations followed by the !important directive: * { font-family: Helvetica !important; }  Default browser rendering of elements are not overridden unless a rule in user or author style sheet is specified

 Key concept that all web designers need to understand  A measure of how specific a rule selector is  Selectors with low specificity may match many elements on the page  Selectors with high specificity may match a single element on a page  e.g., p matches every paragraph in a document whereas #nav, only matches the element with the id of nav

 If two or more rules conflict and all have equal importance, then the rule with the most specific selector wins  Specificity has four components; call them a, b, c, and d  Component “a” is the most distinguishing and “d” the least

 Component “a” given 1 for declaration in a style attribute, otherwise it’s 0  Component “b” is the number of id selectors in the selector (those that begin with #)  Component “c” is the number of attribute selectors, class selectors, and pseudo- classes  Component “d” is the number of element selectors and pseudo-elements

SelectorABCDSpecificity h100010,0,0,1.foo00100,0,1,0 #bar01000,1,0,0 ul#nav a:link01120,1,1,2

 Combinators like >, + and the white space (descendant selector) have no effect on specificity  id selector is not the same specificity as an attribute selector that refers to the same id attribute  [id=“nav”] has a specificity of 0,0,1,0 wheras #nav has a specificity of 0,1,0,0

 Given conflicting rules with the same importance and the same specificity, source order is used to determine the winner: the declaration that appears later in the style sheet  In a single external style sheet the declarations at the end of the file override those at the beginning when they conflict  If the conflicting rules appear in different style sheets the order in which they are linked or imported controls which one is applied If there are two linked style sheets in the of a document the one linked last overrides the one linked first

 Margin – defines the space between block elements The space around a block element MarginPaddingBorderContent Width Height  Border – sets a visible border around the element’s content  Content – represented by text characters and displayed in a typeface  Padding – sets the space between the content and inner border edge  Height – default is distance between ascender and descender  Width – default is width of the line of text

 When adjacent elements have top and bottom margins that meet, you would assume the total space between the two elements is the sum of the bottom margin of one element and the top margin of the next element  In CSS the value collapses to the larger value of the two element margins  If the values were the effective value is 10  If they were the effective value is 5