3-Oct-15 CSS First CSS Lecture Applications to HTML.

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

Part 3 Introduction to CSS. CSS Text Text Styles h1 {color: green} // rgb(0,255,0), #00ff00 h2{letter-spacing: 0.5cm} // 2px h3 {text-align: right} //
กระบวนวิชา 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.
Stylin’ with CSS. 2 Topics What is CSS? Why CSS? CSS Examples.
CS4370/6370 Web Development Cascading Style Sheets (CSS)
Text Properties, Line Box, CSS. Text Properties Properties related to the display of text. Text-align : left, right, center I like FSU!
1 CSS Styling with Fonts and Colors. 2 CSS Cascading Style Sheets and fonts CSS provides Style or Presentation options for our html pages CSS properties.
Cascading Style Sheets (CSS) Why do we need them? Separate structure from browser presentation There are many HTML presentation attributes –We want to.
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.
Using Cascading Style Sheets CSS Structure. Goals Understand how contextual, class and ID selectors work Understand how contextual, class and ID selectors.
First CSS Lecture Applications to HTML
Cascading Style Sheets1. 2 n Style sheets are a means of controlling the way HTML tags are formatted n IE introduced style sheets in IE 3.0 release n.
Creating the Presentation Layer DECO 3001 Tutorial 2 – Style Presented by Ji Soo Yoon 26 February 2004 Slides adopted from
Copyright © Terry Felke-Morris WEB DEVELOPMENT & DESIGN FOUNDATIONS WITH HTML5 7 TH EDITION Chapter 3 Key Concepts 1 Copyright © Terry Felke-Morris.
© 2007 D. J. Foreman CSS-1 Cascading Style Sheets Styles.
3.1 Cascading Style Sheets. Motto Fashions fade, style is eternal. —Yves Saint Laurent.
Stylin’ with CSS. 2 Topics What is CSS? Why CSS? CSS Examples.
Formatting Text (Plus More Selectors) Learning Web Design: Chapter 12.
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.
CSS1-1 Cascading Style Sheets (CSS) Xingquan (Hill) Zhu
HIGHER COMPUTING CSS. WHAT IS CSS? CSS: Cascaded Style Sheets used to separate a web site’s content(information) from its style(how it looks).
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,
Using Cascading Style Sheets. Introduction to Styles and Properties  Cascading Style Sheets (CSS) are a standard set by the World Wide Web Consortium.
Review: Three parts to a webpage: - Content - Structure  XHTML - Presentation  CSS In this chapter we will focus on introducing and examining the mechanics.
INTRODUCTION TO WEB DEVELOPMENT AND HTML Lecture 09: Cascade Style Sheets - Spring 2011.
Copyright © Terry Felke-Morris WEB DEVELOPMENT & DESIGN FOUNDATIONS WITH HTML5 Chapter 3 Key Concepts 1 Copyright © Terry Felke-Morris.
Chapter 7 Web Typography Principles of Web Design, 4 th Edition.
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)
Tutorial #3 Cascading Style Sheets. Review: Last Class Image sizing Pathnames Project Default Path Relative Path Absolute Path Blackboard Homework Submission.
Cascading Style Sheets CSS. CSS - Structure Declaration block Property: identifies what to change Value: how to change it Selector – example h1{ font-size:
Cascading Style Sheets " Provide means to control and change presentation of HTML documents. " Allow the user to impose a standard style. " Three levels.
CSS – Cascading Style Sheets Fred Durao
Cascading Style Sheets Orientation Learning Web Design: Chapter 11.
Cascading Style Sheets Chapter Four. What are they? A set of style rules that tell the web browser how to present a web page or document. Cascading Style.
Tutorial 5 Formatting with CSS. Objectives Session 5.1 – Evaluate why CSS styles are used – Determine where to write styles – Create an element selector.
Tutorial #3 Cascading Style Sheets. Tutorial #2 Review - Anchors Links to Site DMACC Internal Links Go to Top Mail To me Local.
Stylin’ with CSS Monday October 8 th and Tuesday October 9 th.
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.
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.
Creating Your Own Webpage COSC Cascading Stylesheets Think of: HTML: content of your webpage HTML has tags CSS: presentation and appearance of your.
 Cascading Style Sheets (CSS) ◦ Used to specify the presentation of elements separately from the structure of the document.  Inline style ◦ declare.
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.
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,
Copyright © 2006, Jumail, FSKSM, UTM Slide 1 Cascading Style Sheets (CSS)
5 th ed: Chapter 4 4 th ed: Chapter 5 SY306 Web and Databases for Cyber Operations Slide Set #4: CSS.
Developing Web Applications with HTML and CSS “Selectors and Properties”
CSS: Cascading Style Sheets Part II. Style Syntax.
1 CSS: Cascading Style Sheets W3Schools CSS tutorialCSS tutorial.
CSS Cascading Style Sheets *referenced from
Creating Layouts with CSS. Span tag Here is some underlined text. Here is some blinking text. Here's some bold text.
Basic Webpage Design Cascading Style Sheet (CSS).
Font-Family, Color and Background. Basics  CSS rule: Selector (multiple separated by, ) Declaration (multiple separated by ; ) Example: p { color: red;
CSCE Chapter 3 (Cascading Style Sheets) CSCE General Applications Programming Benito Mendoza 1 By Benito Mendoza Department of Computer.
Chapter 11 & 12 CSS Style Sheets: Intro. Why CSS? Separate presentation from content – more accessible Less work – can change appearance of whole site.
Blended HTML and CSS Fundamentals 3 rd EDITION Tutorial 3 Introducing Cascading Style Sheets.
1 CS428 Web Engineering Lecture 07 Font, Text & Background (CSS - II)
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
IS333: MULTI-TIER APPLICATION DEVELOPMENT
Applications to HTML and XHTML
Cascading Style Sheets
Presentation transcript:

3-Oct-15 CSS First CSS Lecture Applications to HTML

2 The problem with HTML HTML was originally intended to describe the content of a document Page authors didn’t have to describe the layout--the browser would take care of that This is a good engineering approach, but it didn’t satisfy advertisers and “artists” Even people that actually had something to say wanted more control over the appearance of their web pages As a result, HTML acquired more and more tags to control appearance Content and appearance became more intertwined Different browsers displayed things differently, which is a real problem when appearance is important

3 Cascading Style Sheets A Cascading Style Sheet (CSS) describes the appearance of an HTML page in a separate document CSS has the following advantages: It lets you separate content from presentation It lets you define the appearance and layout of all the pages in your web site in a single place It can be used for both HTML and XML pages CSS has the following disadvantage: Most browsers don’t support it very well

4 CSS syntax, I CSS syntax is very simple--it’s just a file containing a list of selectors (to choose tags) and descriptors (to tell what to do with them): Example: h1 {color: green; font-family: Verdana} says that everything included in h1 (HTML heading level 1) tags should be in the Verdana font and colored green A CSS file is just a list of these selector/descriptor pairs Selectors may be simple HTML tags or XML tags, but CSS also defines some ways to combine tags Descriptors are defined in CSS itself, and there is quite a long list of them

5 CSS syntax The general syntax is: selector {property: value} or selector,..., selector { property: value;... property: value } where selector is the tag to be affected (the selector is case-sensitive if and only if the document language is case-sensitive) property and value describe the appearance of that tag Spaces after colons and semicolons are optional A semicolon must be used between property:value pairs, but a semicolon after the last pair is optional

6 Example of CSS /* This is a comment */ h1,h2,h3 {font-family: Arial, sans-serif;} /* use 1st available font */ p, table, li, address { /* apply to all these tags */ font-family: "Courier New"; /* quote values containing spaces */ margin-left: 15pt; /* specify indentation */ } p, li, th, td {font-size: 80%;} /* 80% of size in containing element */ th {background-color:#FAEBD7} /* colors can be specified in hex */ body { background-color: #ffffff;} h1,h2,h3,hr {color:saddlebrown;} /* adds to what we said before */ a:link {color:darkred} /* an unvisited link */ a:visited {color:darkred} /* a link that has been visited */ a:active {color:red} /* a link now being visited */ a:hover {color:red} /* when the mouse hovers over it */ Adapted from:

7 More about selectors, I As we have seen, an XML or HTML tag can be used as a simple element selector: body { background-color: #ffffff } You can use multiple selectors: em, i {color: red} You can repeat selectors: h1, h2, h3 {font-family: Verdana; color: red} h1, h3 {font-weight: bold; color: pink} When values disagree, the last one overrides any earlier ones The universal selector * applies to any and all elements: * {color: blue} When values disagree, more specific selectors override general ones (so em elements would still be red)

8 More about selectors, II A descendent selector chooses a tag with a specific ancestor: p code { color: brown } selects a code if it is somewhere inside a paragraph A child selector > chooses a tag with a specific parent: h3 > em { font-weight: bold } selects an em only if its immediate parent is h3 An adjacent selector chooses an element that immediately follows another: b + i { font-size: 8pt } Example: I'm bold and I'm italic Result will look something like: I'm bold and I'm italic

9 More about selectors, III A simple attribute selector allows you to choose elements that have a given attribute, regardless of its value: Syntax: element[attribute] {... } Example: table[border] {... } An attribute value selector allows you to choose elements that have a given attribute with a given value: Syntax: element[attribute="value"] {... } Example: table[border="0"] {... }

10 The class attribute The class attribute allows you to have different styles for the same element In the style sheet: p.important {font-size: 24pt; color: red} p.fineprint {font-size: 8pt} In the HTML: The end is nigh! Offer ends 1/1/97. To define a selector that applies to any element with that class, just omit the tag name (but keep the dot):.fineprint {font-size: 8pt}

11 The id attribute The id attribute is defined like the class attribute, but uses # instead of. In the style sheet: p#important {font-style: italic} or # important {font-style: italic} In the HTML: class and id can both be used, and do not need to have different names:

12 div and span div and span are HTML elements whose only purpose is to hold CSS information div ensures there is a line break before and after (so it’s like a paragraph); span does not Example: CSS: div {background-color: #66FFFF} span.color {color: red} HTML: This div is treated like a paragraph, but this span is not.

13 Using style sheets There are three ways of using CSS: External style sheet This is the most powerful Applies to both HTML and XML All of CSS can be used Embedded style sheet Applies to HTML, not to XML All of CSS can be used Inline styles Applies to HTML, not to XML Limited form of CSS syntax

14 External style sheets In HTML, within the element: As a PI in the prologue of an XML document: Note: "text/css" is the MIME type

15 Embedded style sheets In HTML, within the element: Note: Embedding the style sheet within a comment is a sneaky way of hiding it from older browsers that don’t understand CSS

16 Inline style sheets The STYLE attribute can be added to any HTML element: or Advantage: Useful if you only want a small amount of markup Disadvantages: Mixes display information into HTML Clutters up HTML code Can’t use full range of CSS features

17 Cascading order Styles will be applied to HTML in the following order: 1.Browser default 2.External style sheet 3.Internal style sheet (inside the tag) 4.Inline style (inside other elements, outermost first) When styles conflict, the “nearest” (most recently applied) style wins

18 Example of cascading order External style sheet: h3 {color: red; text-align: left; font-size: 8pt } Internal style sheet: h3 {text-align: right; font-size: 20pt } Resultant attributes: color: red; text-align: right; font-size: 20pt

19 A novel example: XML This is the great American novel. It was a dark and stormy night. Suddenly, a shot rang out!

20 A novel example: CSS chapter {font-family: "Papyrus", fantasy} foreword > paragraph {border: solid red; padding: 10px} novel > foreword {font-family: Impact; color: blue} chapter {display: block} chapter:first-letter {font-size: 200%; float: left} paragraph {display: block} chapter:before {content: "New chapter: "}

21 A novel example: Result This is from Netscape 6.2--other browsers give different results

22 Some font properties and values font-family: inherit (same as parent) Verdana, "Courier New",... (if the font is on the client computer) serif | sans-serif | cursive | fantasy | monospace (Generic: your browser decides which font to use) font-size: inherit | smaller | larger | xx-small | x-small | small | medium | large | x-large | xx-large | 12pt font-weight: normal | bold |bolder | lighter | 100 | 200 |... | 700 font-style: normal | italic | oblique

23 Shorthand properties Often, many properties can be combined: h2 { font-weight: bold; font-variant: small-caps; font- size: 12pt; line-height: 14pt; font-family: sans-serif } can be written as: h2 { font: bold small-caps 12pt/14pt sans-serif }

24 Colors and lengths color: and background-color: aqua | black | blue | fuchsia | gray | green | lime | maroon | navy | olive | purple | red | silver | teal | white | #FF0000 | #F00 | rgb(255, 0, 0) | Additional browser-specific names (not recommended) These are used in measurements: em, ex, px, % font size, x-height, pixels, percent of inherited size in, cm, mm, pt, pc inches, centimeters, millimeters, points (1/72 of an inch), picas (1 pica = 12 points), relative to the inherited value

25 Some text properties and values text-align: left | right | center | justify text-decoration: none | underline | overline | line-through text-transform: none | capitalize | uppercase | lowercase text-indent length | 10% (indents the first line of text) white-space: normal | pre | nowrap

26 Pseudo-classes Pseudo-classes are elements whose state (and appearance) may change over time Syntax: element:pseudo-class {...} :link a link which has not been visited :visited a link which has been visited :active a link which is currently being clicked :hover a link which the mouse is over (but not clicked) Pseudo-classes are allowed anywhere in CSS selectors

27 Choosing good names CSS is designed to separate content from style Therefore, names that will be used in HTML or (especially) in XML should describe content, not style Example: Suppose you define span.huge {font-size: 36pt} and you use throughout a large number of documents Now you discover your users hate this, so you change the CSS to be span.huge {font-color: red} Your name is inappropriate; do you change all your documents? If you had started with span.important {font-size: 36pt}, your documents wouldn’t look so dumb

28 References Some of the examples in this presentation were taken from the W3Schools online tutorial at Dave Raggett’s Adding a Touch of Style is a very nice online tutorial at Index DOT Css has also been a great source of information about CSS: In particular, there is a list of when CSS features were first supported by which browsers ( -- means “not yet supported”) at