Slides:



Advertisements
Similar presentations
LIS901N: Style sheet Thomas Krichel Style sheets Style sheets are the officially sanctioned way to add style to your document We will cover.
Advertisements

Chapter 3 © 2003 by Addison-Wesley, Inc Introduction - HTML is primarily concerned with content, rather than style - However, tags have presentation.
CSS Digital Media: Communication and design 2007.
Today CSS HTML A project.
Cascading Style Sheets (CSS): Pixel-Level Control with HTML Ease
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 By: Valerie Kuna. What are Cascading Style Sheets? Cascading Style Sheets (CSS) are a standard for specifying the presentation.
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.
 2008 Pearson Education, Inc. All rights reserved Cascading Style Sheets™ (CSS)
1 Pengantar Teknologi Internet W03: CSS Cascading Style Sheets.
Cascading Style Sheet CSS CS1520 Ali Alanjawi. 2 TA Information Ali Alanjawi Homepage: Office:
CSS(Cascading Style Sheets )
กระบวนวิชา 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.
Measurement Many CSS properties (values within the declaration) require that you specify a unit of measurement, such as spacing between elements, border.
Dr. Ahmet Cengizhan Dirican BIL 374 Internet Technologies 3. CSS.
 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.
Outline IS400: Development of Business Applications on the Internet Fall 2004 Instructor: Dr. Boris Jukic CSS: Cascading Style Sheets.
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.
CSS – Cascading Style Sheets Fred Durao
 2008 Pearson Education, Inc. All rights reserved Cascading Style Sheets™ (CSS)
 2008 Pearson Education, Inc. All rights reserved Cascading Style Sheets™ (CSS)
 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.
Internet & World Wide Web How to Program, 5/e Copyright © Pearson, Inc All Rights Reserved.
Internet & World Wide Web How to Program, 5/e 1. 2.
WebD Introduction to CSS By Manik Rastogi.
CSS.
Cascading Style Sheets
3.1 Introduction - HTML is primarily concerned with content, rather
HTML WITH CSS.
Cascading Style Sheets™ (CSS)
Chapter 6 - Cascading Style Sheets™ (CSS)
CS3220 Web and Internet Programming CSS Basics
Cascading Style Sheets™ (CSS)
( Cascading style sheet )
CSS: Cascading Style Sheets
Chapter 6 Cascading Style Sheets™ (CSS)
3.1 Introduction - The CSS1 specification was developed in 1996
Using Cascading Style Sheets Module B: CSS Structure
CIIT-Human Computer Interaction-CSC456-Fall-2015-Mr
Cascading Style Sheets (Formatting)
CSS3 Cascading Style Sheet
3.5 Property Value Forms - There are 60 different properties in 7 categories: - Fonts - Lists - Alignment of text - Margins - Colors - Backgrounds - Borders.
Cascading Style Sheets
CSS Applications to XML 19-Sep-18.
IS333: MULTI-TIER APPLICATION DEVELOPMENT
Introduction to Web programming
3.1 Introduction - The CSS1 specification was developed in 1996
The Internet 10/13/11 The Box Model
Second CSS Lecture Applications to XML
DynamicHTML Cascading Style Sheet Internet Technology.
CMPE 280 Web UI Design and Development September 4 Class Meeting
CSS Style Sheets: Intro
Web Programming– UFCFB Lecture 11
Cascading Style Sheets
Cascading Style Sheets™ (CSS)
DynamicHTML Cascading Style Sheet Internet Technology.
3.1 Introduction - The CSS1 specification was developed in 1996
More CSS 22-Feb-19.
CS3220 Web and Internet Programming CSS Basics
CMPE 280 Web UI Design and Development February 7 Class Meeting
CS3220 Web and Internet Programming CSS Basics
CSS Applications to XML 20-May-19.
CSS Applications to XML 3-Jul-19.
Cascading Style Sheets
Cascading Style Sheets™ (CSS)
Cascading Style Sheets
CMPE 280 Web UI Design and Development September 5 Class Meeting
Presentation transcript:

CSS (Cascading Style Sheet) CHAPTER 2 CSS (Cascading Style Sheet)

Topics Introduction Inline Styles Embedded Style Sheets Conflicting Styles Linking External Style Sheets Positioning Elements Backgrounds Element Dimensions Text Flow and the Box Model User Style Sheets

Learning Outcomes At the end of this lesson, students should be able to: Control the appearance of a Web site by creating style sheets. Use a style sheet to give all the pages of a Web site the same look and feel. Use the class attribute to apply styles. Specify the precise font, size, color and other properties of displayed text. Specify element backgrounds and colors. Understand the box model and how to control the margins, borders and padding. Use style sheets to separate presentation from content.

Introduction Cascading Style Sheets (CSS) Separation of structure from presentation new way of formatting your page layout, text, fonts, images allow you to position things on your page down to the exact pixel style sheets types: Inline style sheet Embedded or Internal style sheet External style sheet

Inline Styles An inline style loses many of the advantages of style sheets by mixing content with presentation. Therefore, you should use this method sparingly, such as when a style is to be applied to a single occurrence of an element Declare an individual element’s format Attribute style CSS property Followed by a colon and a value

inline.html (1 of 2)

inline.html (2 of 2)

Embedded/Internal Style Sheets An internal style sheet should be used when a single document has a unique style. Embed an entire CSS document in an HTML document’s head section Property background-color Specifies the background color font-family(line 18)-specifies the name of font to use. h1 { font-family: arial, sans-serif }

Embedded/Internal Style Sheets Font arial will be used. If the arial font is not found on the system, the browser instead will display a generic sans-serif font. Other generic font families: Serif (e.g:Times New Roman, Georgia) Sans-Serif (e.g: Helvetica, Verdana) Cursive ( e.g: script) Fantasy (e.g: critter) Monospace (e.g: Courier, Fixedsys) font-size(line 20)-specifies the size of font.

Embedded/Internal Style Sheets Other possible measurements in addition to pt(point)- will be introduced later. Relative values- xx-small, x-small, small, smaller, medium, large, larger, x-large and xx-large.

Embedded/Internal Style Sheets Relative values are preferred because an author does not know the specific measurements of the display for each client. Relative font-size values permit more flexible viewing of web pages. If relative font-size is specified, the actual size is determined by the browser that displays the font. E.g: Handheld device with a small screen.

Embedded/Internal Style Sheets Dreamweaver environment

declared.html (1 of 3)

declared.html (2 of 3)

declared.html (3 of 3)

Embedded/Internal Style Sheets Dreamweaver environment

Selector forms Simple Selector Forms The simplest selector form is a single element name, such as h1. Consider the following examples: h1 {font-size: 20pt;} h2, h3 {font-size: 20pt;} form em {font-size: 20pt;}

Selector forms Class Selectors Class selectors are used to allow different occurrences of the same tag to use different style specifications. Consider the following examples:

Selector forms p.normal {font-size: 20pt;} p.warning {font-size: 6pt;} <p class= “normal”> …………………………… </p> <p class= “warning”>

Selector forms Generic Selectors A class of style specifications that applies to the content of more than one kind of tag.

Selector forms .sale {font-size: 20pt;} <p class= “sale”> …………………………… </p> <h2 class= “sale”>

Conflicting Styles Inheritance HTML <p class = "special"> The company's clients include many <em>Fortune 1000 companies</em>, government agencies………..</p> CSS em { background-color: #8000ff; color: white } p { font-size: 14pt } .special { color: blue } Child em element inherited the font-size property from its parent p element. However, the child em element had a color property that conflicted with the color property of its parent p element.

Conflicting Styles Descendant’s properties have greater specificity than ancestor’s properties. Conflicts are resolved in favor of properties with a higher specificity. em will be white in color instead of blue.

Conflicting Styles <html> <head> <style type="text/css"> .navtext {color: black; font-weight: bold} p {color: blue} </style> </head> <body> <p class="navtext" style="color: red">Link 1</p> <p class="navtext">Link 2</p> <p>Link 3</p> </body></html>

advance.html (1 of 3)

advance.html (2 of 3)

advance.html (3 of 3)

Linking External Style Sheets External style sheets are the best method when you want the style to be applied to many pages. With an external style sheet, you can change the look of an entire web site by changing one external style sheet file. Text-decoration applies decorations to text within an element. Possible values of Text-decoration – none, overline, line-through, underline, blink(not supported by IE)

Linking External Style Sheets hover (pseudoclass)(line 16-18)- activated dynamically when the user moves the mouse cursor over an element. Pseudoclassses are separated by a colon from the name of the element to which they are applied.

Linking External Style Sheets Margin-left(line 23 & 26)- ul { margin-left: 15px } Left-hand margin of 15 pixels Relative-length measurement- varies in size, based on screen resolution. Example: px, em, ex, percentage(%) Absolute-length measurement- not vary in size based on the system. Example: in(inches), cm(centimeter), mm(milimeter), pt(points; 1pt= 1/72 in), pc(picas; 1pc= 12 pt)

Linking External Style Sheets Dreamweaver environment

styles.css (1 of 1)

external.html (1 of 2)

external.html (2 of 2)

Properties & Property Values There are a large number of CSS properties that you can use with HTML. It is impossible for us to cover all the properties in this course. At the end of this slide, there are a number of references provided for you to refer.

List: Property & Property Values <h3> Some Common Single-Engine Aircraft </h3> <ul style = "list-style-type: square"> <li> Cessna Skyhawk </li> <li> Beechcraft Bonanza </li> <li> Piper Cherokee </li> </ul> <ul> <li style = "list-style-type: disc"> Cessna Skyhawk </li> <li style = "list-style-type: square"> Beechcraft Bonanza </li> <li style = "list-style-type: circle"> Piper Cherokee </li>

List: Property & Property Values Other list-style-type values: Property value First four decimal 1, 2, 3, 4 upper-alpha A, B, C, D lower-alpha a, b, c, d upper-roman I, II, III, IV lower-roman i, ii, iii, iv

Positioning Elements Absolute positioning Removes the elements from the normal flow of elements on the page, instead positioning it according to the distance from the top, left, right, or bottom margin of its containing block-level element (i.e: body, p) z-index attribute Layer overlapping elements properly

Positioning Elements Relative positioning Elements that have a higher z-index values are displayed in front of elements with lower z-index values. If z-index is not specified or elements have same z-index value Elements are placed from background to foreground in order they are encountered in the document. Relative positioning Elements are positioned relative to other elements

positioning.html (1 of 1)

Dreamweaver environment Positioning Elements Dreamweaver environment

Dreamweaver environment Positioning Elements Dreamweaver environment

span One problem with the font properties is that they apply to whole elements, which are often too large Solution: a new tag to define an element in the content of a larger element - <span> The default meaning of <span> is to leave the content as it is

span Example: <p> Now is the <span> best time </span> ever! </p> Use <span> to apply an inline style sheet to its content Now is the <span style = "font-size: 40; font-family: Arial; color: red"> best time </span> ever!

Span & div The <span> tag is similar to other HTML tags, they can be nested and they have id and class attributes Another tag that is useful for style specifications: <div> Used to create document sections (or divisions) for which style can be specified e.g.: A section of five paragraphs for which you want some particular style

Span & div <html> <head> <style type="text/css"> .try {font-size:6pt}; .try1 {font-size:50pt}; </style> </head> <body> <div class="try"> <p> A </p> <p> A </p> </div> <p>Hello <span class="try1">Welcome </span>to Web Programming </p> </body> </html>

positioning2.html (1 of 2)

positioning2.html 2 of 2 Output:

Backgrounds Specifies the image URL background-image Specifies the image URL Can also set background-color property in case the image is not found background-position Places the image on the page Some of the values: top, bottom, center, left, right

Backgrounds All above values are used individually or combination for vertical and horizontal positioning. Example: To position the image as horizontally centered(positioned at 50% of the distance across the screen) and 30 pixels from the top, use: background-position: 50% 30px;

Backgrounds Controls the tiling of the background image background-repeat Controls the tiling of the background image Possible values: no-repeat, repeat, repeat-x (tile the image horizontally), repeat-y (tile the image vertically) background-attachment Fixed (fix the image in the position specified by background-position) Scroll (moves the image when user scrolls through the document)

Backgrounds font-weight Specify the “boldness” of text Possible values: bold, normal, bolder, lighter font-style Possible values: none, italic, oblique (will default to italic if the system does not support oblique text.)

background.html (1 of 2)

background.html (2 of 2)

Alignment of Text The text-indent property can be used to indent the first line of a paragraph. The float property is used to specify that text should flow around some element, often an image or a table. The possible values for float are left, right, and none, which is the default.

Alignment of Text <html><head> <style type="text/css"> p.indent {text-indent: 0.5in} </style> </head> <body> <p class="indent"> A Web programmer or Web developer is the person in charge of making the website do things. They create the interactivity on the site including the actions on forms, rollovers for menus, and any Ajax or other programmming on the site. </p> </body></html>

Alignment of Text A Web programmer or Web developer is the person in charge of making the website do things. They create the interactivity on the site including the actions on forms, rollovers for menus, and any Ajax or other programmming on the site.

Alignment of Text <html><head> <style type="text/css"> img {float: right} </style> </head> <body> <p> <img src="web.jpg" width="100" height="100" /> </p> A Web programmer or Web developer is the person in charge of making the website do things. They create the interactivity on the site including the actions on forms, rollovers for menus, and any Ajax or other programmming on the site. </body></html>

The Box Model Outer Edge Margin Border Padding Content

The Box Model Margins Padding Border Box model margin-top, margin-right, margin-left, margin-bottom Padding padding-top, padding-right, padding-left, and padding-bottom Border border-width thin, medium, thick border-color Sets the color border-style none, hidden, dotted, dashed, solid, double, groove, ridge, inset and outset

floating.html (1 of 3)

floating.html (2 of 3)

floating.html (3 of 3)

Possible values of clear = right, left <p style=“clear: right”>…..</p>(line 49) Possible values of clear = right, left By setting clear property to the same direction as that in which the elements is floated (right or left), you can interrupt the flow of text around a floated element.

borders.html (1 of 2)

borders.html (2 of 2)

borders2.html (1 of 2)

borders2.html (2 of 2)

Margins and Padding <html><head> <style type="text/css"> p.one {margin:0.1in; padding:0.3in; background-color:#C0C0Co; border-style:solid; } </style> </head> <body> <p class="one"> margin= 0.1in, padding=0.3in </p> </body></html>

Margins and Padding padding =0.3in margin =0.1in

User Style Sheets User defines format of pages based on their preferences. Conflicts may occur between author styles and user styles. User_absolute.html- If users define their own font-size in a user style sheet, the author has a higher precedence and overrides the user style. The font size is too small for above file.

User_absolute.html (1 of 2)

User_absolute.html (2 of 2)

userstyles.css 1 of 1

User Style Sheets Fig. 6.18 User style sheet in Internet Explorer 6.

User Style Sheets Fig. 6.19 User style sheet applied with pt measurement.

User Style Sheets 170 Developer/author are advised to use relative measurements (e.g: em or ex) instead of absolute measurements(e.g:pt).-Refer to slide 99 User_relative.html- the font-size has been changed to .75 em. This will not override the user style sheet. Font size displayed is relative to the one specified in the user style sheet.

User_relative.html (1 of 2) 20 pt 0.75 em X 20 pt = 15 pt

User_relative.html (2 of 2)

User Style Sheets Fig. 6.21 User style sheet applied with em measurement.

References CSS Properties http://htmlhelp.com/reference/css/properties.html CSS Reference & Properties http://www.w3schools.com/CSS/CSS_reference.asp Pick Brains: CSS http://www.pickbrains.com/articles/cascading-style-sheets-css-tutorial-usage