SE-2840 Dr. Mark L. Hornick 1 Separating Structure from Presentation: CSS.

Slides:



Advertisements
Similar presentations
Intro to HTML. HTML HTML = HyperText Markup Language Used to define the content of a webpage HTML is made up of tags and attributes Content.
Advertisements

Introduction to HTML & CSS
Cascading Style Sheets (CSS). Cascading Style Sheets With the explosive growth of the World Wide Web, designers and programmers quickly explored and reached.
CSS Cascading Style Sheets. Objectives Using Inline Styles Working with Selectors Using Embedded Styles Using an External Style Sheet Applying a Style.
Making Things Look Nice: Visual Appearance and CSS CMPT 281.
Outline IS400: Development of Business Applications on the Internet Fall 2004 Instructor: Dr. Boris Jukic CSS: Cascading Style Sheets.
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.
Controlling Page Style: Cascading Style Sheets (CSS) References: 1.Wang, P.S & Katila, S. (2004). A Introduction to Web Design and Programming. CA: Thomson.
HTML BASIC
3.1 Cascading Style Sheets. Motto Fashions fade, style is eternal. —Yves Saint Laurent.
1 Working with Cascading Style Sheet (CSS). 2 Cascading Style Sheets (CSS)  a style defines the appearance of a document element. o E.g., font size,
Principles of Web Design 6 th Edition Chapter 4 – Cascading Style Sheets.
Working with Cascading Style Sheets. Introducing Cascading Style Sheets Style sheets are files or forms that describe the layout and appearance of a document.
Cascading Style Sheets (CSS) Instructor: Mr. Ahmed Al Astal ITGD4104 Department Requirement for senior student University of Palestine Faculty of IT.
Cascading Style Sheets Part 1 Library and Information Services, University of St Andrews.
Review: Three parts to a webpage: - Content - Structure  XHTML - Presentation  CSS In this chapter we will focus on introducing and examining the mechanics.
Week 4.  Three ways to apply CSS: Inline CSS Internal style sheets ( header style information) External 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 Sheet (CSS)
Today’s objectives  Complete web page  Using xhtml & CSS  Adding CSS to documents Embed url(File);  CSS.
Today’s objectives  Presentational | Inline | Block | Validate  CSS | Rules | Declarations.
Introduction to CSS CSS Syntax - Fort Collins, CO Copyright © XTR Systems, LLC Cascading Style Sheets - Syntax & Semantics Instructor: Joseph DiVerdi,
ITEC 745 Instructional Web Authoring I Instructor: Ray Cole Week 8.
I NTRO TO CSS IAT100 Spring I NTRO TO CSS Covered in this lesson: Overview What is CSS? Why to use CSS? CSS for Skinning your Website Structure.
1 WDMD 170 – UW Stevens Point WDMD 170 Internet Languages eLesson: CSS Introduction to Style Sheets (NON-audio version) © Dr. David C. Gibbs
Cascading Style Sheets by Pavlovic Nenad by. Presentation Contents  What is CSS?  Why CSS?  Types of Style Sheets  Style Sheets Syntax  Box Formatting.
Today’s objectives  Review  CSS | Rules | Declarations  HTML Structure document  Class asignment.
ITCS373: Internet Technology Week 3: Introduction to CSS Dr. Faisal Al-Qaed.
Website Development & Management Working with Style Rules Instructor: John Seydel, Ph.D. CIT Fall
Part 1: CSS - Why? - How it works - Writing rules - Examples.
 This presentation introduces the following: › 3 types of CSS › CSS syntax › CSS comments › CSS and color › The box model.
Introduction to Programming the WWW I CMSC Summer 2004 Lecture 7.
Cascading Style Sheets Orientation Learning Web Design: Chapter 11.
Introduction to CSS. What is CSS?  Cascading Style Sheets  Used for styling HTML  Also important in javascript and jquery for selectors  External.
Cascading Style Sheets Part 1. CSS vs HTML HTML: Originally intended to markup structure of a document (,...,,,,,...) CSS Developing technology, CSS1,
XP Tutorial 7New Perspectives on HTML and XHTML, Comprehensive 1 Working with Cascading Style Sheets Tutorial 7.
CSS Tutorial 1 Introduction Syntax How to use style specifications. Styles.
Cascading Style Sheets Robin Burke ECT 270. Outline Midterm The Layout Debate CSS properties Fonts Alignment Color CSS selection selectors pseudo-classes.
ECA225 Applied Interactive Programming Cascading Style Sheets, pt 1 ECA 225 Applied Online Programming.
The Web Wizard’s Guide To DHTML and CSS Chapter 1 A Review of CSS1.
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.
XP Review 2 New Perspectives on JavaScript, Comprehensive1 Introducing Cascading Style Sheets Formatting Web Pages with CSS.
1 Web Development CSS (Cascading Style Sheet). 2 1.Setting rules for multiple elements To decrease the amount of typing for setting rules for multiple.
1 Working with Cascading Style Sheet (CSS). 2 Cascading Style Sheets (CSS)  a style defines the appearance of a document element. o E.g., font size,
CSS – 1h. Without stylesheets proprietary HTML extensions making text into images proliferate use of "spacer" GIF images deprecated HTML elements and/or.
CSS Cascading Style Sheets A very brief introduction CSS, Cascading Style Sheets1.
CSS: Cascading Style Sheets Part II. Style Syntax.
Department of Computer Science, Florida State University CGS 3066: Web Programming and Design Spring
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.
ECA 228 Internet/Intranet Design I Cascading Style Sheets.
Internet & World Wide Web How to Program, 5/e Copyright © Pearson, Inc All Rights Reserved.
1 Cascading Style Sheet (CSS). 2 Cascading Style Sheets (CSS)  a style defines the appearance of a document element. o E.g., font size, font color etc…
Cascading Style Sheets Using HTML. What are they? A set of style rules that tell the web browser how to present a web page or document. In earlier versions.
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.
Cascading Style Sheets Robin Burke ECT 270. Outline CSS properties Fonts Alignment Color CSS selection selectors.
1 Cascading Style Sheets
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.
CSS: Cascading Style Sheets
Cascading Style Sheets
Madam Hazwani binti Rahmat
Cascading Style Sheets
Website Design 3
What are Cascading Stylesheets (CSS)?
Cascading Style Sheets
Tutorial 3 Working with Cascading Style Sheets
Web Design and Development
CGS 3066: Web Programming and Design Fall 2019
Presentation transcript:

SE-2840 Dr. Mark L. Hornick 1 Separating Structure from Presentation: CSS

SE-2840 Dr. Mark L. Hornick 2 Recall: Modern HTML is structural markup Describing only the content of a document, not the appearance How does the browser know how to render any element (e.g. font, size, color)? Appearance is specified via CSS rules, which define presentation styles CSS:Cascading Style Sheets

SE-2840 Dr. Mark L. Hornick 3 CSS is not HTML and is defined by it’s own standards: First proposed in : CSS Level 1 First supported in IE : CSS Level : CSS Level 2.1 (Went from Candidate to Proposed Recommendation as of April 2011 – 7 years as CR!) CSS Level 3 June 2011 – CSS 3 Color Module is now a CR

SE-2840 Dr. Mark L. Hornick 4 CSS style rules can be embedded directly within an HTML document, within a … tag SE2840 /* Embedded CSS style rules go here…. */ /* Note you can’t use HTML comments in this section! */

SE-2840 Dr. Mark L. Hornick 5 CSS rules can be placed in an external.css file and linked to the HTML document: SE2840

SE-2840 Dr. Mark L. Hornick 6 Multiple embedded and external style sheets can be used simultaneously CS422 /* Embedded CSS style rules go here…. */ /* More embedded CSS style rules go here…. */ All styles will be applied, but if any style definitions are repeated, the last one wins.

What if an HTML document contains no embedded rules or to external.css rules? The browser applies its own built-in rules for applying styles to various HTML elements! Different browsers define different default styles If you view an “unstyled” HTML document in different browsers, they will probably look different! SE-2840 Dr. Mark L. Hornick 7

8 CSS has its own syntax/vocabulary CSS expresses style rules selector { property1: value1; property2: value2; /* a CSS-style comment */ propertyN: valueN; } The selector specifies the target element(s) to which the style rule will be applied The properties specify the style parameters that are to be applied body { background-color: white; }

SE-2840 Dr. Mark L. Hornick 9 Selectors can be specified by considering the nested structure of an HTML document body { color: #d2b48c ; } /* applies to all elements and descendants*/ p { color: Red; } /* applies to all elements and descendants*/ h1 strong { color: Navy; } /* applies to all elements within elements (and descendants)*/ p em { color: Teal; }] /* applies to all elements within elements (and descendants)*/ html h1 head body strong p title p em p strong These are called “descendant selectors”

SE-2840 Dr. Mark L. Hornick 10 How do you express a style for an individual element?

SE-2840 Dr. Mark L. Hornick 11 One approach: Style can be embedded within an individual element using the style attribute SE2840 … Almost like the old “font” attribute which mixed presentation into structure. However, this usage is deprecated!

SE-2840 Dr. Mark L. Hornick 12 A second approach uses Element Attributes Elements may often contain attributes which provide additional information about the element’s structure: Syntax: content An attribute‘s value must be enclosed in double quotes Ex: MSOE

SE-2840 Dr. Mark L. Hornick 13 The id attribute Elements may often contain an id attribute: GNU: GNU’s Not Unix No elements may share the same id attribute value within an HTML document (must be unique)

SE-2840 Dr. Mark L. Hornick 14 The id attribute is often used as a target in an element GNU Clicking on this href causes the browser to scroll its window to position the element with the specific attribute

SE-2840 Dr. Mark L. Hornick 15 Using the id attribute for style p#gnudef { color: Maroon; } Used in a style rule, the id attribute forms a specifier that is unique to the individual element possessing the “gnudef” attribute value Since the id is unique, the “p” may be omitted: #gnudef { color: Maroon; } Incidentally, there are many predefined colors

SE-2840 Dr. Mark L. Hornick 16 The class attribute Elements can also contain a class attribute: GNU: GNU’s Not Unix Any number of (different) elements may share the same class attribute value within the same HTML document …

SE-2840 Dr. Mark L. Hornick 17 Using the class attribute for style p.definitions { color: Maroon; } Used like this, the element/class attribute combination forms a specifier that applies to all elements possessing that class value.definitions { color: Maroon; } Used like this, the class attribute forms a specifier that applies to any element possessing that class value

SE-2840 Dr. Mark L. Hornick 18 Combining attributes Elements can contain both id and class attributes: GNU: GNU’s Not Unix ….definitions { font-family: Arial; } p#gnudef { color: Maroon; }

SE-2840 Dr. Mark L. Hornick 19 Elements can belong to more than a single class GNU: GNU’s Not Unix ….definitions { font-family: Arial; }.glossary { text-decoration: underline; } p#gnudef { color: Maroon; }

SE-2840 Dr. Mark L. Hornick 20 essentially allows you to create custom in-line elements HTML: This is Courier text. This is Courier text. CSS: #ex { font-family: “Arial”; color:blue; } #courier {font-family:”Courier”; color:black;} generally must have an id or class attribute to be useful Although you also can use a CSS selector like: p#ex span {font-family:”Courier”; color:black;}

SE-2840 Dr. Mark L. Hornick 21 Media selection in style sheets Replaces the “printer-friendly version” of a web page When using a When using in

SE-2840 Dr. Mark L. Hornick 22 Media selection in a single style sheet Use screen { /* use this rule for monitors*/ body {…} print { /* use this rule for printers */ body {…} img.image1 {display:none;} img.image2 {-webkit-filter: grayscale(1) ;} } Note: other media types are defined; see W3C specs

SE-2840 Dr. Mark L. Hornick 23 Validating Style Sheets “CSS Validator” link on course website

SE-2840 Dr. Mark L. Hornick 24 Pseudoselectors: Pseudoclasses Certain classes are implicit to a group of elements a:link { color: Blue; } a:visited { color: Green; } a:hover { color: Red; } a:active { color: Maroon; }

SE-2840 Dr. Mark L. Hornick 25 Pseudoselectors: Pseudoelements p:first-line { color:red; font-weight:bold;}

SE-2840 Dr. Mark L. Hornick 26 Pseudoelements in tables Another example is the CSS that can be used to specify alternating table row color: tr:nth-child(even) { color: white; } tr:nth-child(odd) { color: green; }

SE-2840 Dr. Mark L. Hornick 27 Cascading Style Sheets: The Cascade …how the browser determines which style to apply to a specific element Style specifications arrive from various sources…

SE-2840 Dr. Mark L. Hornick 28 Style specification sources In order of priority (lowest to highest): User-agent (browser) style sheet Built-in or set via Preferences - browser dependent Reader style sheets IE: part of Internet Options Firefox/Chrome: as plugin/extension Author style sheets Linked external style sheet(s) Imported external style sheet(s) Embedded in element Embedded in elements via style attribute Author/Reader !important style specifications

SE-2840 Dr. Mark L. Hornick 29 Style specification specificity In order of priority: Individual element or pseudo-element selectors p :first-line Dependency selectors p em Class selectors p.warning.warning ID selectors p#scarytext

SE-2840 Dr. Mark L. Hornick 30 Resolving conflicts when multiple rules within the same group target the same element 000 A 3-digit specificity number Does the selector include an id? One point for each id. Does the selector include a class or pseudo- class? One point each Does the selector include any element names? One point each

SE-2840 Dr. Mark L. Hornick 31 The highest number wins 000 h1=001 h1.bluetext=011 body h1=002 h1#topmost=101 Does the selector include an id? One point for each id. Does the selector include a class or pseudo- class? One point each Does the selector include any element names? One point each