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.

Slides:



Advertisements
Similar presentations
Cascading Style Sheets
Advertisements

CSS-Formatting Review Cascading Style Sheets addstyle to your HTML web pages.
Intro To Cascading Style Sheets By Mario Yannakakis.
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
Cascading Style Sheets: Basics I450 Technology Seminar Copyright 2003, Matt Hottell.
Cascading Style Sheets (CSS) “Styles” for short. Pg. 418.
CSS Digital Media: Communication and design 2007.
Today CSS HTML A project.
CHAPTER 7 STYLING CONTENT WITH CASCADING STYLE SHEETS.
Introducing CSS CIS 133 mashup Javascript, jQuery and XML 1.
Lecture 5 Use Cases and Style Sheets
Very quick intro HTML and CSS. Sample html A Web Title.
CHAPTER 8 ADVANCED CSS. LEARNING OBJECTIVES Assign formatting styles to a CSS class definition Use a tag’s class attribute to apply the styles defined.
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.
Web Development & Design Foundations with XHTML Chapter 7 Key Concepts.
Cascading Style Sheets By: Valerie Kuna. What are Cascading Style Sheets? Cascading Style Sheets (CSS) are a standard for specifying the presentation.
Cascading Style Sheets CSS. What is it? Another file format ! its not like html Describes the looks of “selectors” in a.css file (example.css) in the.
© 2004, Robert K. Moniot Chapter 6 CSS : Cascading Style Sheets.
1 Web Developer & Design Foundations with XHTML Chapter 9 Key Concepts.
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.
Cascading Style Sheets Based on Castro, HTML for the WWW, 6 th edition Ron Gerton, Fall 2007.
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.
CSW131 Steven Battilana 1 CSW 131 – Chapter 5 (More) Advanced CSS Prepared by Prof. B. for use with Teach Yourself Visually Web Design by Ron Huddleston,
© 2010, Robert K. Moniot Chapter 5 CSS : Cascading Style Sheets 1.
Cascading Style Sheet (CSS) Instructor: Dr. Fang (Daisy) Tang
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.
Cascading Style Sheets Orientation Learning Web Design: Chapter 11.
Tutorial #3 Cascading Style Sheets. Tutorial #2 Review - Anchors Links to Site DMACC Internal Links Go to Top Mail To me Local.
XP Tutorial 7New Perspectives on HTML and XHTML, Comprehensive 1 Working with Cascading Style Sheets Tutorial 7.
ECA225 Applied Interactive Programming Cascading Style Sheets, pt 1 ECA 225 Applied Online Programming.
Cascading Style Sheets CSS.  Standard defined by the W3C  CSS1 (released 1996) 50 properties  CSS2 (released 1998) 150 properties (positioning)  CSS3.
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,
CSS: Cascading Style Sheets Part II. Style Syntax.
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.
Cascading Style Sheets
HTML WITH CSS.
Web Development & Design Foundations with XHTML
CS3220 Web and Internet Programming CSS Basics
Formatting Text with CSS
Cascading Style Sheets
CSS: Cascading Style Sheets
Chapter 6 Cascading Style Sheets™ (CSS)
Cascading Style Sheets
Using Cascading Style Sheets Module B: CSS Structure
Cascading Style Sheets
IS333: MULTI-TIER APPLICATION DEVELOPMENT
Introduction to Web programming
CSS – Properties & Values
The Internet 10/13/11 The Box Model
Cascading Style Sheets
CSS Style Sheets: Intro
Cascading Style Sheets Color and Font Properties
Cascading Style Sheets
Cascading Style Sheets
CS3220 Web and Internet Programming CSS Basics
CS3220 Web and Internet Programming CSS Basics
Cascading Style Sheets
Cascading Style Sheets
Cascading Style Sheets
Session IV Chapter 15 - How Work with Fonts and Printing
Cascading Style Sheets
CS332A Advanced HTML Programming
Cascading Style Sheets™ (CSS)
Presentation transcript:

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 by making a single change to the rule—without requiring changes to all the pages in the site. A separate file can be defined for the rules. Standards-compliant

How to add CSS to HTML Tags You can use the tags to list a series of rules embedded in the header The styles are used to define specific sets of characteristics for HTML tags, classes, or IDs. Classes can be added to tags by using a class attribute :

Block vs. inline tags Block-level tags such as add a line break before and after the tag. – is block-level Inline tags such as do not. – is inline Don't confuse these with inline styles, e.g.: –

Styles inline: in the Tag CSS rules consist of selector {property1:value1; property2:value2;}. (For inline styles, the rules are enclosed in quotes.) Hello World

Style Sheets Defined in Surround with … tags. For HTML include comments: /* CSS rules go here */ Selectors can be HTML tags (h1), classes (.fred), ids (#fred), pseudo-classes (.fred:hover), pseudo-elements (.fred:first-letter) attributes (img[alt]), others. Ids can only be used once per HTML page.

Sample Style sheet in h1 {font-family: Georgia, ‘Times New Roman’, Times, serif; color: red; text-align: center;} h2 {font-weight: bold; color: orange;}.dropcap {font: 100%/200% serif; color: blue; margin-top: 1em; position: relative; left: 10px; top: 10px;} p {color: red; font-family: courier, monospace; padding: 1em;} #fred {border: 2px solid #cf4;} (Use vertical format as in Zeldman Chap. 9)

Using the Style Sheet When you use the H1, H2 or P tags the styles defined in the style sheet are applied. To use the.dropcap class you may –Either add the class to the tag.dropcap and add the class name –Define a set of div or span tags and add the attribute class=" "

External Linking You may also define a style sheet as a text file which includes the defined set of rules. The file contains only the selectors and the property: value pairs. The file is the same as the rules in the element without the tags.

The external file is then connected to the HTML page by using the tag Note /> for XHTML; for HTML5 just The xxx.css is the name of the file path that contains the list of rules. You should end the file with the extension css to be sure you know what the file contains. You may also import one CSS file into url(other.css).

Order of style rules (cascade) The last definition is the one which is applied to the tag. So if a css file is attached with a definition for p tags and there is an inline definition for the p tag after the reference to the embedded or external file, the inline definition will apply. In general inline>embedded>external. If the user has a set of defined browser characteristics which conflict with the css, the user characteristics will override the css definition.

Defining Classes You can define a set of specifics which may be applied to a series of tags. The definition is prefaced with a.classname. You reference the class name in the HTML tag by using the attribute class="classname"

Defining IDs In the style sheets, you may also define an ID, which acts like a class except there can be only one per page. Note in HTML5 this would be replaced by The ID always starts with a pound/hash sign (#): #idname To apply the ID tag to the HTML tag, you add the attribute See Zeldman chapter 8 for reasons to use id.

Example #area1 {color: red}

Multiple Tags with the same Style (grouped selectors) Separate the list of tags by commas and the place the set of style rules in parentheses for the entire group. h1, h2, h3 {color: blue;}

Descendant (contextual) Selectors You can pass a style definition down a list of related selectors. E.g. #copy li p {font-size: 1.5em;} (Read this right to left. All p that are descendants of li that are descendants of an element with id="copy" get this rule.) The selectors are separated by a space. The first selector in the list is the parent, the others are descendants. Changes to the first selector will be inherited by the next selector.

CSS 2.1 selectors (IE 7+, MOSe) Child selectors li>p {color: red;} (all p that are children of an li) Adjacent siblings li+li {color: #234;} (all li that are adjacent siblings of li) Universal (wild card) selector * {color:red;} #copy * i{color:#123456;} Attribute selectors a[href="page2.html"] {color: black;} OR div[align] {font-family: serif;}

Pseudo-classes Most common are :link, :visited, :hover, :active. E.g. a:hover {text-decoration:underline;} Also (2.1) :first-child, :focus, :blur, :lang() With IE7+ (and always with MOSe) can use the "whatever:hover" e.g. li:hover {text-decoration:underline;}

Pseudo-elements Not often used, but Gillenwater uses :before and :after for "generated content." :first-letter, :first-line, :before, :after

Some other options !important tag Adding the !important to the style rule will override any other rule. Media queries: in or media="screen" media="print" media="handheld" media="all" etc. media="print" — used for a print page style sheet. (Resume project) media="screen" – used for a browser display [but omit if only sending to a browser]

Competing rules The cascade as described earlier Inheritance (rules passed to descendants) Specificity (id=100, class=10, tag=1) (sort of) Lower rule in a style sheet or declaration wins h1 {color:blue;} h1 {color:red;} so h1 will be red

Comments CSS comments look like JavaScript: /* Multiple lines of comment go here and can continue until the closing mark */ p {color:red;} Conditional comments are best way to serve IE rules. E.g. OR... Or... comments

Defaults for font-family serif—small ornamentation at the end of the letters sans-serif – not serif monospace—all letters occupy same amount of space cursive—resembles handwriting fantasy—decorative fonts that are not the same as the other styles

Setting Font font-family: font stack (give the one you prefer first); multiple word families need quotes font-family: "courier new", courier, is used to define the name and location of a font to be downloaded to the user’s nametodownload; src:url(filelocation);} Best idea—use browser-safe screen fonts (Georgia, Verdana)

Other font properties font-size: –Absolute (pt, in cm, mm) –Relative (sort of) (px, em, %) –Absolute expression xx-small, x-small, small, medium, large, x-large, xx-large (smaller, larger are relative) font-style: – italic

font-weight: – normal, bold, lighter. –Or use a value of 100 to 900 in increments of 100. Creating smallcaps – font-variant small-caps normal Shorthand: font options separated by spaces after the font: property. E.g. h1 {font: bold italic small-caps 12px/18px verdana, serif;} At a minimum, need font-family, font-size. E.g. h1 {font: 12px georgia, "times new roman", times, serif;