CS 174: Web Programming September 9 Class Meeting Department of Computer Science San Jose State University Fall 2015 Instructor: Ron Mak www.cs.sjsu.edu/~mak.

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

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.
CSS BASICS. CSS Rules Components of a CSS Rule  Selector: Part of the rule that targets an element to be styled  Declaration: Two or more parts: a.
XP Introducing Cascading Style Sheets With Cascading Style Sheets (CSS), you can create one or more documents that control the appearance of some or all.
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.
Introduction to Web Site Development Steven Emory Department of Computer Science California State University, Los Angeles Lecture 5: Cascading Style Sheets.
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.
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.
Chapter 4 Cascading Style Sheets Basics Key Concepts Copyright © 2013 Terry Ann Morris, Ed.D 1.
Cascading Style Sheets Example
Cascading Style Sheets CS3505. What are CSS? Method for adding style attributes consistently to HML tags Cascading because styles are applied in order.
Cascading Style Sheets Billy Toy Cascading Style Sheets Syntax review How to Implement style sheets Background properties Text properties.
CSS Dvijesh Bhatt.
Cascading style sheets (CSS)
Copyright © Terry Felke-Morris WEB DEVELOPMENT & DESIGN FOUNDATIONS WITH HTML5 Chapter 3 Key Concepts 1 Copyright © Terry Felke-Morris.
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)
Tutorial #3 Cascading Style Sheets. Review: Last Class Image sizing Pathnames Project Default Path Relative Path Absolute Path Blackboard Homework Submission.
Copyright © Terry Felke-Morris WEB DEVELOPMENT & DESIGN FOUNDATIONS WITH HTML5 Chapter 3 Key Concepts 1 Copyright © Terry Felke-Morris.
Cascading Style Sheets Part 1 Presentation by Audrey Altman Exercises from CSS: The Missing Manual.
WDV 101 Intro to Website Development
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.
Today’s objectives  Review  CSS | Rules | Declarations  HTML Structure document  Class asignment.
Part 1: CSS - Why? - How it works - Writing rules - Examples.
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.
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 #3 Cascading Style Sheets. Tutorial #2 Review - Anchors Links to Site DMACC Internal Links Go to Top Mail To me Local.
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.
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.
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…
The Web Wizard’s Guide To DHTML and CSS Chapter 1 A Review of CSS1.
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.
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)
LEARN THE QUICK AND EASY WAY! VISUAL QUICKSTART GUIDE HTML and CSS 8th Edition Chapter 7: CSS Building Blocks.
CSS properties Basharat Mahmood, Department of Computer Science, CIIT, Islamabad, Pakistan 1.
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
Font-Family, Color and Background. Basics  CSS rule: Selector (multiple separated by, ) Declaration (multiple separated by ; ) Example: p { color: red;
Tutorial 3 Designing a Web Page with CSS
ECA 228 Internet/Intranet Design I Cascading Style Sheets.
Chapter 11 & 12 CSS Style Sheets: Intro. Why CSS? Separate presentation from content – more accessible Less work – can change appearance of whole site.
Links All CSS properties can be applied on links (i.e. change colors, fonts, underline, etc). The new thing is that CSS allows you to define these properties.
CSS Introductions. Objectives To take control of the appearance of a Web site by creating style sheets. To use a style sheet to give all the pages of.
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.
Cascading Style Sheets
CMPE 280 Web UI Design and Development September 5 Class Meeting
Cascading Style Sheets
CMPE 280 Web UI Design and Development February 6 Class Meeting
>> Dynamic CSS Selectors
Cascading Style Sheets
Presentation transcript:

CS 174: Web Programming September 9 Class Meeting Department of Computer Science San Jose State University Fall 2015 Instructor: Ron Mak

Computer Science Dept. Fall 2015: September 9 CS 174: Web Programming © R. Mak HTML and CSS  HTML content organization semantics  Cascading Style Sheet (CSS) layout formatting 2

Computer Science Dept. Fall 2015: September 9 CS 174: Web Programming © R. Mak Link to a Style Sheet  An HTML page can link to an external style sheet. Example: 3 Paragraphs and Headings...

Computer Science Dept. Fall 2015: September 9 CS 174: Web Programming © R. Mak Example Style Sheet  Style sheet css/mystyles1.css: All h1 headings should have red text on a yellow background. All h2 headings should have a gray text. 4 h1 { background-color: yellow; color: red; } h3 { color: gray; } Demo

Computer Science Dept. Fall 2015: September 9 CS 174: Web Programming © R. Mak Style Rules  Each style rule has a selector and a declaration block. A declaration block consists of one or more declarations. A declaration is a property: value pair. 5 h1 { background-color: yellow; color: red; } h3 { color: gray; } selector declaration block declaration style rule

Computer Science Dept. Fall 2015: September 9 CS 174: Web Programming © R. Mak Style Colors  Specify colors for CSS properties with a predefined color keyword: 6 See for the complete list of predefined colors. HTML and CSS, 8 th ed. by Elizabeth Castro and Bruce Hyslop Peachpit Press, 2014 ISBN

Computer Science Dept. Fall 2015: September 9 CS 174: Web Programming © R. Mak Style Colors, cont’d  You can specify colors by RGB (red-green- blue). Example: rgb(178, 60, 0) where each value can range from 0 through 255.  You can include alpha transparency with RGBA. Example: rgba(178, 60, 0, 0.75) where the transparency value ranges from 0 to 1 0 is completely transparent, 1 is completely opaque.  Also available: HSL (hue-saturation-lightness) and HSLA Examples:hsl(282, 90%, 25%) hsla(282, 90%, 25%, 0.5) 7

Computer Science Dept. Fall 2015: September 9 CS 174: Web Programming © R. Mak Element Classes  An HTML element can have a class name. Several elements can share the same class name. Examples: 8 Lorem ipsum dolor sit amet, consectetur adipiscing elit,... Duis aute irure dolor in reprehenderit in voluptate velit...

Computer Science Dept. Fall 2015: September 9 CS 174: Web Programming © R. Mak Class Selectors  A style sheet can apply a style to all HTML elements of a particular class. Example: 9.latin { font-style: italic; } Demo

Computer Science Dept. Fall 2015: September 9 CS 174: Web Programming © R. Mak Class Selectors, cont’d  An element can have more than one class. Example:  To style an element with both classes: There is no space between the two class names in the selector. 10.class-1.class-2 {... }

Computer Science Dept. Fall 2015: September 9 CS 174: Web Programming © R. Mak Element IDs  An HTML element can have an ID. An ID must be unique and cannot be shared. Examples: 11 This is a paragraph. Chapter 2 Yet another paragraph.

Computer Science Dept. Fall 2015: September 9 CS 174: Web Programming © R. Mak ID Selectors  A style sheet can apply styles to HTML elements with particular IDs. Examples: The use of element IDs is generally discouraged because styles cannot be reused. 12 #alpha { font-variant: small-caps; } #beta { font-size: x-large; } Demo

Computer Science Dept. Fall 2015: September 9 CS 174: Web Programming © R. Mak Grouping Selectors  To group selectors in order to share a declaration block, separate the selectors with commas. Example: 13 h1, h3 { background-color: yellow; color: red; }

Computer Science Dept. Fall 2015: September 9 CS 174: Web Programming © R. Mak Defining Selectors  CSS provides many ways to define selectors.  You’ve already seen: by element name: h1, h2, p by class name:.latin by element ID: #alpha, #beta 14

Computer Science Dept. Fall 2015: September 9 CS 174: Web Programming © R. Mak Select Elements by Context  Select elements based on their ancestors, parents, or siblings.  Example: Select paragraphs that are nested inside an element with class formula (i.e., paragraphs that are descendants of such an element).  Example: Select paragraphs that are direct children of an element with class formula. 15.formula p {... }.formula > p {... }

Computer Science Dept. Fall 2015: September 9 CS 174: Web Programming © R. Mak Select Elements by Context, cont’d  Example: Select only the paragraphs that directly follow a sibling paragraph. 16.formula p+p {... }

Computer Science Dept. Fall 2015: September 9 CS 174: Web Programming © R. Mak Select Elements by Context, cont’d 17 HTML and CSS, 8 th ed. by Elizabeth Castro and Bruce Hyslop Peachpit Press, 2014 ISBN

Computer Science Dept. Fall 2015: September 9 CS 174: Web Programming © R. Mak Select Elements by Context, cont’d 18 HTML and CSS, 8 th ed. by Elizabeth Castro and Bruce Hyslop Peachpit Press, 2014 ISBN

Computer Science Dept. Fall 2015: September 9 CS 174: Web Programming © R. Mak Select Elements by Context, cont’d 19 HTML and CSS, 8 th ed. by Elizabeth Castro and Bruce Hyslop Peachpit Press, 2014 ISBN

Computer Science Dept. Fall 2015: September 9 CS 174: Web Programming © R. Mak Select the First or Last Child Elements  Example: Select the first item of a list.  Example: Select the last item of a list. 20 li:first-child {... } li:last-child {... }

Computer Science Dept. Fall 2015: September 9 CS 174: Web Programming © R. Mak Select the First or Last Child Elements, cont’d 21 HTML and CSS, 8 th ed. by Elizabeth Castro and Bruce Hyslop Peachpit Press, 2014 ISBN

Computer Science Dept. Fall 2015: September 9 CS 174: Web Programming © R. Mak Select the First Letter or the First Line  Example: Select the first letter of every paragraph.  Example: Select the first line of every paragraph. 22 p:first-letter {... } p:first-line {... }

Computer Science Dept. Fall 2015: September 9 CS 174: Web Programming © R. Mak Select the First Letter or the First Line, cont’d 23 HTML and CSS, 8 th ed. by Elizabeth Castro and Bruce Hyslop Peachpit Press, 2014 ISBN

Computer Science Dept. Fall 2015: September 9 CS 174: Web Programming © R. Mak Select Links Based on State  Link states: not yet visited visited focused via the tab key hovered over by the mouse activated by the visitor 24

Computer Science Dept. Fall 2015: September 9 CS 174: Web Programming © R. Mak Select Links Based on State, cont’d 25 Links An absolute link to the Paragraphs and Headings page. A relative link to the Tables page.

Computer Science Dept. Fall 2015: September 9 CS 174: Web Programming © R. Mak Select Links Based on State, cont’d 26 a:link { color: red; } a:visited { color: orange; } a:focus { color: purple; } a:hover { color: green; } a:active { color: blue; } Demo

Computer Science Dept. Fall 2015: September 9 CS 174: Web Programming © R. Mak Select Elements Based on Attributes  Example: Select any paragraph that has a class attribute. 27 p[class] {... }

Computer Science Dept. Fall 2015: September 9 CS 174: Web Programming © R. Mak Select Elements Based on Attributes, cont’d 28 HTML and CSS, 8 th ed. by Elizabeth Castro and Bruce Hyslop Peachpit Press, 2014 ISBN

Computer Science Dept. Fall 2015: September 9 CS 174: Web Programming © R. Mak Select Elements Based on Attributes, cont’d  Attribute selector options: 29 HTML and CSS, 8 th ed. by Elizabeth Castro and Bruce Hyslop Peachpit Press, 2014 ISBN

Computer Science Dept. Fall 2015: September 9 CS 174: Web Programming © R. Mak Inheritance  An HTML element inherits style properties from its ancestors. 30 HTML and CSS, 8 th ed. by Elizabeth Castro and Bruce Hyslop Peachpit Press, 2014 ISBN

Computer Science Dept. Fall 2015: September 9 CS 174: Web Programming © R. Mak What Can Be Inherited  Text color (except by the a element) direction font font-family font-size font-style font-variant font-weight letter-spacing line-height text-align text-indent text-transform visibility white-space word-spacing  Lists list-style list-style-image list-style-position list-style-type  Tables border-collapse border-spacing caption-side empty-cells  Paged Media (as in printing) orphans page-break-inside widows  Other cursor quotes 31

Computer Science Dept. Fall 2015: September 9 CS 174: Web Programming © R. Mak The Cascade  The cascade principle resolves conflicting style properties for an HTML element.  Specificity The more specific the selector, the stronger the rule. Some selectors from least specific to most specific: 32 HTML and CSS, 8 th ed. by Elizabeth Castro and Bruce Hyslop Peachpit Press, 2014 ISBN

Computer Science Dept. Fall 2015: September 9 CS 174: Web Programming © R. Mak The Cascade, cont’d  Order Rules that appear later take precedence over earlier rules.  Importance A style marked as !important overrides specificity and order. Example: 33 { color: purple !important; }

Computer Science Dept. Fall 2015: September 9 CS 174: Web Programming © R. Mak Embedded Style Sheet 34 Embedded Style Sheet img { border: 4px solid red; }...  Not as clean a separation of content and style.

Computer Science Dept. Fall 2015: September 9 CS 174: Web Programming © R. Mak Inline Styles  Example:  Not recommended! Combines content and style. We want to separate content and style! 35