Cascading style sheets - CSS

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

Today CSS HTML A project.
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.
© 2004, Robert K. Moniot Chapter 6 CSS : Cascading Style Sheets.
1 Web Developer & Design Foundations with XHTML Chapter 9 Key Concepts.
กระบวนวิชา 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.
Stylin’ with CSS. 2 Topics What is CSS? Why CSS? CSS Examples.
CS4370/6370 Web Development Cascading Style Sheets (CSS)
Cascading Style Sheets SP.772 May 6, CSS Useful for creating one unified look for an entire web site. Helps to seperate style from content. Can.
Web Design & Development Cascading Style Sheets (CSS)
CS134 Web Design & Development Cascading Style Sheets (CSS) Mehmud Abliz.
Lecture 7 Cascading Style Sheets (CSS) Boriana Koleva Room: C54
© 2007 D. J. Foreman CSS-1 Cascading Style Sheets Styles.
3.1 Cascading Style Sheets. Motto Fashions fade, style is eternal. —Yves Saint Laurent.
Stylin’ with CSS. 2 Topics What is CSS? Why CSS? CSS Examples.
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,
Using Cascading Style Sheets. Introduction to Styles and Properties  Cascading Style Sheets (CSS) are a standard set by the World Wide Web Consortium.
Chapter 4 Cascading Style Sheets Basics Key Concepts Copyright © 2013 Terry Ann Morris, Ed.D 1.
Cascading Style Sheets Example
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.
INTRODUCTION TO WEB DEVELOPMENT AND HTML Lecture 09: Cascade Style Sheets - Spring 2011.
Cascading Style Sheet (CSS)
XP New Perspectives on XML Tutorial 5 1 TUTORIAL 5 CSS Tutorial – Carey ISBN
1 Cascading Style Sheets (CSS) Part 2. 2 The Sources of Style Sheets.
Cascading Style Sheets " Provide means to control and change presentation of HTML documents. " Allow the user to impose a standard style. " Three levels.
CSS – Cascading Style Sheets Fred Durao
ITCS373: Internet Technology Week 3: Introduction to CSS Dr. Faisal Al-Qaed.
CIS 1315 – Web Development for Educators CIS 1315 HTML Tutorials 3 & 4: Working With CSS.
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.
CO1552 – Web Application Development Cascading Style Sheets.
Introduction to CSS. What is CSS?  Cascading Style Sheets  Used for styling HTML  Also important in javascript and jquery for selectors  External.
Stylin’ with CSS Monday October 8 th and Tuesday October 9 th.
HTML - Quiz #2 Attendance CODE:
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.
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.
 Cascading Style Sheets (CSS) ◦ Used to specify the presentation of elements separately from the structure of the document.  Inline style ◦ declare.
DIV, Span, CSS.
3. Cascading Style Sheets (CSS) M. Udin Harun Al Rasyid, S.Kom, Ph.D Lab Jaringan Komputer.
Cascading Style Sheets CSS.  Standard defined by the W3C  CSS1 (released 1996) 50 properties  CSS2 (released 1998) 150 properties (positioning)  CSS3.
XP Review 2 New Perspectives on JavaScript, Comprehensive1 Introducing Cascading Style Sheets Formatting Web Pages with CSS.
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.
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,
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:
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.
Developing Web Applications with HTML and CSS “Selectors and Properties”
Department of Computer Science, Florida State University CGS 3066: Web Programming and Design Spring
CSS Cascading Style Sheets *referenced from
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.
Tutorial 3 Designing a Web Page with CSS
Chapter 11 & 12 CSS Style Sheets: Intro. Why CSS? Separate presentation from content – more accessible Less work – can change appearance of whole site.
Blended HTML and CSS Fundamentals 3 rd EDITION Tutorial 3 Introducing Cascading Style Sheets.
Internet & World Wide Web How to Program, 5/e Copyright © Pearson, Inc All Rights Reserved.
1 CS428 Web Engineering Lecture 07 Font, Text & Background (CSS - II)
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.
Cascading Style Sheets Part 1 1 IT 130 – Internet and the Web.
Internet & World Wide Web How to Program, 5/e 1. 2.
Cascading Style Sheets
Cascading Style Sheets Part 1
Cascading Style Sheets contd: Embedded Styles
IS333: MULTI-TIER APPLICATION DEVELOPMENT
Cascading Style Sheets™ (CSS)
Cascading Style Sheets Part 1
Presentation transcript:

Cascading style sheets - CSS Separate the content from the style! More flexible (changing one style definition in the style sheet will change the entire site) Consistent design Less work for larger sites (more overhead) CSS1-’96 supported by IE 4, Netscape 4 CSS2-’98 supported by IE 5, Netscape 6

Cascading Style Sheets (CSS) Like HTML, style sheets must use a common language and follow common rules. This language is known as Cascading Style Sheets, or more simply, CSS. CSS has been developed by the WWW Consortium (www.w3c.org), the same organization that develops standards for HTML. CSS is designed to augment HTML, not replace it. CSS is a whole new way of formatting Web pages. CSS provides several tools not available with standard HTML.

Type of style rules Inline style: Embedded or global style: adds styles to each individual tag within the HTML file (single section) Embedded or global style: a style is applied to the entire HTML file. The style declarations are in the header (web page) Linked or external style: links the HTML file to a text file containing the style declaration. Gives a consistent look across pages (web site) INLINE: almost defeats the purpose!

Components of a CSS Style The three parts to a CSS style: selector, property, and value. The selector is the HTML tag you are formatting (e.g. H1), The property is the attribute you want to change (e.g. font, color). Each property is set to a value. Every property (i.e. attribute) and its value are separated by a colon (:). Recall that we previously assigned attribute/value pairs by using the equals sign. However this syntax is not correct (does not work) in CSS. If you include multiple groups of property/value pairs, each group must be separated by semicolons (;).

Property / Value Pairs Example of property / value pairs separated by semicolons: font-family:Arial; font-style:italic; font-weight:bold; color : blue Compare how you set a style with HTML syntax v.s. CSS syntax: HTML syntax: color=“blue”  deprecated CSS syntax: style=“color:blue”

Inline style (in body) <tag style=“attribute1:value1; attribute2:value2 …”> <body> <h3 style=“font-family:Arial, Times; font-style:italic; color:green”> This is H3, Arial, italic and green </h3> <h3>This is simply H3</h3> </body> This is H3, Arial, italic and green This is simply H3

Inline Style Examples The style <body style="color:blue"> body is the selector, color is the property, and blue is the value. In the style <body style="background-color:silver"> body is the selector, background-color is the property, and silver is the value. These tags have their usual </body> closing tags.

Inline Style Examples In the style <p style="font-family:Arial; font-weight:bold"> p is the selector, font-family and font-weight are the properties, and Arial and bold are the values. In the style <p style="font-size:300%; color:red"> p is the selector, font-size and color are the properties, and 300% and red are the values. These tags have their usual </p> closing tags.

span, div, and p Tags The previous styles show you how to change the default style of a tag. What if you want to apply a style to just a section of text (one word, a few words, a sentence, a paragraph)? You can use the span or div or p tags, and then apply a style(s): <span style="font-style:italic"> Hey! </span> <div style="color:blue"> Good night… </div>

Differences between span, div, p span tags are usually used to format a small amount of text, such as a single word or sentence. p tags are typically used to format individual paragraphs div tags are usually used to format even largers segments of a web page, such as a table of contents. Since div tags specify a division or section of the web page, the tag includes additional formatting, namely, a line break before and after the <div> and </div>. (This is similar to the additional line breaks automatically placed after <h> tags).

Example of the Span tag <body> This sentence has one word in <span style="color:#0000FF;"> blue </span> and the rest in standard text color. <span style="color:#00DD45;">This sentence is in green.</span> <p style="font-style:italic; font-size:200%">Note how unlike tags such as ‘h’ ‘p’ or ‘div’, the ‘span’ tag doesn’t apply extra formatting such as new lines. </p> </body>

Embedded style sheet (in header) <style> selector {attribute1:value1; attribute2:value2 …} </style> <head> <style> h3 {font-family:Arial; font-style:italic; color:green} </style> </head><body> <h3>This is H3, Arial, italic and green</h3> <h3>And so is this H3</h3> </body> This is H3, Arial, italic and green And so is this

External style sheet (in header) Create a text file containing all style declarations: File should have extension “.css” such as: mystyle.css Link, or import that file to the HTML file using special tags in the header. <link href=“URL” rel=“stylesheet” type=“text/css”> mystyle.css OR The LINK tag’s attributes tell the browser to find an external style sheet, that the style sheet is a CSS file, and that the name of that file is mystyle.css ( DON’T FORGET THE RELATIVE PATH!) USER DEFINED STYLES: Tools>Internet Options>Accessibility>Check user style sheet, and provide name @import or multiple LINK tags allow you to use more than one style sheet in the same document <style> @import url(“mystyle.css”) </style>

Using CSS Style Types If you need to format a single section in a Web page, you’d probably use an inline style. An embedded style is applied to various sections within a Web page Create styles that apply to an entire Web site by creating a text file containing style declarations. Most style sheets have the extension “.css”, though this is not a requirement. Within a style sheet, you don’t need <style> tags, just the style declarations.

External Style Examples http://www.w3schools.com/css/showit.asp?filename=ex1 http://www.w3schools.com/css/showit.asp?filename=ex2

Setting fonts and attributes SAFE Font-families: Times New Roman,  text Arial, Helvetica,  headings Courier New  text

Using Font Families To choose a font-family, use font-family: font1, font2,…. Examples: body{font-family: Times New Roman, serif} p{font-family: Arial, Helvetica, San-serif} A browser will display the body text using the first font available in the list above. Helpful to use a generic family name as the last option.

Font-size style definition font-size: size h1{font-family: Arial, sans-serif; font-size: 28pt} Size can be expressed as Absolute units: cm, mm, pt, in. Relative units: px, em, ex. A percentage (of font-size of parental element) Keywords (absolute): xx-small, x-small,small, medium, large, x-large, xx-large Keywords (relative): smaller, larger (relative to the font-size of the parental element)

Font styles and weights font-style: style_type style_type  normal, italic or oblique font-weight: weight weight can be a value from 100(lightest) to 900 (boldest) in intervals of 100. normal or bold lighter or bolder (relative to the parental element)

Aligning Test text-align:alignment Examples: Alignment  left, center, right or justify (like in MS words) Examples: h1,h2,h3,h4,h5,h6{ font-family: Arial,sans-serif; text-align:center; font-weight:700; } p{font-family: Times new roman,serif; text-align:justify;}

Combining styles A linked style sheet can help you maintain a consistent look and feel throughout your Web site If you want a certain page to have additional styles, you can include styles in the head of that particular HTML document If you want just one section of a page to look different, you might use the inline styles with a <div> or <span> tag.

Combining styles The @import tag must be the first element within the STYLE tag Embedded style declarations should come after the @import commands If two style sheets define competing style, the innermost style sheet wins Style precedence: inline > global > external > browser

CSS control of Lists Style declarations for list elements (applicable to <ul>, <ol> and <li> tags). list-style-type : type disc, circle, square, none (<ol> or <ul>) decimal (“decimal-leading-zero” is not a valid value) lower-roman, upper-roman lower-alpha, upper-alpha In IE, specify an image for use as a label (<ol> or <ul>) list-style-image: url(image) warnings: does not work in Netscape 4.0 nested lists will automatically inherit this image unless you set the list-style-image attribute to “none” Change the position of the labels (semi works in IE) list-style-position: inside (“outside” is the default)

Defining colors in CSS Color names (names supported by HTML are also supported by CSS): body {color: teal} Hexadecimal form: body {color: #008080} RGB color values: body {color: rgb(0,128,128)} RGB color percentages: body {color: rgb(0%,50%,50%)}

Colors on the Web Colors on the web are represented by 3 numbers, called an RGB triplet based on their Red, Green, and Blue components. So you can “mix” any color you like. Each component has 8 bits, so there are 24 bits in all. The intensity of each component is expressed as a value ranging between (0-255) in decimal base. RED = (255, 0, 0)

Background color Background colors can be applied to almost any element in a Web page not just the page itself. H1 {background-color: rgb(204,102,255)} This is an H1 headers with a purple background

More background styles Background-image : url (file.jpg) Background-attachment: scroll | fixed (to allow the image to scroll with the element or not) Background-repeat: repeat | repeat_x | repeat_y | no-repeat (controls how the image is tiled)

Tables and CSS Other Table Attributes? Examples: Recall that the Height and Width attribute for <table> tag have been depricated. We can use the “style” attribute for CSS instead. Examples: <table style="width:50%; height:20%"> <table style="width:100%"> <table style="width:500px; height:700px"> <table style="width:50%; height:200px"> Similarly for table cells: <td style="width:value; height:value"> Other Table Attributes? Examples from W3Schools

Using class and ID as selectors An HTML tag can be a selector but sometimes you want to be more specific. For example you have a huge table and you want to format the rows in 4 different ways. Using TR as a selector will allow you only one style definition Instead you can define a class and then attach it to any HTML tag, without limiting the tag itself to a particular style

Using classes as selectors Define a class (in the header) by giving it a name preceded by a period adding the standard style definitions inside {} <style type=“txt/css”> .bright {font-weight:bold; color:red} </style> Apply the class to any HTML tag <strong class=“bright”> text </strong> <h1 class=“bright”> text </h1>

More on classes Define a class for a specific tag by Attaching to the tag selector a dot and the class name Adding the standard style definition within {} This particular class can only be applied to the tag used in its definition <style type=“txt/css”> h1.bright {font-weight:bold; color:red} </style> “bright” can be used only for h1

Hyperlink pseudo-class a: link {style for never visited links} a: visited {style for visited links} a: active {style for link that is currently being clicked} a: hover {style when the mouse cursor is hovering over the link} – rollover effect. a:hover {color=red; text-transform:uppercase; font-weight=bold}

The <div> tag This HTML tag does not format content It creates a container for block-level elements You can assign a CLASS (or ID) to the container <ul> <div class=“bright”> <li> First item <li> Second item </div> <li>Third element </ul> The <span> tag is used to mark inline elements like letters, words or phrases

Block-level element boxes HTML tags that can be treated as block-level elements: <h1>-<h6>, <p>, <hr> <blockquote> <ul>,<ol>, <li> <div> (Use this as a block container) <body> <img> You can move them around the page, apply borders and background colors to them etc.

Formatting block-level elements padding margin border The size of margins, border and padding are set with the margin, padding, and border properties respectively The padding area uses the same background as the element itself Margins are always transparent

Formatting block-level elements CSS Box Model Examples