1 Getting Started with CSS. 2 CSS Cascading Style Sheets XHTML provides structure for our documents (web pages) CSS provides Style or Presentation for.

Slides:



Advertisements
Similar presentations
HIGH LEVEL OVERVIEW: CSS CSS SYNTAX CONSISTS OF A SET OF RULES THAT HAVE 3 PARTS: A SELECTOR, A PROPERTY, AND A VALUE. IT’S NOT NECESSARY TO REMEMBER THIS.
Advertisements

Intro To Cascading Style Sheets By Mario Yannakakis.
Cascading Style Sheets (CSS). Cascading Style Sheets With the explosive growth of the World Wide Web, designers and programmers quickly explored and reached.
CSS Cascading Style Sheets. Objectives Using Inline Styles Working with Selectors Using Embedded Styles Using an External Style Sheet Applying a Style.
Cascading Style Sheets
CSS The basics { }. CSS Cascading Style Sheets - language used to – describe html appearance & formatting Style Sheet - file that describes – how html.
Cascading Style Sheets
HTML Overview - Cascading Style Sheets (CSS). Before We Begin Make a copy of one of your HTML file you have previously created Make a copy of one of your.
CHAPTER 7 STYLING CONTENT WITH CASCADING STYLE SHEETS.
Chapter 3 – Designing your web pages Dr. Stephanos Mavromoustakos.
© 2004, Robert K. Moniot Chapter 6 CSS : Cascading Style Sheets.
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.
Chapter 8 Creating Style Sheets.
Cascading Style Sheets. Slide 2 Lecture Overview Overview of Cascading Style Sheets (CSS) Ways to declare a CSS CSS formatting capabilities New features.
HCI 201 Week 6 Client Side Image Maps Introduction to CSS.
Using Cascading Style Sheets CSS Structure. Goals Understand how contextual, class and ID selectors work Understand how contextual, class and ID selectors.
More HTML Chapter 4. 2 Nesting Tags How do you write the following in HTML? The wrong way: This is really, REALLY fun ! Tags must be correctly nested.
4.01 Cascading Style Sheets
Computing Concepts: CSS. Aims  To understand the uses of css  To understand the different types of css  To be able to create a css file  To be able.
Tutorial 3: Adding and Formatting Text. 2 Objectives Session 3.1 Type text into a page Copy text from a document and paste it into a page Check for spelling.
 Missing (or duplicate) semicolons can make the browser completely ignore the style rule.  You may add extra spaces between the properties/values to.
XHTML and CSS Introduction to XHTML and CSS Bharti Patel 1 phones off (please)
Principles of Web Design 6 th Edition Chapter 4 – Cascading Style Sheets.
Chapter 11 Cascading Style Sheets: Part I The Web Warrior Guide to Web Design Technologies.
Cascading style sheets (CSS)
Cascading Style Sheets (CSS) 1.  What is CSS?  Why CSS?  How to write a CSS? 2.
Tutorial #3 Cascading Style Sheets. Review: Last Class Image sizing Pathnames Project Default Path Relative Path Absolute Path Blackboard Homework Submission.
INTRODUCTION TO HTML5 CSS Styles. Understanding Style Sheets  HTML5 enables you to define many different types of content on a web page, including headings,
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.
1 What is CSS?  CSS stands for Cascading Style Sheets  Styles define how to display HTML elements  Styles are normally stored in Style Sheets  Styles.
Introduction To CSS.. HTML Review What is HTML used for? Give some examples of formatting tags in HTML? HTML is the most widely used language on the Web.
 This presentation introduces the following: › 3 types of CSS › CSS syntax › CSS comments › CSS and color › The box model.
Just A Few More Fun Objectives 1 Having Some Fun With Java Script 2 Using Style Sheets.
Cascading Style Sheets Orientation Learning Web Design: Chapter 11.
INTRODUCTION TO CSS. OBJECTIVES: D EFINE WHAT CSS IS. K NOW THE HISTORY OF CSS. K NOW THE REASON WHY CSS IS USED. CSS SYNTAX. CSS ID AND CLASS.
CSS CSS is short for C ascading S tyle S heets. It is a new web page layout method that has been added to HTML to give web developers more control over.
Tutorial #3 Cascading Style Sheets. Tutorial #2 Review - Anchors Links to Site DMACC Internal Links Go to Top Mail To me Local.
WRT235: Writing in Electronic Environments Basic CSS.
Introduction to CSS. What is CSS?  Cascading Style Sheets  Used for styling HTML  Also important in javascript and jquery for selectors  External.
IS1825: Developing Multimedia Applications for Business Lecture 1: Introduction to CSS Rob Gleasure
CS134 Web Design & Development Cascading Style Sheets (CSS) Mehmud Abliz.
Css. Definition Cascading style sheet (CSS)  It is a simple mechanism for adding style (e.g. fonts, colors, spacing) to Web documents.
INT222 - Internet Fundamentals Shi, Yue (Sunny) Office: T2095 SENECA COLLEGE.
Cascading Style Sheets CSS.  Standard defined by the W3C  CSS1 (released 1996) 50 properties  CSS2 (released 1998) 150 properties (positioning)  CSS3.
LEARN THE QUICK AND EASY WAY! VISUAL QUICKSTART GUIDE HTML and CSS 8th Edition Chapter 8: Working with Style Sheets.
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.
XHTML Formatting font with a style declaration. Formatting Font HTML uses the font tag to change size and family of font But… the font tag is being deprecated.
Style Sheets. Coding Style Sheets  Style sheets use RULES to create the style  A selector (a tag or user-defined style name)  and then declarations.
CSS Cascading Style Sheets *referenced from
Department of Computer Science, Florida State University CGS 3066: Web Programming and Design Spring
NASRULLAHIBA.  It is time to take your web designing skills to the next level with Cascading Style Sheets (CSS). They are a way to control the look and.
Blended HTML and CSS Fundamentals 3 rd EDITION Tutorial 3 Introducing Cascading Style Sheets.
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…
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.
The Internet 10/11/11 Fonts and Colors
4.01 Cascading Style Sheets
>> Introduction to CSS
IS 360 Declaring CSS Styles
Using Cascading Style Sheets Module B: CSS Structure
IS333: MULTI-TIER APPLICATION DEVELOPMENT
Software Engineering for Internet Applications
CS134 Web Design & Development
What are Cascading Stylesheets (CSS)?
The Internet 10/6/11 Cascading Style Sheets
Tutorial 3 Working with Cascading Style Sheets
Web Design & Development
4.01 Cascading Style Sheets
External Style Sheets.
Presentation transcript:

1 Getting Started with CSS

2 CSS Cascading Style Sheets XHTML provides structure for our documents (web pages) CSS provides Style or Presentation for our documents Important to learn the language of CSS CSS is better suited than XHTML for specifying style information CSS is much better for handling styles for multiple pages

3 CSS rules, selectors, properties and values CSS contains simple statements called rules Each rule provides the style for a selection of XHTML elements A typical rule consists of a selector along with one or more properties and values The selector specifies which elements the rule applies to

4 The language of CSS CSS has its own language or syntax Each statement in CSS consists of the following: Location, Property, Style

5 CSS Location, Property, Style 1.Location (XHTML element) 2.Property (like background color) 3.Style(like color) CSS format: element { property: style; }

6 p Rule CSS format:element { property: style; } CSS example: p { background-color: red; }

7 CSS Location, Property, Style Relating this concept to an example of a house Location = bedroom Property = carpet Style = red Using CSS syntax it would look something like: bedroom { carpet: red; }

8 CSS declaration known as a Rule 1.Select element you want to style 2.Specify the property you want to style (property of the element) 1.Set the style (or color) for the property element { property: style; }

9 Anatomy of a CSS Rule CSS Rule:element { property: style; } p rule example:p { background-color: red; } Or write like…p { background-color: red; } **(linebreaks and spacing used to improve readability)

10 Adding more style to a Rule Elements have many properties which can be defined You can add as many properties and values as you like into each rule The following has a background color of red to the element and adds a 1 pixel thick solid gray border to that element p { background-color: red; border: 1px solid gray; }

11 Inserting a element into our XHTML Adding a internal CSS using the element to an XHTML page

12 Inserting a element into our XHTML Add opening & closing style tags within the element Can go just before the closing element CSS rules will go between these style elements Adams Document

13 Inserting a element example Adams Document p { color: maroon; } welcome to my webpage

14 Adding style using CSS color property Specifying the font color for paragraphs Applies style to only the element The p selector selects all the paragraphs in our XHTML document and changes font color to maroon The property to change the font color is named color p { color: maroon; }

15 Adding style using CSS color property Adams Document p { color: maroon; } Welcome, the text in all paragraphs will be colored maroon

16 Writing combined rules for more than one element Putting commas between the selectors h1, h2 allows us to combine styling to our and headings Combined rule p { color: maroon; } h1, h2 { font-family: sans-serif; color: gray; }

17 Adding an underline to both h1, h2 headings p { color: maroon; } h1, h2 { font-family: sans-serif; color: gray; border-bottom: 1px solid black; }

18 Adding a second rule for only the h1 headings Additional (more specific) rules can be added to elements p { color: maroon; } h1, h2 { font-family: sans-serif; color: gray; } h1 { border-bottom: 1px solid black; }

19 Cascading Styles Can have as many rules as you want for an element Each rule adds to the style information of the rule before it Any style specific to an element you would write another rule CSS allows you to specify all kinds of selectors that determine which elements your styles are applied to

20 Using an external Style Sheet You can use an external Style Sheet (instead of an internal Style Sheet) External Style Sheet is linked to within the xhtml page External CSS is a text document saved with the.css extension Remember a webpage is also a text document saved with the.html extension External CSS enable you to easily update an entire site vs having to update the Style Sheet on each page

21 Creating an external Style Sheet You can copy CSS …simply highlight, copy and paste into a blank plain text document p { color: maroon; } h1, h2 { font-family: sans-serif; color: gray; } h1 { border-bottom: 1px solid black; }

22 Creating an external Style Sheet Save Style Sheet in the same directory (folder) as your webpage Save with the.css file extension anyname.css Delete any style elements back in the webpage, int CSS in head

23 Linking an external Style Sheet Add element within the element Can go just before the closing element Links to our external Style Sheet Adams Document

24 link element used to link to external info type refers to the type of info, “text/css” (CSS Style Sheet) rel attribute specifies the relationship between the XHTML file and the file (CSS Style Sheet) we are linking to href links to where file (CSS Style Sheet) is located is an empty element, must end with />

25 href absolute Relative or absolute path can be used within href Absolute path would provide the complete path in order to find file (

26 href relative Relative means relative to where your file is currently located in the directory or folder structure In the relative example below, name.css must reside within the same folder/directory as the webpage the code resides in

27 href=“../name.css” In the example below, name.css must reside in the directory or folder directly above the current folder or directory

28 Serif vs sans serif font style Sans serif have the clean look Sans serif example Serif have “serifs” or tails and are considered more difficult to read, Serif is the default font used if we don’t specify any in our Style Sheet Serif example

29 Changing our element to use a sans-serif font p { font-family: sans-serif; color: maroon; } h1, h2 { font-family: sans-serif; color: gray; } h1 { border-bottom: 1px solid black; }

30 Inheritance, parent and child elements Adding the font-family property to the “p” selector will affect any elements inside this element Additional elements that are located within elements will inherit their style For example, if a element has a font-family property, than any elements inside the element will inherit the same style Parent and child elements, child inherits style from parent

31 Styling a element affects whole document Add a body selector (see below) Modify the p,h1,h2 selectors, remove font-family from p and h1,h2, no longer needed body { font-family: sans-serif; } p { color: maroon; } h1, h2 { color: gray; } h1 { border-bottom: 1px solid black; }

32 Overriding an inheritance Add a new rule for element, rule overrides its parent rule body { font-family: sans-serif; } p { color: maroon; } h1, h2 { color: gray; } h1 { border-bottom: 1px solid black; } em { font-family: serif; }

33 Inheritance You can override an inherited value by adding a new rule around the desired (child) element New rule is considered a specific rule for that element only (and any of its child elements) The most specific rule will always override an inherited value

34 Inheritance Determining which properties are inherited and which are not can best be determined by using a CSS reference

35 Inheritance Styles that affect the way the text looks, such as font color (the color property), the font-family, and other font related properties such as font size, font-weight (for bold text), and font-style (for italics) are inherited

36 Inheritance Properties such as border are not inherited You can always override a property that is being inherited Use a specific selector to override a property from a parent

37 Adding comments can help explain CSS logic Add comments to your CSS file using /* addcomments */ Comments can span multiple lines, for example /* this rule selects all paragraphs and colors them gray/*

38 Adding classes Can define a class of elements and then apply styles to any element that belongs to that class A class is simply a grouping or belonging to a group Sort of like belonging to a club, there are members who are part of the club Using a class would allow you to create a class for each element individually

39 class=“name_of_class” Mocha Welcome to my paragraph about my mocha type drinks Espresso Welcome to my paragraph about my expresso type drinks Vanilla Welcome to my paragraph about my expresso type drinks

40 Creating a selector for the class To specify a particular class you would write out the selector in the following format p.mocha { color: olive; } This selector only selects paragraphs belonging to the mocha class p represents the selector mocha represents the class name olive represents the style/value

41 Creating a p selector for the mocha class Enables the selecting of elements that belong to only the mocha class Add the class attribute to any element which you want the desired rule/style applied to Adding the p.mocha class selector to the.css body { font-family: sans-serif; } p { color: maroon; } h1, h2 { color: gray; } h1 { border-bottom: 1px solid black; } em { font-family: serif; } p.mocha { color: olive; }

42 Taking classes further If you wanted to apply the same styling to blockquotes You could add a second rule to the mocha class blockqoute.mocha, p.mocha { color: olive; }

43 Adding a class to an element Within the XHTML you would add the following to the desired blockquote Text goes here

44 Specifying several elements to class Modify the p.mocha class selector in the.css body { font-family: sans-serif; } p { color: maroon; } h1, h2 { color: gray; } h1 { border-bottom: 1px solid black; } em { font-family: serif; } blockqoute.mocha, p.mocha { color: olive; }

45 Adding class to multiple elements If you wanted to add class to multiple elements you could instead write as a class and apply to all desired elements.mocha { color: olive; } Rule will apply to all members assigned to this class Text goes here

46 Adding a class Leaving out all the element names and instead writing out by starting with a period followed by class name will apply rule to all elements with that class body { font-family: sans-serif; } h1 { border-bottom: 1px solid black; } em { font-family: serif; }.mocha { color: olive; }

47 Adams Document Mocha Mocha is the most popular customer item. Mocha is part of the chocolate family

48 Elements can be in more than one class If you want to specify a element in three classes you would write out the three classes with space in-between and no comma Use multiple classes when you want an element to have styles you’ve defined in different classes Not recommended, but possible

49 Elements can be in more than one class If an element belongs to multiple classes and all of which define the same property like the element, then the style which gets applied is ?…..since there is a conflict, the most specific rule will win or if all the same than the rule listed last in CSS file would rule

50 Determining how styles are applied Do any selectors select your element …if so then that’s your value If there are no selectors then you rely on inheritance …look at the elements parents until you find the property defined, if you do then that’s the value If there is no selectors and no inheritance …then the default value defined by the browser will be used

51 Determining how styles are applied Again, if multiple selectors select an element..then there is a conflict, the most specific rule will win or if all the same than the rule listed last in CSS file would rule

52 Always validate your CSS Style Sheet Always make sure to validate your CSS Style Sheet to check for conformance There will be no obvious message that it validated, instead it will notify you of obvious errors or make suggestions It does list out the valid CSS information

53 Review of the benefits to always validating Web pages will work and appear as intended by designer Will be better supported on new devices being used to view web pages Easy to make errors when writing code within a text editor, important to verify syntax -end