© Yaron Kanza HTML,CSS and JavaScript Written by Dr. Yaron Kanza, Edited by permission from author by Liron Blecher.

Slides:



Advertisements
Similar presentations
Cascading Style Sheets (CSS). Cascading Style Sheets With the explosive growth of the World Wide Web, designers and programmers quickly explored and reached.
Advertisements

CSS Cascading Style Sheets. Objectives Using Inline Styles Working with Selectors Using Embedded Styles Using an External Style Sheet Applying a Style.
Today CSS HTML A project.
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.
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.
“Cascading Style Sheets” for styling WWW information DSC340 Mike Pangburn.
1 Lecture #5 Static Web Documents Shimrit Tzur-David HAIT Summer 2005.
Cascading Style Sheets Scripting with Style. CSS versus HTML  Ways to format in HTML –HTML Tag extensions –Converting Text to images –Page Layout with.
XP 1 Working with Cascading Style Sheets Creating a Style for Online Scrapbooks Tutorial 7.
CSS: Cascading Style Sheets. What are Style Sheets A style sheet is a mechanism that allows to specify how HTML (/XHTML/XML) pages should look The style.
Cascading Style Sheets (CSS). DBI 2008 HUJI-CS 2 What are Style Sheets A style sheet is a mechanism that allows to specify how HTML (/XHTML/XML) pages.
Tutorial 3: Adding and Formatting Text. 2 Objectives Session 3.1 Type text into a page Copy text from a document and paste it into a page Check for spelling.
3.1 Cascading Style Sheets. Motto Fashions fade, style is eternal. —Yves Saint Laurent.
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.
Using Cascading Style Sheets. Introduction to Styles and Properties  Cascading Style Sheets (CSS) are a standard set by the World Wide Web Consortium.
Cascading Style Sheets CS3505. What are CSS? Method for adding style attributes consistently to HML tags Cascading because styles are applied in order.
XP Tutorial 7New Perspectives on Creating Web Pages with HTML, XHTML, and XML 1 Working with Cascading Style Sheets Creating a Style for Online Scrapbooks.
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.
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)
1Computer Sciences Department. And use
Tutorial #3 Cascading Style Sheets. Review: Last Class Image sizing Pathnames Project Default Path Relative Path Absolute Path Blackboard Homework Submission.
New Perspectives on XML, 2nd Edition Tutorial 5 1 TUTORIAL 5 WORKING WITH CASCADING STYLE SHEETS.
XP New Perspectives on XML Tutorial 5 1 TUTORIAL 5 CSS Tutorial – Carey ISBN
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.
Tutorial 6 By Sam INE 1020 Introduction to Internet Engineering 1 DHTML & CSS Tutorial 6.
Doman’s Sections Information in this presentation includes text and images from
CSS: Cascading Style Sheets. 2 What are Style Sheets A style sheet is a mechanism that allows to specify how HTML (/XHTML/XML) pages should look The style.
Cascading Style Sheets by Pavlovic Nenad by. Presentation Contents  What is CSS?  Why CSS?  Types of Style Sheets  Style Sheets Syntax  Box Formatting.
 A style sheet is a single page of formatting instructions that can control the appearance of many HTML pages at once.  If style sheets accomplished.
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.
Tutorial #4 Formatting Text and Links. Tutorial #3 Review - CSS CSS format Selector { property1: value1; /* Comments */ } Embedded, In-Line, and External.
Introduction to Programming the WWW I CMSC Summer 2004 Lecture 7.
Today’s objectives  Review  CSS | Rules | Declarations  HTML Structure document  Class asignment.
Cascading Style Sheets Orientation Learning Web Design: Chapter 11.
Tutorial #3 Cascading Style Sheets. Tutorial #2 Review - Anchors Links to Site DMACC Internal Links Go to Top Mail To me Local.
Introduction to CSS. What is CSS?  Cascading Style Sheets  Used for styling HTML  Also important in javascript and jquery for selectors  External.
Lecture 2 - HTML and CSS Review SFDV3011 – Advanced Web Development 1.
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.
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.
Cascading Style Sheets CSS.  Standard defined by the W3C  CSS1 (released 1996) 50 properties  CSS2 (released 1998) 150 properties (positioning)  CSS3.
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
Managing Data on the World-Wide Web cs What is HTML? A Markup Language for representing documents text (data) structure appearance functionality.
Cascading Style Sheets Primary readings Presentations Explain & review projects with class mates.
CSS: Cascading Style Sheets Part II. Style Syntax.
1 CSS: Cascading Style Sheets W3Schools CSS tutorialCSS tutorial.
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.
Tutorial 3 Designing a Web Page with CSS
ECA 228 Internet/Intranet Design I Cascading Style Sheets.
Blended HTML and CSS Fundamentals 3 rd EDITION Tutorial 3 Introducing Cascading Style Sheets.
Internet & World Wide Web How to Program, 5/e Copyright © Pearson, Inc All Rights Reserved.
Cascading Style Sheets Robin Burke ECT 270. Outline CSS properties Fonts Alignment Color CSS selection selectors.
CONFIGURING COLOR AND TEXT WITH CSS Chapter 3. Cascading Style Sheets (CSS) Used to configure text, color, and page layout. Launched in 1996 Developed.
Internet & World Wide Web How to Program, 5/e 1. 2.
Cascading Style Sheets
Cascading Style Sheets
IS333: MULTI-TIER APPLICATION DEVELOPMENT
Cascading Style Sheets
Presentation transcript:

© Yaron Kanza HTML,CSS and JavaScript Written by Dr. Yaron Kanza, Edited by permission from author by Liron Blecher

Agenda HTML Style Sheets Style Properties Layout Properties Selector Types Inserting Style to a Page Inheritance and Cascading Java Script

A Markup Language for representing documents text (data) structure appearance functionality Designed for writing Web pages Traditionally rendered by Web browsers Nowadays, also by other applications (for example: AppStore app in iOS) 3 What is HTML?

Content presentation Structures, e.g., paragraphs, lists, tables, etc. Decorations, e.g., fonts, images, etc. Declaration of meta information e.g., the page title, language, etc. Linkage to other pages i.e., attaching links to components Management of user input e.g., searching, making reservations, ordering products Directions for browsers e.g., refresh, redirect, caching control, etc. 4 Capabilities of HTML

An HTML Page Hello World Wide Web! Filename ends with.htm or.html 5 HTML Page Structure

HTML Version History HTML 1.0 (first draft) – 1992 HTML 2.0 (proposed standard) – September 1995 From this point on - W3C recommendations HTML 3.2 – January 1997 added tables, applets,... HTML 4.0 – December 1997 improved tables, forms,... 6

HTML Version History - cont’d HTML 4.01 – December 1999 Slightly different from 4.0 XHTML 1.0 – January 2000 Reformulation of HTML 4.01 as an XML application Stricter and cleaner syntax, formatting moved to CSS XHTML 1.1 – May 2001 “Modularization of XHTML” 7

Non-standard / mixed HTML Most of the time, will display more-or-less as expected, on most browsers, but its appearance may vary between browser types and between browser versions Even when using completely valid and standard HTML, always check your pages on more than one browser type At least IE & some Mozilla 8 (X)HTML Support in Real Life

Basic HTML Syntax (X)HTML contains text, separated by tags Tags come in pairs: opening and closing tag Tags can have attributes, which have values An HTML Page Hello World Wide Web! 9

An HTML page is surrounded by the html tag 2 Basic parts: head: general information about the document (e.g., title – shown on the browser bar) body: the content of the document An HTML Page Hello World Wide Web! Actually a tree structure is created 10 Basic HTML Syntax – con’t

Element and attr. names must be in lower case HTML allows any case combination, e.g.,, which conveniently helped distinguish tags from the body text All tags must have corresponding closing tags Use as a shorthand for Elements should be properly nested e.g., hello world is illegal! Attribute values must be quoted e.g., and not 11 XHTML Stricter Syntax

Document Type Definitions It is good to specify which XHTML standard you are using Put a document type definition (DTD) at the first line of your file (before the html tag) For an example, see the next slide 12

XHTML - strict <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" " XHTML - transitional (loose) XHTML - frameset (for using frames) Transition html  xhtml: allows some legacy formatting outside CSS 13 Document Type Definitions – con’t

Basic Structures Hello World Example Hello World 14

Links Hello World Example Hello World 15

DEMO Mysite-index-simple 16

Agenda HTML Style Sheets Style Properties Layout Properties Selector Types Inserting Style to a Page Inheritance and Cascading Java Script

What are Style Sheets A style sheet is a mechanism that allows to specify how HTML (/XHTML/XML) pages should look The style is specified by style rules The style rules appear either in the document or in external files, called style sheets 18

Style Sheets Usually, a file that ends with.css For example: i.a.cnn.net/cnn/.element/ssi/css/1.1/main.css (CNN) (MTA) To attach a style sheet to an HTML file, add You can link to more than one css file to the head 19

Style Sheets A file that is used for storing information about the way elements of HTML (or XML) should appear on the browser A style sheet increases the separation between content and presentation Easier to generate large sites in which all the pages have the same style It allows changing the look of many pages by changing a single file May reduce network traffic 20

Without a style sheet (i.e., with the default style definitions)

Simple Example – without css A Joke A joke A mama tomato, a papa tomato and a baby tomato are walking down the street. The baby tomato keeps falling behind so the papa tomato goes back, steps on the baby tomato and says, ketchup ("Catch- up!"). div defines a division/section in a document. Using div you group elements. 22

Style File: joke.css body { background-image: url("bg.gif"); } h1 { background-color: green; color: rgb(250, 200, 250); /* pink */ font-family: cursive; } p { background-color: yellow; color: purple; font-size: 200%;} 23 Simple Example

Simple Example - with css A Joke A joke A mama tomato, a papa tomato and a baby tomato are walking down the street. The baby tomato keeps falling behind so the papa tomato goes back, steps on the baby tomato and says, ketchup ("Catch-up!"). 24

Background: Style in Legacy HTML In traditional HTML, every HTML tag which supported changing its font/color/etc…, supported this using a different syntax Examples: Hello Hey! line-through 25

Separates content from style Often require two kinds of skills; moreover, one is likely to change independently from the other Keeps HTML pages human-readable Reduces download time (how?) Allows to easily maintain a consistent appearance over a whole Web site (why?) A more flexible, unified way to specify style properties for different HTML elements (tables, paragraphs, etc…) 26 Simple Example – without css

Style Sheets provide new ways to accomplish tasks which were already possible … but recall the advantages from the previous slide Once style sheets were introduced, most of the legacy features with equivalent functionality were deprecated in HTML 4.01 and in Transitional XHTML and were removed in Strict XHTML 27 The Transition to Style Sheets

Style Rules A rule has the following form selector {declaration block} The selector determines when the rule is applied For example, the following rule applies to text that is inside a tag p {color: green; font-size: 1.5em; font-style: italic} em is the current font-size of the element 28

Properties that CSS Controls Style properties Layout properties There are many properties and many possible values We will not cover all of them here Look in the Web !!! 29

Agenda HTML Style Sheets Style Properties Layout Properties Selector Types Inserting Style to a Page Inheritance and Cascading Java Script

Our Examples We use the following HTML example: This is our example for css. The tag is used to group inline elements for formatting with styles Extremely useful tag... 31

Font Properties Font properties: family, size, weight, style, variant, etc. span { font-family: courier; font-size: 130%; font-style: italic; font-weight: bold} 32

Text Properties Text properties: color, transform, decoration, … span { color: #00cc00; text-decoration: line-through; text-transform: uppercase} 33

Background Properties Background properties: background-color, background- image, … span {background-color: #00ff00} span {background-image: url('bg.gif');} 34

DEMO Mysite-joke 35

Agenda HTML Style Sheets Style Properties Layout Properties Selector Types Inserting Style to a Page Inheritance and Cascading Java Script

Page Layout Each HTML element defines a layer (rectangular box) that is placed in some location on the page Layers are nested with correspondence to the nesting of their elements 37

There are two type of elements: Block elements: p, ol, table, div, h1, etc. Inline elements: b, i, a, span, cite, etc. Layers of block elements are separated from their adjacent elements (i.e., a new line before and after), while inline elements are not You can turn a block into an inline and vice-versa (highly useful for img elements, among others), using the display property, e.g., h1 { display: inline } 38 Inline vs. Block Elements

Positioning Elements Using CSS, you can define the position of an element inside its parent layer For that, use the properties position, left, right, top and bottom span { position:relative; left: 1cm; top: 1cm; color: #00cc00;} distance from left distance from top 39

But 1cm left to what?? For that, we have the position property Four position types are supported: static: the default position relative: relative to the static position absolute: relative to the parent layer coordinates fixed: relative to the window coordinates (remains at the same position regardless of scrolling) 40 Position Types

span { position:absolute; left: 1cm; top: 1cm; color: #00cc00;} span { position:fixed; left: 1cm; top: 1cm; color: #00cc00;} 41 Position ExamplesPositions Examples

span { position:static; left: 1cm; top: 1cm; color: #00cc00;} This is the default position type 42 Positions Examples – con’t

Layer properties margin-top (-bottom, -left, -right) padding-top (-bottom, -left, -right) border-width (-color, -style, … ) Text Layout direction, word-spacing, white-space, letter-spacing, text-align, text- indent, … A mama tomato, a papa tomato and a baby tomato are walking down the street. Padding margin 43 More Layout Properties

Length Units CSS has several types of length units: em, ex: height of current fonts ex is the height of “x”, em is the distance between bottoms of two subsequent lines px, in, cm, mm, pt, pc: international units %: ratio of parent’s respective dimension A page should remain a proper layout when fonts and/or windows are resized (usually by the user) Hence, do not assume anything about default sizes 44

Links CSS Layout Tutorials: 45

Agenda HTML Style Sheets Style Properties Layout Properties Selector Types Inserting Style to a Page Inheritance and Cascading Java Script

Type Selectors Class Selectors ID Selectors Attribute Selectors Universal Selector Child Selectors Adjacent-Sibling Selectors Descendant Selectors Pseudo-Class Selectors Pseudo-Element Selectors 47 Several Kinds of Selectors

Type Selector A type selector is the name of an element type A type selector matches every instance of the element type li {color: red; font-size: 16px} Matches: An item Another item 48

Universal Selector The universal selector matches every element The following rule means that all the text will have a size of 40px * {font-size: 40px } 49

Attribute Selector p[title] matches p when its title attribute is set to any value p[title=intro] or p[title="intro"] (the quotes are optional) matches p when its title attribute is set to “intro” p[class~=green] matches p when the class attribute value includes the word “green” 50

Class Selector A class selector is a selector of the form x.y It matches xs that have the class attribute with value y (i.e., it is a shorthand for x[class~=y]) li.reditem {color: red} Matches: An item Another item 51

ID Selector IDs are similar to classes, except that there can only be one element with a given ID in a document That is, an ID uniquely identifies an element li#23 {color: red} Matches: An item Another item 52

A descendant selector has the form S 1 S 2 where S 1 and S 2 are (possible complex) selectors It matches all elements that match S 2, and are descendants (nested in any level in) elements that match S 1 To match only immediate descendants (children), use a Child Selector S 1 > S 2 To match S 2 immediately following S 1, use an Adjacent-Sibling Selector S 1 + S 2 53 Descendant/Child/Sibling Selector

Descendant/Child/Sibling Selector - Example.head div>span em {color: blue} What will this match? Matches: This is not blue. This is blue and so is this. p em {color: blue} 54

Pseudo-Classes Pseudo class selectors are similar to class selectors, but they match states rather than class values For example, a link can be in the states: visited, active, mouse- over (“hover”), etc. Another example: a text-area can be focused 55

Pseudo-Classes - Examples of Rules a:link {color: blue} a:visited {color: purple} a:hover {font-size: 1.5em} a:active {color: red} input[type=text]:focus {background-color: yellow} when typing a text into a text input box (meaningful with other input types as well) 56

Pseudo-Elements Pseudo element selectors select abstract elements which are not specified as elements in the source HTML For example, to transform the first line of every p into uppercase, use: P:first-line {text-transform: uppercase} Why can’t this be faked by enclosing the first line with a span? Example 2: p.article:first-letter {color:#ff0000} 57

Grouping Selectors We can group several declarations by specifying several selectors, separated by commas For example, the following rule applies to all elements that match either h1, p b, or h2[class=largehead] p b, h1, h2.largehead {font-size: 120%} 58

Agenda HTML Style Sheets Style Properties Layout Properties Selector Types Inserting Style to a Page Inheritance and Cascading Java Script

In an inline style, the declaration block is the value of the attribute style of the element Almost every tag can have the style attribute exceptional: base, head, html, meta, param, script, style and title This text will be shown in italic green and the size will be 1.5 times the current font size 60 Inline Styles

Document-Level Style body {color: red; background: skyblue;} h1 { color: blue; }... 61

Imported Style Sheets rule imports the style rules of another style sheet url(file.css) Several import rules may appear at the beginning of the style sheet Import rules can appear in embedded style sheets or in external style sheets 62

Imported Style Sheets Why do we need the import command when we have the url(general.css); body { color: red; background:skyblue } h1 { color: blue } in a css file, one can create style- sheets which are based on others… 63

Agenda HTML Style Sheets Style Properties Layout Properties Selector Types Inserting Style to a Page Inheritance and Cascading Java Script

Inheritance of Properties Consider a property of an element that does not match any rule For some properties (inherited properties), the computed value of this property is inherited from the parent of the element For example, color, font and word-spacing are inherited Yet border, margin and padding are not! 65

Inheritance of Properties - Example Given the rules: body { font-size: 10pt } h1 { font-size: 120% } What will be the font size of the element? A large heading Computed Value: 12pt 66

Cascading of Styles CSS merges style rules from different places (inline, document-level, linked and defaults) Different places may have conflicting style rules conflicts may even arise in a single source The process of merging (cascading) styles from different places determines which style rules have higher priority 67

Determining Property Values Suppose that we would like to determine the value of property p for element e Choose all declarations that have a selector that matches e and have the property p “Sort” all declarations according to cascading order (importance) Apply the rule of the first declaration in the cascading order 68

Cascading Order The cascading order of declarations: origin 1. Primary sort: Importance of origin Specificity 2. Secondary sort: Specificity of selectors Order 3. Final sort: Order of appearance 69

Importance of Origin There are two origins of rules: author and browser (defaults / user customizations) browser !important rules author !important rules author rules browser rules strongest weakest For example, you can add stylesheets to IE in the following way: Tools  internet options  Accessibility  User style sheet. Of course you can add !important browser rules this way as well… 70

is rule in style attribute? number of ID attributes number of attributes and pseudo-classes number of element names strongest weakest 71 Specificity of Selectors

Specificity of Selectors - Example Which is the most specific? li {…} #x34y {…} ul ol li.red {…}

Agenda HTML Style Sheets Style Properties Layout Properties Selector Types Inserting Style to a Page Inheritance and Cascading Java Script

Client-Side Programming Certain parts of a Web application can be executed locally, in the client For example, some validity checks can be applied to the user’s input locally The user request is sent to the server only if the input is valid Java Script (not part of Java!) is an HTML- embedded scripting language for client-side programming 74

Java Script is a scripting language for generating dynamic HTML pages in the browser The script is written inside an HTML page and the browser runs the script and displays an ordinary HTML page There is some interaction of the script with the file system using cookies Cookies are small files that store personal information in the file system of the client For example, a cookie may store your user name and password for accessing a particular site 75 Java Script

JS Example Before the script document.write(' In the script ') After the script 76 Java ScriptJava Script – Example #1

JS Example Before the script document.write(new Date().toLocaleString()) After the script 77 Java Script – Example #1Java Script – Example #2

Hello and hours = new Date().getHours(); if (hours < 10) { document.write("good morning") } else {document.write("good day") }. 78 Java Script – Example #2Java Script – Example #3

DEMO Mysite-index.html 79

Links