Using CSS (Cascading Style Sheets) Effie Nadiv Edited by permission from author by Amir Kirsh.

Slides:



Advertisements
Similar presentations
Copenhagen, 6 December 2004 Modern CSS Principles Miruna Bădescu Finsiel Romania.
Advertisements

Table, List, Blocks, Inline Style
CSS Cascading Style Sheets. Objectives Using Inline Styles Working with Selectors Using Embedded Styles Using an External Style Sheet Applying a Style.
Web Pages Week 10 This week: CSS Next week: CSS – Part 2.
1 Cascading Style Sheets Continued Different kinds of selectors in a style sheet –Simple- Pseudo-Class –Contextual- Pseudo-Element –Class Image Styles.
Cascading Style Sheets
Cascading Style Sheets
Copyright © Terry Felke-Morris WEB DEVELOPMENT & DESIGN FOUNDATIONS WITH HTML5 Chapter 6 Key Concepts 1 Copyright © Terry Felke-Morris.
Presenter: James Huang Date: Sept. 26,  Introduction  Basics  Lists  Links  Forms  CSS 2.
CSS. Intro to CSS Cascading Style Sheets – styles and enhances appearance of webpage.css extension.
NSWI142 – Web Applications Lecture 3 – CSS (Part 1) Martin Nečaský, Ph.D. Web Applications (NSWI142 ), Lecture 31.
Lecture 5 Use Cases and Style Sheets
Copyright © Terry Felke-Morris WEB DEVELOPMENT & DESIGN FOUNDATIONS WITH HTML5 Chapter 6 Key Concepts 1 Copyright © Terry Felke-Morris.
Very quick intro HTML and CSS. Sample html A Web Title.
FORMATTING IN CONTEXT. FOLLOW UPS ANCHOR POINTS MUST BE UNIQUE  If you have more than one, how does it know where to go?  They can be repeated across.
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.
Cascading Style Sheets By: Valerie Kuna. What are Cascading Style Sheets? Cascading Style Sheets (CSS) are a standard for specifying the presentation.
Today’s objectives  Element relations – tree structure  Pseudo classes  Pseudo elements.
© 2004, Robert K. Moniot Chapter 6 CSS : Cascading Style Sheets.
Advance CSS (Menu and Layout) Miftahul Huda. CSS Navigation MENU It's truly remarkable what can be achieved through CSS, especially with navigation menus.
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.
Building a Website: Cascading Style Sheets (CSS) Fall 2013.
With CSS, a color is most often specified by: a HEX value - like "#ff0000" an RGB value - like "rgb(255,0,0)" a color name - like "red“ Example h1.
1 Pengantar Teknologi Internet W03: CSS Cascading Style Sheets.
CIS 1310 – HTML & CSS 6 Layout. CIS 1310 – HTML & CSS Learning Outcomes  Describe & Apply the CSS Box Model  Configure Float with CSS  Designate Positioning.
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.
CSS(Cascading Style Sheets )
Web Pages and Style Sheets Bert Wachsmuth. HTML versus XHTML XHTML is a stricter version of HTML: HTML + stricter rules = XHTML. XHTML Rule violations:
กระบวนวิชา 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.
Class four: the box model and positioning. is an HTML tag which allows you to create an element out of inline text. It doesn’t mean anything! try it:
CSS normally control the html elements. Three Ways to Insert CSS There are three ways of inserting a style sheet: External style sheet Internal style.
Web Design with Cascading Style Sheet Lan Vu. Overview Introduction to CSS Designing CSS Using Visual Studio to create CSS Using template for web design.
Cascading style sheets CSS
Using CSS for Page Layout. Types of HTML Elements Block-Level Element –Creates blocks of content e.g. div, h1..h6, p, ul, ol, li, table, form –They start.
CSS (Cascading Style Sheets): How the web is styled Create Rules that specify how the content of an HTML Element should appear. CSS controls how your web.
Principles of Web Design 6 th Edition Chapter 4 – Cascading Style Sheets.
Cascading style sheets (CSS)
Week 4.  Three ways to apply CSS: Inline CSS Internal style sheets ( header style information) External style sheets.
Basics of Smarajit Dasgupta.
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.
 Word doc for you to download › Link at the beginning of class › 10 Questions › Answers to be added inline  Post to Sakai when completed › No resubmits.
Lecture 2 - HTML and CSS Review SFDV3011 – Advanced Web Development 1.
Chapter 6 Introducing Cascading Style Sheets Principles of Web Design, 4 th Edition.
Cascading Style Sheets Primary readings Presentations Explain & review projects with class mates.
CSS: Cascading Style Sheets Part II. Style Syntax.
CIS 228 The Internet 10/18/11 Grouping XHTML. CSS Selectors Rule: selector-group { property-declaration* } Selector-group: selector *, Selector: simple-selector.
WebD Introduction to CSS By Manik Rastogi.
Cascading Style Sheets (CSS) Internal Style Sheets Classes
HTML & CSS Jan Janoušek.
Semester - Review.
CSS Layouts: Grouping Elements
>> The “Box” Model
Chapter 3 Style Sheets: CSS
Cascading Style Sheets (Layout)
Web Development & Design Foundations with HTML5 7th Edition
Web Development & Design Foundations with HTML5 8th Edition
Web Development & Design Foundations with HTML5
Cascading Style Sheets
6 Layout.
Cascading Style Sheets
Web Development & Design Foundations with H T M L 5
Web Development & Design Foundations with HTML5
Web Development & Design Foundations with HTML5
The Internet 10/20/11 CSS Layout
CS3220 Web and Internet Programming More CSS
Introduction to Cascading Style Sheets (CSS)
Presentation transcript:

Using CSS (Cascading Style Sheets) Effie Nadiv Edited by permission from author by Amir Kirsh

Using CSS Linking CSS Selector Styling Hacking

Quick History First CSS proposal by Hakon Lie in Oct 94 W3C established and CSS workshop run in 95 CSS1 becomes a recommendation in Dec 96 CSS2 becomes a recommendation in May 98 Drafts of first 3 CSS3 modules published in June 99

CSS Linking Alternate:

Use Relativity When linking to a style sheet use a relative path: href="skins/sg/narrow.css" When pointing a resource inside a style sheet use a relative path: src=”images/my-image.png”

CSS Rule selector { property: value;}

Selector ID (#main-menu) Class (.sidebar) HTML tag (body) body{background-color:#fff;} body #wrapper {background-color:#ccc;} body div.menu {background-color:#fff;}

CSS 2.1 selector syntax Universal*Matches any element TypeEMatches any E element. Class.info Matches any element whose class attribute contains the value info. Id#footer Matches any element with an id equal to footer DescendantE F Matches any F element that is a descendant of an E element. ChildE > F Matches any F element that is a child of an E element.

CSS 2.1 selector syntax AttributeE[att] Matches any E element that has an att attribute, regardless of its value. AttributeE[att=val] Matches any E element whose att attribute value is exactly equal to val. Attribute Matches any E element E[att~=val] whose att attribute value is a list of space-separated values, one of which is exactly equal to val. pseudo-class E:first-child Matches element E when E is the first child of its parent. Adjacent sibling selectorsp + p matches an element which is the next sibling to the first element

Descendant selectors div p { color:#f00; } div#myid li p.info { color:#f00; }

Child selectors div > span { color:#f00; }

Pseudo-classes a:link a:visited a:hover a:active a.error:visited {color: #f00}

Pseudo-elements p:first-letter { color:#0000ff; font-variant:small-caps } a:link:after { content: " (" attr(href) ") "; }

Adjacent sibling selectors p + p { color:#f00; } Paragraph one Paragraph two

Attribute selectors p[title] { color:#f00; } div[class=error] { color:#f00; } td[headers~=col1] { color:#f00; } p[lang|=en] { color:#f00; }

Grouping Selectors h1,h2,h3,h4,h5,h6 { color: #000; }

CSS Selector Specificity

A selector's specificity is calculated as follows: count the number of ID attributes in the selector (= a) count the number of other attributes and pseudo- classes in the selector (= b) count the number of element names in the selector (= c) ignore pseudo-elements. Concatenating the three numbers a-b-c (in a number system with a large base) gives the specificity.

Some examples: * {} /* a=0 b=0 c=0 -> specificity = 0 */ LI {} /* a=0 b=0 c=1 -> specificity = 1 */ UL LI {} /* a=0 b=0 c=2 -> specificity = 2 */ UL OL+LI {} /* a=0 b=0 c=3 -> specificity = 3 */ H1 + *[REL=up]{} /* a=0 b=1 c=1 -> specificity = 11 */ UL OL LI.red {} /* a=0 b=1 c=3 -> specificity = 13 */ LI.red.level {} /* a=0 b=2 c=1 -> specificity = 21 */ #x34y {} /* a=1 b=0 c=0 -> specificity = 100 */

Styling Fonts Colors Position Navigation Forms Images

Fonts Do not change font-family Use presents (%) size Do not bold more than 5% of text Mind the line-height (longer lines – more height)

Colors The less, the better Use spark colors Vary chroma and lumina to pick near colors Never use red unless it is an error!

Position Do not override the style guide template When you think about width:100% use “auto” Remember the box model (paddings are ontop of the 100%) Float, float float Make floats “display: inline;”

Navigation Don't mask link color schema

Forms Use standard forms Do not style form elements (inputs, buttons) Use fieldset and legend Use a dl element to structure the form

Images Use image maps #layout-switcher #layout-wide{ background: transparent url( images/tb-layout.gif ) no-repeat left top; } #layout-switcher #layout-normal{ background: transparent url( images/tb-layout.gif ) no-repeat -36px top; } #layout-switcher #layout-wide:hover{ background-position: left -25px; } #layout-switcher #layout-normal:hover{ background-position: -36px -25px; }

Hacking – Fixing behaviour by errors Aiming a rule at a specific browser in order to workaround a bug (usually an IE bug) Logical errors Scope errors Syntax errors Priority errors Woodo hacks CSS2 filters

Logical errors Adding “display: inline” to a float. Floats are block elements (like div). Declaring them as “float” makes them block elements automatically. Why are we telling them they are “in-line”?

Scope errors * html body{ Background-ccolr: #fff; }

Syntax errors.class{ height: 22px; /* all browsers*/ _height: 24px; /* IE6 or less */ *height: 26px; /* IE7 or less */ }

Priority errors.class{ height: 22px!important; height: 24px; }

Woodo hacks Picabu bug – zoom: 1; overflow: hidden; Flickering list elements – height: 1%; HasLayout - zoom: 1; Change rendering order

CSS2 filters.menu > ul a {width:auto;}

General rules Try to hang your attribute where it is most effective. (minimal repeats and minimal side- effects) Use context. Our main menu has only one class: menu. Prefix your class names. (We should have done it as well) Test in various browsers (IE, FF, Op, Saf/Chr)

Thank You