CITS1231 Web Technologies. Introduction to Cascading Style Sheets

Similar documents
What is CSS? NAME: INSERT OPENING GRAPHIC HERE:

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

Assignments (4) Assessment as per Schedule (2)

CSS how to display to solve a problem External Style Sheets CSS files

CSS Scripting and Computer Environment - Lecture 09

Three Ways to Use CSS:

Chapter 3 Style Sheets: CSS

Comp-206 : Introduction to Software Systems Lecture 23. Alexandre Denault Computer Science McGill University Fall 2006

INTRODUCTION TO CSS. Mohammad Jawad Kadhim

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

Cascading style sheets, HTML, DOM and Javascript

CSS: The Basics CISC 282 September 20, 2014

INFORMATICA GENERALE 2014/2015 LINGUAGGI DI MARKUP CSS

COMS 359: Interactive Media

<body bgcolor=" " fgcolor=" " link=" " vlink=" " alink=" "> These body attributes have now been deprecated, and should not be used in XHTML.

CISC1600-SummerII2012-Raphael-lec3 1

CSS CSS how to display to solve a problem External Style Sheets CSS files CSS Syntax

Cascading Style Sheets. Overview and Basic use of CSS

Introduction to Web Programming and Design

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

COSC 2206 Internet Tools. CSS Cascading Style Sheets

Lab Introduction to Cascading Style Sheets

HTML Hyperlinks (Links)

CSS for Styling CS380

Overview. Part I: Portraying the Internet as a collection of online information systems HTML/XHTML & CSS

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

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

DAY 4. Coding External Style Sheets

CSS - Cascading Style Sheets

recall: a Web page is a text document that contains additional formatting information in the HyperText Markup Language (HTML)

CSS: Cascading Style Sheets

Chapter 4 CSS basics

CSS 1: Introduction. Chapter 3

BIM222 Internet Programming

CSC 121 Computers and Scientific Thinking

Web Design and Development ACS-1809

EECS1012. Net-centric Introduction to Computing. Lecture 3: CSS for Styling

HTML, CSS, JavaScript

Creating and Building Websites

Lab 4 CSS CISC1600, Spring 2012

CMPT 165 INTRODUCTION TO THE INTERNET AND THE WORLD WIDE WEB

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

CSS Cascading Style Sheets

Scripting for Multimedia LECTURE 5: INTRODUCING CSS3

CSS stands for Cascading Style Sheets Styles define how to display HTML elements

A Balanced Introduction to Computer Science, 3/E

CSC309 Winter Lecture 2. Larry Zhang

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

What Is a Style Sheet

CSS.

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

Introduction to WEB PROGRAMMING

Unit 20 - Client Side Customisation of Web Pages. Week 2 Lesson 3 Introduction to CSS

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

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

Module 2 (VII): CSS [Part 4]

Styles, Style Sheets, the Box Model and Liquid Layout

Hypertext Markup Language, or HTML, is a markup

E , Fall 2007 More with stylesheets

CSC 443: Web Programming

Markup Language SGML: Standard Generalized Markup Language. HyperText Markup Language (HTML) extensible Markup Language (XML) TeX LaTeX

3.1 Introduction. 3.2 Levels of Style Sheets. - HTML is primarily concerned with content, rather than style. - There are three levels of style sheets

Web Design and Development Tutorial 03

ID1354 Internet Applications

Zen Garden. CSS Zen Garden

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

CITS1231 Midterm Test (A total of 45 marks)

INTRODUCTION TO HTML5! CSS Styles!

IMY 110 Theme 6 Cascading Style Sheets

This tutorial will help both students as well as professionals who want to make their websites or personal blogs more attractive.

Creating and Building Websites

Chapter 2 CSS for Style

Using CSS in Web Site Design

CS 350 Internet Applications I Name: Exam II (CSS) October 29, 2013

CSc 337 LECTURE 3: CSS

ITNP43: HTML Lecture 4

CSS: formatting webpages

Understanding the Web Design Environment. Principles of Web Design, Third Edition

XHTML & CSS CASCADING STYLE SHEETS

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

CREATING A WEBSITE USING CSS. Mrs. Procopio CTEC6 MYP1

CITS3403 Agile Web Development 2019 Semester 1

Web Publishing with HTML

Cascading Style Sheets Level 2

Web Technology. Assignment 3. Notes: This assignment is individual assignment, every student should complete it by himself.

Introduction to Cascading Style Sheet (CSS)

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

Controlling Appearance the Old Way

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

Setting a Background Image

Cascading Style Sheet. Styles as Tag Attributes. Syntax. <h1>: what font type/size is used? STYLE = SELECTOR {RULES} Attributes such as bgcolor

The internet is a worldwide collection of networks that link millions of computers. These links allow the computers to share and send data.

HTML CS 4640 Programming Languages for Web Applications

WML2.0 TUTORIAL. The XHTML Basic defined by the W3C is a proper subset of XHTML, which is a reformulation of HTML in XML.

Basic CSS Lecture 17

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

GIMP WEB 2.0 MENUS. Before we begin this tutorial let s visually compare a standard navigation bar and a web 2.0 navigation bar.

COMP519 Web Programming Autumn Cascading Style Sheets

APPLIED COMPUTING 1P01 Fluency with Technology

Cascading Style Sheets (CSS)

Transcription:

CITS1231 Web Technologies Introduction to Cascading Style Sheets

The Problems with HTML Poor Coding No consistency in the way a document is developed. The same markup can often be written a number of ways. One can omit attributes, or include irrelevant or illegal attributes, with the browser usually ignoring the problems. It seemingly encourages poorly written code. <table border> <table border= 1 > <table> <table bdr> (wrong syntax) <table border= 0 > 2

XHTML vrs HTML Must have quotes for attributes eg: Necessary to have: XHTML All elements explicitly closed eg: <br/> All elements/attributes must be lower case <body lang= en > HTML Not necessary eg: <br> Case insensitive Quotes not necessary eg: <body lang=en> Not necessary <html>, <head>, or <body> Recommendation: Use XHTML. 3

The Problems with HTML Coding Design As appearance and design became a central issue (with disregard to rules) new design tags were created. <font> is the classic example. It defines typographic presentation of the page. However this tag is not easy to use. Every time you change an attribute of the font, you must close and re-open the tag. You must open and close them every time you apply this tag to sections of your document. For example, to define the font to be used table cells, the definition must be repeated in each cell, it cannot be done as a global setting. 4

The Problems with HTML - Compatibility The initial goal of HTML was across platforms. Unfortunately this goal has been degraded. Distinct differences between the main browsers, and how they interpret HTML. Proprietary tags introduced due to browser war. For example: <blink> only works for Netscape <marquee> only works for Internet Explorer. 5

The Problems with HTML Editors The worst abuses of HTML have subsequently found themselves coded into editor software. One needs to understand the limitations of the software one uses. A document created with three HTML editors, will produce three very different markups, but each giving rise to the same document. Many are unnecessarily long and complicated. 6

Solution: Separate Structure from Appearance There is a return to the old school of thought, one which requires a language that clearly separates the definition of a document s structure, from the definition of a document s appearance. This separation reduces to the design or appearance being a transformation using a style language operated over the structure. The standard language for doing this is Cascading Style Sheets (CSS), like HTML 4.0, CSS is an official W3C recommendation: http://www.w3.org/tr/rec-css2 7

Cascading Style Sheets (CSS) <font face= Courier size= 6 color= black >some text</font> 8 <head> <style type= text/css > <!--.defined{font-family: Courier; background-color:red; color:black; font-size: medium} --> </style> </head> <body> <p><span class= defined >some text</span></p> </body>

Document Presentation Markup comes in two varieties: markup that represents logical structure and markup that represents presentational structure. The logical structure influences but does not control the layout. One logical structure can result in multiple layouts: e.g. text-based terminal, computer screen, WebTV, paper, mobile phone even audio or Braille. Different layout are possible on the same output device. Multiple layout can be generated for presentation for a single marked up document. 9

Text terminal rendering 10

Rendering without CSS 11

What a difference CSS can make! 12

Types of CSS There are three ways of specifying styles: External style sheet (multiple pages can link to this). Internal style sheet (applies only to specify web page). Inline style (applies only to the specific element). 13

Inline Styles Each browser has default display style. Inline styles can be used to customise how elements are displayed. Examples: <body style="background-color:yellow"> <h1 style="text-align:center"> <p style="font-family:courier new; color:red; font-size:20px"> 14

Disadvantages of Inline Styles If all h2 headings need to use a certain font and alignment, then every time we specify a h2, we need to duplicate presentation attributes: <h2 style="text-align:center; font-size:10px"> blah blah </h2> Each time we want to change the style for h2, need to search andreplace everywhere. For large web pages/sites this leads to complexity and maintenance issues. Could be tens or hundreds of occurrences across tens of web pages. How to cope with on-screen display versus printed How to display same page on mobile phone or text browser? Not easy to copy the presentation style from one web page to another. 15

Embedded Style They specify uniform styles for each element in given page. Are specified in the head of your HTML document: <head> <style type="text/css"> <! h2 style="text-align:center; font-size:10px"> --> </style> </head> Older browsers do not support embedded style hence use of comments. 16

Style Rule Syntax Each style rule is of the form: selector { property:value; property:value;...; property:value; } Selectors determine which markup elements the style properties and values apply to. Example: h1 { color: white; background-color: orange } 17

Embedded Style Advantages: Uniform display of each element type within a given web page. Easy to change one location at head section. Disadvantages: To make several web pages look same, need to duplicate the embedded style in each one. 18

External Style Sheet Style rules stored in a separate file (eg mystyle.css). Each page wishing to use this style links to this external file: <head> <link rel="stylesheet" type="text/css" href="mystyle.css" /> </head> External style sheet contains list of style rules. Advantages: Many pages can share same style easily. Easy maintenance just change external style sheet. 19

How does CSS work? CSS defines an extensive set of presentation properties, including color, font size, font family, margins, borders, and many more. Web browsers assume a default set of values for each property, which may vary from element to element. For example, browsers will render <p> text differently from <em> text or <strong> text. A CSS style sheet changes that default rendering by naming an element or set of elements, and the new property values: p {color: blue; font-size: small} 20

What does it all mean? Each line in the style sheet looks something like: p {color: blue} pis the selector. This is the element to apply the style to. color is the property. blueis the valuethat we wish to set the property to. 21

Cascading? Style sheets may have three different origins: author, user and browser. The author specifies style sheets for a source document, defining a preferred presentation; The user may also specify style information for a particular document; The web browser must effectively provide a default style sheet. These rules combine together to form the final set of presentations. 22

Understanding Cascading Order You can link a single style sheet to multiple documents in your Web site by using the link element or the @import element You can also link a single document to several style sheets 23

Resolving Rule Conflict 1. By default, rules in user style sheets have higher priority than author style rules. Use!important to override. p {color: blue!important} 2.All user rules and author rules have more weight than the default supplied by the web browser. 3.If two rules of the same origin conflict, the more specific rule applies. 4.If the rules are equally specific, the last-specified rule is chosen. 24

Style precedence for one document Three ways to apply a style to an HTML or XHTML document: Inline Styles Embedded Styles External Styles Style precedence Inline > embedded > external 25

Inheritance Property values are normally inherited. Suppose there is a <h1>element with an emphasizing element (<em>) inside: <h1>the headline <em>is</em> important!</h1> If no color has been assigned to <em>element, the emphasized is will inherit the color of the parent element, so if <h1>has the color blue, the content enclosed in the <em>element will be in blue as well. 26

HTML <div> Tag The <div> element, to mark logical blocks within a document. Used to group block-elements to format them with styles. <div style="color:red"> <h3>this is a header</h3> <p>this is a paragraph.</p> </div> 27

HTML <span> Tag Used to mark sub-sequences of text. Styles can be applied to text marked with <span>: <p> I have <span style=color:brown;">brown</span> eyes and my wife has <span style="color:blue;">blue</span> eyes. </p> 28

HTML class Attribute Marks scattered members of a particular conceptual group. <html> <head> <style type="text/css"> span.blue{color:lightskyblue; font-weight:bold;} span.brown{color:brown; font-weight:bold;} </style> </head><body> <p> I have <span class= brown"> brown</span> eyes and my wife has <span class="blue">blue</span> eyes. </p> </body></html> 29