Presentation (5): Cascading Style Sheets (CSS) ITNET1.

Slides:



Advertisements
Similar presentations
1 Cascading Style Sheets™ (CSS) Outline 5.1 Introduction 5.2 Inline Styles 5.3 Embedded Style Sheets 5.4 Conflicting Styles 5.5 Linking External Style.
Advertisements

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.
 2002 Prentice Hall, Inc. All rights reserved. Chapter 4 – Cascading Style Sheets (CSS) Objectives –To take control of the appearance of a Web site by.
1 Dynamic HTML: Cascading Style Sheets™ (CSS). 2 Introduction Cascading Style Sheets (CSS) –Specify the style of your page elements –Spacing, margins,
1 XHTML Cascading Style Sheets™ (CSS). 2 Inline.html 1 2
Background: HTML and CSS Chapters 1-4 of Deitel XML text.
 2003 Prentice Hall, Inc. All rights reserved. Chapter 6 - Cascading Style Sheets™ (CSS) Outline 6.1 Introduction 6.2 Inline Styles 6.3 Embedded Style.
 2002 Prentice Hall, Inc. All rights reserved. Chapter 4 – Cascading Style Sheets (CSS) Outline 4.1Introduction 4.2Inline Styles 4.3Creating Style Sheets.
Outline IS400: Development of Business Applications on the Internet Fall 2004 Instructor: Dr. Boris Jukic CSS: Cascading Style Sheets.
1 Dynamic HTML -Cascading Style Sheets™ (CSS) Outline 6.1 Introduction 6.2 Inline Styles 6.3 Embedded Style Sheets 6.4 Conflicting Styles 6.5 Linking External.
14-Jul-15 CSS Applications to XML. 2 A different emphasis CSS is the same for XML as it is for HTML, but-- HTML already does a pretty good job of layout.
Working with Cascading Style Sheets. 2 Objectives Introducing Cascading Style Sheets Using Inline Styles Using Embedded Styles Using an External Style.
3.1 Cascading Style Sheets. Motto Fashions fade, style is eternal. —Yves Saint Laurent.
Selectors thru Borders. CSS – Cascading Style Sheets – is a way to style HTML HTML is the content base of a web page CSS provides the presentation qualities.
CSS1-1 Cascading Style Sheets (CSS) Xingquan (Hill) Zhu
TECH2018 Multimedia and the Internet More about CSS and Page Layouts.
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 CS3505. What are CSS? Method for adding style attributes consistently to HML tags Cascading because styles are applied in order.
XP Tutorial 7New Perspectives on Creating Web Pages with HTML, XHTML, and XML 1 Working with Cascading Style Sheets Creating a Style for Online Scrapbooks.
 2000 Deitel & Associates, Inc. All rights reserved. Chapter 14 – Dynamic HTML: Cascading Style Sheets (CSS) Outline 14.1Introduction 14.2Inline Styles.
HTML - Quiz #2 Attendance CODE:
Cascading style sheets (CSS)
Dreamweaver -- CSS. Dreamweaver -- MX New icons are added in MX Most of the features commonly used in web design, and are same as FrontPage. New feature.
Chapter 7 Web Typography Principles of Web Design, 4 th Edition.
Today’s objectives  Complete web page  Using xhtml & CSS  Adding CSS to documents Embed url(File);  CSS.
Tutorial 6 By Sam INE 1020 Introduction to Internet Engineering 1 DHTML & CSS Tutorial 6.
CSS in XHTML continued Please use speaker notes for additional information!
 2001 Prentice Hall, Inc. All rights reserved. 1 Chapter 6 - Cascading Style Sheets™ (CSS) Outline 6.1 Introduction 6.2 Inline Styles 6.3 Embedded Style.
Just A Few More Fun Objectives 1 Having Some Fun With Java Script 2 Using Style Sheets.
CSS. HTML: Looking Back HTML dictates order, structure, and function Does very little to specify layout or visual rendering.
COP 3813 Intro to Internet Computing Prof. Roy Levow Lecture 3.
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.
 2001 Prentice Hall, Inc. All rights reserved. 1 Chapter 6 - Cascading Style Sheets™ (CSS) Outline 6.1 Introduction 6.2 Inline Styles 6.3 Embedded Style.
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.
 2008 Pearson Education, Inc. All rights reserved Cascading Style Sheets™ (CSS)
 2008 Pearson Education, Inc. All rights reserved Cascading Style Sheets™ (CSS)
1 Introduction to XHTML. 2 Main.html Program Output 1 2
 2004 Prentice Hall, Inc. All rights reserved. Chapter 6 - Cascading Style Sheets™ (CSS) Outline 6.1 Introduction 6.2 Inline Styles 6.3 Embedded Style.
 Cascading Style Sheets (CSS) ◦ Used to specify the presentation of elements separately from the structure of the document.  Inline style ◦ declare.
CHAPTER 2 CSS (Cascading Style Sheet). Topics Introduction Inline Styles Embedded Style Sheets Conflicting Styles Linking External Style Sheets Positioning.
 2008 Pearson Education, Inc. All rights reserved Cascading Style Sheets™ (CSS)
CSS with XHTML Please use speaker notes for additional information!
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.
Presentation (5): Cascading Style Sheets (CSS) Fundamentals of Web-Centric Development.
XP Review 2 New Perspectives on JavaScript, Comprehensive1 Introducing Cascading Style Sheets Formatting Web Pages with CSS.
 2008 Pearson Education, Inc. All rights reserved Cascading Style Sheets™ (CSS)
1 Introduction to Web Application Introduction to Cascading Style Sheet.
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:
3.2 Cascading Style Sheets. 2 Positioning Elements Normally, elements are laid out on the page in the order that they are defined in the XHTML document.
5 th ed: Chapter 4 4 th ed: Chapter 5 SY306 Web and Databases for Cyber Operations Slide Set #4: CSS.
Web Technologies Beginning Cascading Style Sheets (CSS) 1Copyright © Texas Education Agency, All rights reserved.
Cascading Style Sheets (CSS)
 2008 Pearson Education, Inc. All rights reserved Cascading Style Sheets™ (CSS)
 2008 Pearson Education, Inc. All rights reserved Cascading Style Sheets™ (CSS)
Internet & World Wide Web How to Program, 5/e Copyright © Pearson, Inc All Rights Reserved.
Internet & World Wide Web How to Program, 5/e Copyright © Pearson, Inc All Rights Reserved.
HTML & CSS Contents: the different ways we can use to apply CSS to The HTML documents CSS Colors and Background CSS Fonts CSS Text CSS box model: padding,
 2008 Pearson Education, Inc. All rights reserved Cascading Style Sheets™ (CSS)
Internet & World Wide Web How to Program, 5/e 1. 2.
Chapter 6 - Cascading Style Sheets™ (CSS)
Cascading Style Sheets™ (CSS)
CSS: Cascading Style Sheets
Chapter 6 Cascading Style Sheets™ (CSS)
Chapter 26 - Bonus: Cascading Style Sheets (CSS)
Cascading Style Sheets
Chapter 6 - Cascading Style Sheets™ (CSS)
Second CSS Lecture Applications to XML
Cascading Style Sheets™ (CSS)
Cascading Style Sheets™ (CSS)
Presentation transcript:

Presentation (5): Cascading Style Sheets (CSS) ITNET1

Ingeniørhøjskolen i Århus Slide 2 af 38 Topics in this presentation CSS – Cascading Style Sheets –Purpose of CSS –CSS Types and versions –Practical use of CSS –XSL vs CSS –CSS as In line Internally Externally –CSS Positioning I must apologize for the poor english in some slides. I did not translate these !

Ingeniørhøjskolen i Århus Slide 3 af 38 Purpose of CSS CSS is a simple way to set document style information (primarily fonts, colors and positioning) Technology to separate content and presentation … and practical: to ease change in design CSS is a W3C recommendation: –

Ingeniørhøjskolen i Århus Slide 4 af 38 Applied CSS Real-world HTML is still the main source to presentation formatting, and CSS is only used with obviously advantages to fonts and colors –But of course some designers use it more than others –May easily change in the future –Visual Studio ASP.NET visual designer, CSS Positioning is used extensively

Ingeniørhøjskolen i Århus Slide 5 af 38 CSS Versions Cascading Style Sheets, level 1 (CSS1) became W3C Recommendation in December The CSS language is given inCascading Style Sheets, level 1 (CSS1)W3C Recommendation – CSS2, W3C Recommendation may 1998, extends CSS1 and adds support for media specific style sheets (ex.. for printers and speech or sound devices), features downloading new fonts, element positioning and tables. (2009: CSS 2.1 is currently state of the art)CSS2 – CSS Mobile Profile became W3C Candidate Recommendation specification in October 2001CSS Mobile Profile W3C Candidate Recommendation – CSS3 is under construction (from 2005) follow this work at – ATTENTION PLEASE. The specifications are OPEN, so the browsers may use them to the extent they wish. Always test the browsers for level of support. ATTENTION PLEASE. The specifications are OPEN, so the browsers may use them to the extent they wish. Always test the browsers for level of support.

Ingeniørhøjskolen i Århus Slide 6 af 38 XSL vs. CSS W3C and the XSL family: –The Extensible Stylesheet Language –Using XML to format documents –… more simple language than the sometime cryptically CSS language – perhaps… –Opens the way of a automatically formatting procedure: XSL Transformations (XSLT) which is a language for transforming XML documents into other XML documents –May also be done by server side scripting

Ingeniørhøjskolen i Århus Slide 7 af 38 XSL vs. CSS Why two ways of formatting techniques? Mostly out of practically reasons –The results of a StyleSheets are completely dependent on the different browsers interpretation – and implementation –The existing experiences that HTML developers holds is enormous and will be used for many years to come (Habits are the most difficult thing to change)

Ingeniørhøjskolen i Århus Slide 8 af 38 XSL vs. CSS II CSSXSL Can be used with HTML? yesno Can be used with XML? yes Transformation language? noyes SyntaxCSSXML

Ingeniørhøjskolen i Århus Slide 9 af 38 Will XSL substitute CSS? Why does W3C recommend two different style languages? Which one should you use? Basically, the rule can be summarized very succinctly: –Use CSS when you can, use XSL when you must. eventually read in cursoryhttp://

Ingeniørhøjskolen i Århus Slide 10 af 38 3 ways using CSS with HTML External Stylesheet: The composition way. Style information is put into its own separate file/document Inline style-(sheet): Formatting put into the HTML tag Internal Stylesheet: div {text-align: right} Embedded in the beginning of a HTML document (typically)

Ingeniørhøjskolen i Århus Slide 11 af 38 CSS Syntaks div {color: red; padding-left: 3cm} Selector (tag) Declaration PropertyValue

Ingeniørhøjskolen i Århus Slide 12 af 38 Inline styles Style as in line code put into a tag Use it carefully – in special cases (SW recommendation) –Like CSS Positioning –Used extensively in Visual Studio What problems do you see with inline?

Ingeniørhøjskolen i Århus Slide 13 af 38 Inline.html 1 2 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" 3 " Inline Styles This text does not have any style applied to it This text has the 21 font-size style applied to it, making it 20pt This text has the font-size and 26 color styles applied to it, making it 27 20pt. and blue The style attribute specifies the style for an element. Some style properties are font-size and color.

Ingeniørhøjskolen i Århus Slide 14 af 38 Internal stylesheets Applies to one whole HTML document and thereby all of its tags. Should be avoided.. But is of course allowed. –(Embedded Web server with limited resources)

Ingeniørhøjskolen i Århus Slide 15 af 38 Declared.html 1 2 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" 3 " Style Sheets em { background-color: #8000ff; 16 color: white } h1 { font-family: arial, sans-serif } p { font-size: 14pt } special { color: blue } Styles placed in the head apply to all elements in the document. A style class named special is created. Style classes inherit the style properties of the style sheet in addition to their own. A class can be used for special formatting needs More style properties include font type (font-family) and background color (background-color). Use the style element to create an embedded CSS.

Ingeniørhøjskolen i Århus Slide 16 af 38 Declared.html Deitel & Associates, Inc Deitel & Associates, Inc. is an internationally 33 recognized corporate training and publishing organization 34 specializing in programming languages, Internet/World 35 Wide Web technology and object technology education. 36 Deitel & Associates, Inc. is a member of the World Wide 37 Web Consortium. The company provides courses on Java, 38 C++, Visual Basic, C, Internet and World Wide Web 39 programming, and Object Technology Clients 42 The company's clients include many 43 Fortune 1000 companies, government agencies, 44 branches of the military and business organizations. 45 Through its publishing partnership with Prentice Hall, 46 Deitel & Associates, Inc. publishes leading-edge 47 programming textbooks, professional books, interactive 48 CD-ROM-based multimedia Cyber Classrooms, satellite 49 courses and World Wide Web courses The styles associated with the special class are applied to the header and paragraph elements. Notice the styles defined in the CSS are applied to all paragraphs, headers, and bolded text.

Ingeniørhøjskolen i Århus Slide 17 af 38 Advanced.html 1 2 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" 3 " More Styles a.nodec { text-decoration: none } a:hover { text-decoration: underline; 17 color: red; 18 background-color: #ccffcc } li em { color: red; 21 font-weight: bold } ul { margin-left: 75px } ul ul { text-decoration: underline; 26 margin-left: 15px } Shopping list for Monday : 34 A style class is defined specifically for a elements. The style is applied if the a element’s class attribute is set to nodec. The hover psuedoclass defined for the a element is activated dynamically when the user rolls over the a element with a mouse. The em element for li elements is defined to have bold red font. Elements of an unordered list in another nested unordered list will be underlined and have a left-hand margin of 15 pixels.

Ingeniørhøjskolen i Århus Slide 18 af 38 Advanced.html Milk 37 Bread White bread 40 Rye bread 41 Whole wheat bread Rice 45 Potatoes 46 Pizza with mushrooms Go to the Grocery store According to the CSS defined, the three elements listed under bread should be underlined and indented 15 pixels from the left margin when rendered. ul { text-decoration: underline; margin-left: 15px } The text placed between the em tags should be bolded and colored red when rendered. li em { color: red; … When the user scrolls over the text anchoring the link, the hover class will be activated and the text will change to the style defined by the hover class. a:hover { text-decoration … Until that happens – it will be the class nodec: a.nodec { text-decoration: none

Ingeniørhøjskolen i Århus Slide 19 af 38 Program Output The elements in the nested unordered list are underlined and indented 15 pixels from the left margin. By applying the hover psuedoclass to this anchor, the anchor’s background and text color changes when the use r rolls over it with the mouse.

Ingeniørhøjskolen i Århus Slide 20 af 38 External stylesheets The ”right” way to do styling! Decouples the CSS from the XHTML Styling placed in separate doc (ex. style.css) Main document links to the stylesheet Gives many main HTML document the possibility of using/linking the same stylesheet document Changes done in the CSS document propagates to all HTML document

Ingeniørhøjskolen i Århus Slide 21 af 38 Styles.css 1 /* Fig. 6.4: styles.css */ 2 /* An external stylesheet */ 3 4 a { text-decoration: none } 5 6 a:hover { text-decoration: underline; 7 color: red; 8 background-color: #ccffcc } 9 10 li em { color: red; 11 font-weight: bold; 12 background-color: #ffffff } ul { margin-left: 2cm } ul ul { text-decoration: underline; 17 margin-left:.5cm } Here is a separate stylesheet document, that may be linked to (referenced) from XHTML documents

Ingeniørhøjskolen i Århus Slide 22 af 38 External.html 1 2 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" 3 " Linking External Style Sheets 11 <link rel = "stylesheet" type = "text/css" 12 href = "styles.css" /> Shopping list for Monday : Milk 20 Bread White bread 23 Rye bread 24 Whole wheat bread Rice 28 Potatoes 29 Pizza with mushrooms The link element is used to reference an external style sheet. The rel attribute is used to define the linking relationship. The type attribute defines the MIME type.

Ingeniørhøjskolen i Århus Slide 23 af 38 External.html Program Output Go to the Grocery store The documents rendered with an external CSS should be the same as those rendered with an internal CSS.

Ingeniørhøjskolen i Århus Slide 24 af 38 W3C CSS Validation Service Like XHTML it is possible to get your CSS documents validated

Ingeniørhøjskolen i Århus Slide 25 af 38 CSS Positioning Instead of doing layout using tables Use CSS positioning Ex. when using STRICT XHTML or XML Paradigm strongly depend on standards and tool support Good for some problems Specially DHTML designers may have real use of positioning when doing interactive user interfaces –Alternative technology could be Flash, Applets, Silver

Ingeniørhøjskolen i Århus Slide 26 af 38 Positioning. html 1 2 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" 3 " Absolute Positioning <img src = "i.gif" style = "position: absolute; 16 top: 0px; left: 0px; z-index: 1" alt = 17 "First positioned image" /> 18 <p style = "position: absolute; top: 50px; left: 50px; 19 z-index: 3; font-size: 20pt;">Positioned Text 20 <img src = "circle.gif" style = "position: absolute; 21 top: 25px; left: 100px; z-index: 2" alt = 22 "Second positioned image" /> The position property of the style element allows for positioning of an element. The z-index property allows layering of multiple images.The images are layered such that images with lower z-indexes are placed under images with higher ones. The effect of the z-index property is several images layered on top of one another.

Ingeniørhøjskolen i Århus Slide 27 af 38 Positioning2.html 1 2 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" 3 " Relative Positioning p { font-size: 1.3em; 15 font-family: verdana, arial, sans-serif } span { color: red; 18 font-size:.6em; 19 height: 1em } super { position: relative; 22 top: -1ex } sub { position: relative; 25 bottom: -1ex } shiftleft { position: relative; 28 left: -1ex } shiftright { position: relative; 31 right: -1ex } Relative positioning places an element relative to a reference point on the page. For instance, when this class is applied the element will be displayed –1cm relative to the left of where it would be placed.

Ingeniørhøjskolen i Århus Slide 28 af 38 Positioning2.html Program Output The text at the end of this sentence 39 is in superscript The text at the end of this sentence 42 is in subscript The text at the end of this sentence 45 is shifted left The text at the end of this sentence 48 is shifted right The text in red has the shiftleft class applied, and is shifted left relative to where it would have initially been placed.

Ingeniørhøjskolen i Århus Slide 29 af 38 Background.html 1 2 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" 3 " Background Images body { background-image: url(logo.gif); 15 background-position: bottom right; 16 background-repeat: no-repeat; 17 background-attachment: fixed; } p { font-size: 18pt; 20 color: #aa5588; 21 text-indent: 1em; 22 font-family: arial, sans-serif; } dark { font-weight: bold; } The background-image property assigns a background to the body of the page. The background–position property assigns a location for the image on the page. If set to repeat, the background- repeat property will tile the image as the background. The value of the background- attachment property determines if the image moves as the user scrolls the page. The font format specified will be applied to all p elements.

Ingeniørhøjskolen i Århus Slide 30 af 38 Background.html P rogram Output This example uses the background-image, 33 background-position and background-attachment 34 styles to place the Deitel 35 & Associates, Inc. logo in the bottom, 36 right corner of the page. Notice how the logo 37 stays in the proper position when you resize the 38 browser window Note that no formatting needed to be set in the p element itself because it has already been defined in the CSS.

Ingeniørhøjskolen i Århus Slide 31 af 38 Width.html 1 2 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" 3 " Box Dimensions div { background-color: #ffccff; 15 margin-bottom:.5em } Here is some 23 text that goes in a box which is 24 set to stretch across twenty percent 25 of the width of the screen Here is some CENTERED text that goes in a box 29 which is set to stretch across eighty percent of 30 the width of the screen. 31 Elements placed between div tags will be set on their own line with a margin below and after it. The width and height attributes of style allow the user to indicate the percentage of the width and height of the screen the element can occupy.

Ingeniørhøjskolen i Århus Slide 32 af 38 Width.html Program Output This box is only twenty percent of 34 the width and thirty percent of the height. 35 What do we do if it overflows? Set the 36 overflow property to scroll! This will set the overflow attribute to add scroll bars for text that overflows.

Ingeniørhøjskolen i Århus Slide 33 af 38 Floating.html 1 2 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" 3 " Flowing Text Around Floating Elements div { background-color: #ffccff; 15 margin-bottom:.5em; 16 font-size: 1.5em; 17 width: 50% } p { text-align: justify; } Deitel & Associates, Inc <div style = "float: right; margin:.5em; 31 text-align: right"> 32 Corporate Training and Publishing 33 The margin property specifies the distance between the edge of the element and any other element on the page. The float property allows you to move an element to one side of the screen such that other content in the document then flows around the floated element.

Ingeniørhøjskolen i Århus Slide 34 af 38 Floating.htm 34 Deitel & Associates, Inc. is an internationally 35 recognized corporate training and publishing organization 36 specializing in programming languages, Internet/World 37 Wide Web technology and object technology education. 38 Deitel & Associates, Inc. is a member of the World Wide 39 Web Consortium. The company provides courses on Java, 40 C++, Visual Basic, C, Internet and World Wide Web 41 programming, and Object Technology <div style = "float: right; padding:.5em; 44 text-align: right"> 45 Leading-edge Programming Textbooks The company's clients include many Fortune companies, government agencies, branches of the military 49 and business organizations. Through its publishing 50 partnership with Prentice Hall, Deitel & Associates, 51 Inc. publishes leading-edge programming textbooks, 52 professional books, interactive CD-ROM-based multimedia 53 Cyber Classrooms, satellite courses and World Wide Web 54 courses. Here is some 55 unflowing text. Here is some unflowing text Padding is the distance between the content inside an element and the element’s border. The clear property can be used to interrupt the flow of text around a floating element.

Ingeniørhøjskolen i Århus Slide 35 af 38 Flow and box model Content Margin Border Padding Fig. 6.13Box model for block-level elements.

Ingeniørhøjskolen i Århus Slide 36 af 38 Borders.html 1 2 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" 3 " Borders body { background-color: #ccffcc } div { text-align: center; 17 margin-bottom: 1em; 18 padding:.5em } thick { border-width: thick } medium { border-width: medium } thin { border-width: thin } groove { border-style: groove } inset { border-style: inset } outset { border-style: outset } red { border-color: red } blue { border-color: blue } The border-width property is the width of the border around an element. The border-style property is the style of border used. The border-color property is the color of the border.

Ingeniørhøjskolen i Århus Slide 37 af 38 Borders.html Program Output This text has a border 42 This text has a border 43 This text has a border A thin red line And a thicker blue line A sampling of the different types of borders that can be specified.

Ingeniørhøjskolen i Århus Slide 38 af 38 User Style Sheets Users can set their own stylesheets. Cascading: A waterfall or a series of small waterfalls over steep rocks Styles cascade from parents to children, styles mingle from designer (top), user (second), browser

Ingeniørhøjskolen i Århus Slide 39 af 38 Style Sheets finished Consider your use of CSS – then be consequent in use! Be carefull using the ”Golden Hammer”