Style changes (contd.) When a user event happens in the context of some element, we may wish several aspect of the style to change For example, we may.

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

Computer and Communication Fundamental Basic web programming Lecture 8 Rina Zviel-Girshin.
CSS The basics { }. CSS Cascading Style Sheets - language used to – describe html appearance & formatting Style Sheet - file that describes – how html.
Style changes (contd.) When a user event happens in the context of some element, we may wish several aspect of the style to change For example, we may.
HTML Overview - Cascading Style Sheets (CSS). Before We Begin Make a copy of one of your HTML file you have previously created Make a copy of one of your.
Making Things Look Nice: Visual Appearance and CSS CMPT 281.
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.
Chapter 6 © 2012 by Addison Wesley Longman, Inc Introduction Def: A dynamic HTML document is one whose tag attributes, tag contents, or element.
The Web Warrior Guide to Web Design Technologies
NAMEd anchors Enabling users to jump to specific points within Web documents.
Chapter 7 © 2001 by Addison Wesley Longman, Inc. 1 Chapter 7 Sebesta: Programming the World Wide Web.
Capturing user input: Using HTML FORMs User input Up till now, our HTML documents have all been directed at outputting information to the user However,
Style Sheets: the right way to specify rendering.
CSS Basics LIS Webteam April 8, Why CSS? What’s wrong with HTML? Structure vs Style Early web design used hacks to style webpages with HTML – like.
NAMEd anchors Enabling users to jump to specific points within Web documents.
Tutorial 13 Working with Objects and Styles. XP Objectives Learn about objects and the document object model Reference documents objects by ID, name,
Inline, Internal, and External FIle
CSS (Cascading Style Sheets): How the web is styled Create Rules that specify how the content of an HTML Element should appear. CSS controls how your web.
1 Events Lect 8. 2 Event-driven Pages one popular feature of the Web is its interactive nature e.g., you click on buttons to make windows appear e.g.,
DHTML - Introduction Introduction to DHTML, the DOM, JS review.
CP476 Internet Computing JavaScript and HTML1 1.JavaScript Execution Environment The JavaScript Window object represents the window in which the browser.
DHTML. What is DHTML?  DHTML is the combination of several built-in browser features in fourth generation browsers that enable a web page to be more.
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) 1.  What is CSS?  Why CSS?  How to write a CSS? 2.
Today’s objectives  Presentational | Inline | Block | Validate  CSS | Rules | Declarations.
CS346 Javascript-7A Events1 DOM Document Object Model and Events.
Cascading Style Sheets by Pavlovic Nenad by. Presentation Contents  What is CSS?  Why CSS?  Types of Style Sheets  Style Sheets Syntax  Box Formatting.
Introduction To CSS.. HTML Review What is HTML used for? Give some examples of formatting tags in HTML? HTML is the most widely used language on the Web.
Using Cascading Style Sheet As you create more web pages, you may wish to impose a consistent look for all of your web pages or for group of related pages.
Cascading Style Sheets CSS by Pavlovic Nenad by. 2Cascading Style Sheets Presentation Contents What are CSS? What are CSS? History of CSS History of CSS.
Css. Definition Cascading style sheet (CSS) Cascading Style Sheets (CSS) is a simple mechanism for adding style (e.g. fonts, colors, spacing) to Web documents.
INTRODUCTION TO CSS. OBJECTIVES: D EFINE WHAT CSS IS. K NOW THE HISTORY OF CSS. K NOW THE REASON WHY CSS IS USED. CSS SYNTAX. CSS ID AND CLASS.
Css. Definition Cascading style sheet (CSS)  It is a simple mechanism for adding style (e.g. fonts, colors, spacing) to Web documents.
Definition CSS “Short for Cascading Style Sheets, a new feature being added to HTML that gives both Web site developers and users more control over how.
Chapter 8 © 2001 by Addison Wesley Longman, Inc. 1 Chapter 8 Sebesta: Programming the World Wide Web.
Lecture 10 JavaScript: DOM and Dynamic HTML Boriana Koleva Room: C54
Introduction to the Document Object Model DOM *Understand document structure manipulation *Dynamic effects in web pages *Programming, scripting, web content.
Web Development 101 Presented by John Valance
INT222 - Internet Fundamentals Shi, Yue (Sunny) Office: T2095 SENECA COLLEGE.
Fluency with Information Technology INFO100 and CSE100 Katherine Deibel Katherine Deibel, Fluency in Information Technology1.
Modifying HTML attributes and CSS values. Learning Objectives By the end of this lecture, you should be able to: – Select based on a class (as opposed.
How to Use Google Charts. Using Google Charts Google Charts is used to provide a way to visualize data on your website. You can choose to use simple line.
1 CSC160 Chapter 7: Events and Event Handlers. 2 Outline Event and event handlers onClick event handler onMouseOver event handler onMouseOut event handler.
 Scripts that execute in response to some event  User clicking on something  Script does NOT execute as part of page loading  DOM facilities like.
Host Objects: Browsers and the DOM
Chapter 6 © 2014 by Pearson Education Introduction Def: A dynamic HTML document is one whose tag attributes, tag contents, or element style properties.
Document Object Model Nasrullah. DOM When a page is loaded,browser creates a Document Object Model of the Page.
CSS Syntax. Syntax The CSS syntax is made up of three parts: a selector, a property and a value: selector {property: value}
Project 7: Exploring DHTML Essentials for Design JavaScript Level Two Michael Brooks.
SE-2840 Dr. Mark L. Hornick 1 Dynamic HTML Making web pages interactive with JavaScript.
Chapter 6 © 2003 by Addison-Wesley, Inc Introduction - Dynamic HTML is not a new markup language - A dynamic HTML document is one whose tag attributes,
Jackson, Web Technologies: A Computer Science Perspective, © 2007 Prentice-Hall, Inc. All rights reserved Chapter 5 Host Objects: Browsers.
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.
6.1 Introduction 6.2 Element Positioning
DHTML.
Week 3: Introduction to Javascript
Week 4: Introduction to Javascript
Intro to CSS CS 1150 Fall 2016.
JAVASCRIPTS AND HTML DOCUMENTS
Cascading Style Sheets - Building a stylesheet
Introduction to JavaScript
Intro to CSS CS 1150 Spring 2017.
A second look at JavaScript
Intro to CSS Mr. Singh.
CSS Style Sheets: Intro
Events Comp 205 Fall 2017.
Introduction to DHTML, the DOM, JS review
Introduction to JavaScript
Inheritance CSS.
Cascading Style Sheets - Building a stylesheet
Presentation transcript:

Style changes (contd.) When a user event happens in the context of some element, we may wish several aspect of the style to change For example, we may wish to change both the font size and the color To do this, we can have several style- property settings in one event handler: onmouseover = ‘this.style.color=“red”; this.style.fontSize=“50” ‘ onmouseout= ‘this.style.color=“blue”; this.style.fontSize=“20” ‘

Analysis of this: onmouseover=‘ this.style.color=“red”; this.style.fontSize=“50” ‘ onmouseout= ‘ this.style.color=“blue”; this.style.fontSize=“20” ‘ the overall event-handler is enclosed by apostrophes individual style settings are separated by semi-colons layout should be chosen to support human readability of the HTML specification

Style Property Names: CSS versus Javascript CSS property names can be written in upper or lower case -- although I encourage you to use lower-case, as in font-size Javascript property names do not contain hyphens and must be written in lower-case, except for capitals at word boundaries, as in fontSize, which corresponds to font-size borderLeftWidth, which corresponds to border- left-width

Example Consider the next three slides –the first one shows a document before the mouse is placed over the heading –the second one shows what the document looks like when the mouse is over the heading –the third one shows what the document looks like when the mouse is moved away again

Mouse not on heading

Mouse is on heading

Mouse moves off heading again

Event-handlers to achieve this <h1 onmouseover= 'this.style.borderStyle="solid"; this.style.borderColor="blue"; this.style.borderLeftWidth="50"; this.style.backgroundColor="black"; this.style.color="white"' onmouseout= 'this.style.borderStyle="none"; this.style.backgroundColor="white"; this.style.color="black"' > Some Subject or Other The heading above gets...

Multiple similar event handlers: Handling these two events for one heading required a lot of typing It would be worse if we wanted to do the same thing for many headings We need some way of abbreviating event handler specification

First, a motivating example: Consider the following document with several headings Consider what happens when we move the mouse over/out with respect to these headings

Before we move mouse over anything

When mouse is over 1st heading

After mouse is moved away

When mouse is over 2nd heading

After mouse has moved out

When mouse is on 3rd heading

How this can be done economically: We must define some new JavaScript functions

Using the new functions Some Subject or Other Blah blah blah. Another Subject Blah blah blah. A Third Subject Blah blah blah.

The new functions We have used two new functions: –highlight –restore Each time one of these functions is used, it is given one argument: the word this, which refers to the element in question

Function definition General form: function ( ) { } Example: function changeStyleOf(someThing) { someThing.style.color=“red”; someThing.style.fontSize=“20” } I require you to have verbs in the names of function which “do” something

Formal versus Actual arguments In the function definition function changeStyleOf(someThing) { someThing.style.color=“red”; someThing.style.fontSize=“20” } the word someThing is a formal argument In the event-handler onmouseover=‘changeStyleOf(this)’ the word this is an actual argument

Where to put function definitions They are placed in an element called a script element Such an element is delimited by two tags: and We can have lots of script elements in a document However, a script element which contains function definitions should be placed in the head of a HTML specification

Defining the functions used earlier function highlight(someThing) {someThing.style.borderStyle="solid"; someThing.style.borderColor="blue"; someThing.style.borderLeftWidth="50"; someThing.style.backgroundColor="black"; someThing.style.color="white" } function restore(someThing) {someThing.style.borderStyle="none"; someThing.style.backgroundColor="white"; someThing.style.color="black" }

Overall Document Spec. (Part I) Simple Mouse Event function highlight(someThing) {someThing.style.borderStyle="solid"; someThing.style.borderColor="blue"; someThing.style.borderLeftWidth="50"; someThing.style.backgroundColor="black"; someThing.style.color="white" } function restore(someThing) {someThing.style.borderStyle="none"; someThing.style.backgroundColor="white"; someThing.style.color="black" }

Overall Document Spec. (Part II) Some Subject or Other Blah blah blah. Another Subject Blah blah blah. A Third Subject Blah blah blah.

Event-handlers can have widespread effect An event-handler attached to one element of a document can affect any part of a document In the next example, there are event- handlers attached to three headings but they all affect only the display of the first paragraph

Appearance when mouse is not on any heading

Appearance when mouse is on first heading

Appearance when mouse is on second heading

Appearance when mouse is on third heading

How this is done: Only two changes from the earlier HTML specification: –the first paragraph is given an ID, which happens to be “blah1” –all the event-handlers specify that blah1 should be highlighted or restored, as the case may be –in other words, in every event-handler, blah1 is the actual argument passed to the functions

The body of this revised document: Some Subject or Other Blah blah blah. Another Subject Blah blah blah. A Third Subject Blah blah blah.

A better way of using id attributes

The usage of the id attribute that we have just seen was introduced in the late 1990s by Microsoft It still works in many browsers But, to future-proof your programs, you should conform to the W3C standard, –which is a little verbose

The body of this W3C-compatible document: Some Subject or Other Blah blah blah. Another Subject Blah blah blah. A Third Subject Blah blah blah.

The head of this W3C-compatible document: Simple Mouse Event function highlight(someString) {var someThing=document.getElementById(someString); someThing.style.borderStyle="solid"; someThing.style.borderColor="blue"; someThing.style.borderLeftWidth="50"; someThing.style.backgroundColor="black"; someThing.style.color="white" } function restore(someString) {var someThing=document.getElementById(someString); someThing.style.borderStyle="none"; someThing.style.backgroundColor="white"; someThing.style.color="black" }

Another example: events on headings affecting their related paragraphs Some Subject or Other Blah blah blah. Another Subject Blah blah blah. A Third Subject Blah blah blah.

Mouse on first heading

Mouse on second heading

Mouse on third heading