Introduction to Cascading Style Sheets Pat Morin COMP 2405.

Slides:



Advertisements
Similar presentations
Building a Website: Cascading Style Sheets (CSS) Fall 2013.
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} //
Cascading Style Sheets (Formatting. Slide 2 Lecture Overview At this point, you have learned how and where to create styles You have not learned much.
Tutorial 4 Formatting Text. XP New Perspectives on Blended HTML, XHTML, and CSS2 Objectives Create a spread heading Indent text Change the line spacing.
CS4370/6370 Web Development Cascading Style Sheets (CSS)
Week 7 Web Typography. 2 Understanding Type Design Principles.
Web Design & Development Cascading Style Sheets (CSS)
CS134 Web Design & Development Cascading Style Sheets (CSS) Mehmud Abliz.
Using Cascading Style Sheets CSS Structure. Goals Understand how contextual, class and ID selectors work Understand how contextual, class and ID selectors.
Lecture CSS: Cascading Style Sheets. What are Styles? Cascading Style Sheets (CSS) is a style sheet language used to describe the presentation semantics.
Lecture 7 Cascading Style Sheets (CSS) Boriana Koleva Room: C54
© 2007 D. J. Foreman CSS-1 Cascading Style Sheets Styles.
3.1 Cascading Style Sheets. Motto Fashions fade, style is eternal. —Yves Saint Laurent.
Formatting Text (Plus More Selectors) Learning Web Design: Chapter 12.
CSS1-1 Cascading Style Sheets (CSS) Xingquan (Hill) Zhu
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.
Cascading Style Sheets Example
CSS Dvijesh Bhatt.
Cascading style sheets (CSS)
Chapter 7 Web Typography Principles of Web Design, 4 th Edition.
Principles of Web Design 6 th Edition Chapter 5 – Web Typography.
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.
Cascading Style Sheets, pt 2 ECA 225 Applied Online Programming.
Cascading Style Sheets CSS. CSS - Structure Declaration block Property: identifies what to change Value: how to change it Selector – example h1{ font-size:
INTRODUCTION TO HTML5 Styling Text. Change the Font Size  You can use the font-size property to change the font size for a document’s text.  Instead.
Cascading Style Sheets " Provide means to control and change presentation of HTML documents. " Allow the user to impose a standard style. " Three levels.
 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 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.
Class three: CSS review, backgrounds, font formatting, the box model.
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.
Introduction to CSS. What is CSS?  Cascading Style Sheets  Used for styling HTML  Also important in javascript and jquery for selectors  External.
MySQL and PHP Review CSS. Cascading Style Sheet (CSS) Style sheets are files or forms that describe the layout and appearance of a document. Cascading.
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.
Cascading Style Sheets Robin Burke ECT 270. Outline Midterm The Layout Debate CSS properties Fonts Alignment Color CSS selection selectors pseudo-classes.
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 (CSS) ◦ Used to specify the presentation of elements separately from the structure of the document.  Inline style ◦ declare.
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.
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)
CIS234A Lecture 5 Instructor Greg D’Andrea. Font Styles Review Font-Family: generic family, font family Font-Size: em, pt, px, %, mm, cm, in Font-Style:
©SoftMoore ConsultingSlide 1 Introduction to HTML: Cascading Style Sheets.
Cascading Style Sheets Web Design Fairport High School.
5 th ed: Chapter 4 4 th ed: Chapter 5 SY306 Web and Databases for Cyber Operations Slide Set #4: CSS.
CSS for Styling CS The good, the bad and the… ugly!  Tags such as b, i, u, and font are discouraged in strict XHTML  Why is this bad? CS380 2.
Developing Web Applications with HTML and CSS “Selectors and Properties”
CSS: Cascading Style Sheets Part II. Style Syntax.
Class & ID Selectors, Font and List Properties. Id Selectors  # followed by Id-name (without space)  Can be used once on a page  Examples: #p1 { color:
ECA 228 Internet/Intranet Design I Cascading Style Sheets.
Tutorial 3 Designing a Web Page with CSS
03 CSS (Cascading StyleSheet) Р.Жавхлан МОНГОЛ УЛСЫН ИХ СУРГУУЛЬ Мэдээллийн технологийн сургууль Интернэт технологийн үндэс 2015 Намар.
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)
CSS Details Cascading Style Sheets. Lesson Overview  In this lesson, you will learn:  To use CSS properties for fonts  Evaluate whether to use pts,
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.
WebD Introduction to CSS By Manik Rastogi.
Cascading Style Sheets
Introducing :CSS Cascading Style Sheets in 5 Lessons.
Cascading Style Sheets (Formatting)
IS333: MULTI-TIER APPLICATION DEVELOPMENT
CSS Style Sheets: Intro
CS3220 Web and Internet Programming CSS Basics
Cascading Style Sheets™ (CSS)
Presentation transcript:

Introduction to Cascading Style Sheets Pat Morin COMP 2405

2 Outline Motivation for CSS How to use CSS in your documents Formatting text with CSS – Font properties – Text properties Formatting lists with CSS Summary

3 HTML HTML (when used correctly) describes the different parts of a document – Paragraphs, section headings, quotes, images,... HTML (when used correctly) does not describe the formatting of a document HTML is a logical markup language not a physical markup language HTML was designed to be rendered on a wide variety of devices – Graphical web browsers, text terminals, screen readers,...

4 CSS CSS (Cascading Style Sheets) is for the formatting side of the Web CSS describes how rendered HTML documents should look CSS considers the physical and visual display of the document (the Style)

5 Advantages of CSS The use of CSS separates document layout from document content – Different people can be responsible for the two parts – Document author can focus on content – Graphic designer can focus on layout A single file can control the look of an entire web site – Easy to modify look of web site without affecting its contents – Easy to obtain a consistent look (the R in CRAP) If done correctly, documents degrade gracefully on platforms that don't support visual formatting

6 Disadvantages of CSS More to learn – CSS is powerful but complex Not fully supported on some browsers – Even some modern browsers are not fully CSS 2 compliant The formatting is separated from the document – Makes it hard to write a document and format it simultaneously

7 How to Write a Document 1. Decide what you want to write ● First and foremost the content of the document is important ● Decide on the logical structure of the document 2. Write it ● Write the document content ● Markup the document's logical structure 3. Format it ● Use CSS to do formatting ● Add other formatting-specific data (e.g., navigation) ● Points 1 and 2 should take the majority of the time

8 Using CSS There are three ways to use CSS External Style Sheets – Uses the LINK tag (in the document HEAD) <link rel=”stylesheet” href=”../morin.css” type=”text/css”> Inline Style Sheets – The STYLE tag (in the document HEAD) /* CSS information goes here */

9 Using CSS (Cont'd) Inline STYLE Attributes – The STYLE attribute (within another HTML tag) Don't use these – Gives the disadvantages of CSS without the most important advantages

10 Simple CSS An Inline CSS example that modifies some of the common HTML tags h1 { font-size: 12pt; font-family: “Luxi Sans”, sans-serif; font-weight: bold; } p { font-size: 12pt; font-family: “Luxi Serif”, serif; }

11 CSS with Class (Almost) all HTML tags can have an optional CLASS attribute This works nicely in conjunction with CSS: p.blogentry { font-size: 12pt; font-family: “Luxi Serif”, serif; }... Today was the best day ever...

12 CSS with IDs Similarly, almost all HTML tags can have an ID attribute: #menubar { font-size: 12pt; font-family: “Luxi Serif”, serif; }... Item 1...

13 Notes on CLASS and ID Use CLASS when a document contains (or may contain) many items of this type – E.g.: blogEntry, nameList, properName Use ID when a document can only contain one item of this type – E.g. pageTitle, mainNavigationBar Choose CLASS and ID names wisely – Good: Pat Morin – Bad: Pat Morin

14 The DIV and SPAN tags HTML has 2 tags, DIV and SPAN, that are specifically used with CSS and CLASS and ID attributes A DIV tag contains a block of text – Like a paragraph, section heading, or title A SPAN tag contains a short piece of text within a block – Like a proper name, or a dollar amount

15 Example of DIV and SPAN On his way to school, Uncle Rico stopped at the local groceteria and spent $4.55 on milk, bread, and honey. This document was written by Pedro Sanchez on Jan. 9th, 2007.

16 Typeface: font-family Consists of a comma-separated list of font names h1 { font-family: “Times New Roman”, “Luxi Serif”, “DejaVu LGC Serif”, serif; } Not all fonts are available on all systems – Browser will try fonts in order that they are specified Always make the last option one of the generic fonts: serif, sans-serif, cursive, fantasy, or monospace

17 Font Size: font-size Specified in one of the CSS size units – 1em is the width of a letter m (relative to surrounding text) – 1pt is a standard typographic point (1/72 inches) – 1px is one screen pixel – Keywords: xx-small, x-small, small, medium, large, x-large, xx-large are browser dependant – Percentages: XXX% relative to the surrounding code Points and pixels are extremely accurate but not resizeable h1 { font-size: 200%; } h2 { font-size: large; } h3 { font-size: medium; }

18 Bold Fonts: font-weight Can be one of normal, bold, bolder, lighter, 100, 200,..., 900 h1 { font-weight: bold; font-size: 200%; } h2 { font-weight: bold; font-size: medium; }

19 The Font Style: font-style Can be one of normal, italic, or oblique An italic font is usually slanted and maybe has some curls added An oblique font is a skew transformation of a regular font (not well supported) em { font-style: italic; } h1 { font-family: sans-serif; font-weight: bold; font-style: italic; }

20 Other Font Properties Use font-variant for producing small caps Use font-stretch to expand or condense a font Use font as a shorthand to set all font properties at once h1 { font: italic small-caps bold 12pt sans-serif; }

21 Text Properties: color Can be a color name, a rgb value, or a hexadecimal value 147 color names are at – /* Make all headings pure red */ H1 { color: red; } H2 { color: rgb(255,0,0); } H3 { color: #ff0000; }

22 Text Properties: background The background property specifies the background color and/or image background-color specifies a color (named, RGB, or hex) background-image, background-position, background-repeat, and/or background- attachment to specify a background image Usually used on the body tag

23 Text Properties: text-align Determine which side of the page (or containing box) that text lines up with Can be one of left, right, center, or justify h1 { text-align: center; } p { text-align: left; }

24 Text Properties: text-decoration Add some decoration to the text Can be one of none, underline, overline, line- through, or blink Treat blink like a contagious disease h1 { text-decoration: underline; } a { text-decoration: none; }

25 Text Properties: text-indent Specifies a length by which the first line of text should be indented Length can be measured in a relative unit – em: the font-size of the current font (width of a letter m) – ex: the x-height of the current font (height of a letter x) – px: one screen pixel Or an absolute unit – Inches (in) centimeters (cm) millimeters (mm), points (pt), or picas (pc) 1pt = (1/72)in and 1pc=12pt P { text-indent: 5em; }

26 Text Properties: text-transform Can actually transform the text Can be one of – none: don't do anything to the text – capitalize: Start each word with an uppercase letter – uppercase: Make everything uppercase (allcaps) – lowercase: Make everything lowercase h1 { font-size: large; text-transform: capitalize; } h2 { font-size: normal; text-transform: uppercase; }

27 Text Properties: white-space Defines how white space (space, tabs, carriage- returns) is handled Can be one of – normal: Normal formatting, wrap at white space, merge multiple whitespace – pre: treat as preformatted text – nowrap: don't wrap at whitespace a.properName { white-space: nowrap; }

28 Other Text Properties direction: Sets the text direction line-height: Sets the distance between lines letter-spacing: Sets the space between characters text-shadow: Make a colored text shadow unicode-bidi – Allows english blocks to flow left-to-right and Arabic blocks flow right-to-left on the same page word-spacing: Sets the space between words These probably should not be used unless you know a lot about typesetting.

29 CSS and Lists Several properties are specific to lists and list items list-style-image: sets an image to use as the bullet marker list-style-position: controls where the bullet appears list-style-type: specifies what kind of bullet to use – none, disc, circle, square, decimal, decimal-leading-zero, lower-roman, upper-roman, lower-alpha, upper-alpha, lower- greek, lower-latin, upper-latin, hebrew, armenian,,georgian, cjk-ideographic, hiragana, katakana, hiragana-iroha, katakana-iroha ul.menu li { list-style-type: none; }

30 CSS Lookup We can specify styles that apply to tags or identifiers only when contained in other tags ul.menu { padding: 0; } ul.menu li { text-decoration: none; }... Menu item1 Menu item2

31 CSS and the A Tag CSS has several options for the A tag – A:link defines the style for normal unvisited links – A:visited defines the style for links that have already been visited in the past – A:active defines the style for links after the user clicks on them (usually while the next page loads) – A:hover defines the style for links when the mouse pointer is hovering over them A:hover is useful for making things that look like menus

32 Summary CSS provides fine-grained control over – fonts – text – the display of lists The CSS lookup mechanism allows us to apply styles to tags that only appear within other tags In practice, many authors ignore most HTML tags other than DIV and SPAN