Presentation is loading. Please wait.

Presentation is loading. Please wait.

Chapter 8 Cascading Style Sheets (CSS). Agenda Definition of a CSS style Types of CSS Styles CSS Backgrounds CSS Text CSS Fonts CSS Links CSS Lists CSS.

Similar presentations


Presentation on theme: "Chapter 8 Cascading Style Sheets (CSS). Agenda Definition of a CSS style Types of CSS Styles CSS Backgrounds CSS Text CSS Fonts CSS Links CSS Lists CSS."— Presentation transcript:

1 Chapter 8 Cascading Style Sheets (CSS)

2 Agenda Definition of a CSS style Types of CSS Styles CSS Backgrounds CSS Text CSS Fonts CSS Links CSS Lists CSS Tables CSS Selectors CSS Units CSS Color Values

3 What is CSS? Cascading Style Sheets (CSS) is a style sheet language used for describing the presentation semantics (the look and formatting) of a document written in a markup language. Its most common application is to style web pages written in HTML and XHTML, but the language can also be applied to any kind of XML document. Styles define how to display HTML elements Styles are added to HTML to solve a problem External Style Sheets can save a lot of work External Style Sheets are stored in CSS files

4 Types of CSS Styles 1.Internal Styles are defined in the section of the current web page. 2.Inline Styles are defined within the HTML markup of a particular page element. (avoid using) 3.External Styles are defined on the External Style Sheet, which is linked to the web pages(s). (Best choice)

5 Internal Style Sheet An internal style sheet should be used when a single document has a unique style. You define internal styles in the head section of an HTML page, by using the tag, like this: hr {color:sienna;} p {margin-left:20px;} body {background image:url("images/back40.gif");}

6 Inline Styles An inline style loses many of the advantages of style sheets by mixing content with presentation. Use this method sparingly! To use inline styles you use the style attribute in the relevant tag. The style attribute can contain any CSS property. The example shows how to change the color and the left margin of a paragraph: This is a paragraph.

7 External Styles An external style sheet is ideal when the style is applied to many pages. With an external style sheet, you can change the look of an entire Web site by changing one file. Each page must link to the style sheet using the tag. The tag goes inside the head section: An external style sheet can be written in any text editor. The file should not contain any html tags. Your style sheet should be saved with a.css extension. An example of a style sheet file is shown below: hr {color:sienna;} p {margin-left:20px;} body {background-image:url("images/back40.gif");}

8 Example body {color:red;} h1 {color:#00ff00;} p.ex {color:rgb(0,0,255);} This is heading 1 This is a paragraph. This is an ordinary paragraph. Notice that this text is red. The default text-color for a page is defined in the body selector. This is a paragraph with class="ex". This text is blue.

9 CSS Background Properties PropertyDescription backgroundSets all the background properties in one declaration background-attachment Sets whether a background image is fixed or scrolls with the rest of the page background-colorSets the background color of an element background-imageSets the background image for an element background-positionSets the starting position of a background image background-repeatSets how a background image will be repeated

10 Example of CSS Background body { background-image:url('img_tree.png'); background-repeat:no-repeat; background-position:right top; } h1 {background-color:#6495ed;} p {background-color:#e0ffff;}

11 CSS Text Properties PropertyDescription colorSets the color of text directionSpecifies the text direction/writing direction letter-spacingIncreases or decreases the space between characters in a text line-heightSets the line height text-alignSpecifies the horizontal alignment of text text-decorationSpecifies the decoration added to text text-indentSpecifies the indentation of the first line in a text-block text-shadowSpecifies the shadow effect added to text text-transformControls the capitalization of text vertical-alignSets the vertical alignment of an element white-spaceSpecifies how white-space inside an element is handled word-spacingIncreases or decreases the space between words in a text

12 Example of CSS Text Properties body {color:blue;} h1 {color:#00ff00;} h2 {color:rgb(255,0,0);} h1 {text-align:center;} p.date {text-align:right;} p.main {text-align:justify;} a {text-decoration:none;} h1 {text-decoration:overline;} h2 {text-decoration:line-through;} h3 {text-decoration:underline;} p.uppercase {text-transform:uppercase;} p.lowercase {text-transform:lowercase;} p.capitalize {text-transform:capitalize;} p {text-indent:50px;}

13 CSS Font Properties PropertyDescription fontSets all the font properties in one declaration font-familySpecifies the font family for text font-sizeSpecifies the font size of text font-styleSpecifies the font style for text font-variantSpecifies whether or not a text should be displayed in a small-caps font font-weightSpecifies the weight of a font

14 Example of CSS Font Properties p{font-family:"Times New Roman", Times, serif;} p.normal {font-style:normal;} p.italic {font-style:italic;} p.oblique {font-style:oblique;} h1 {font-size:40px;} h2 {font-size:30px;} p {font-size:14px;} p.small{font-variant:small-caps;} p.normal {font-weight:normal;} p.thick {font-weight:bold;} p.thicker {font-weight:900;}

15 CSS Links Links can be styled with any CSS property (e.g. color, font-family, background, etc.). In addition, links can be styled differently depending on what state they are in. The four links states are: a:link - a normal, unvisited link a:visited - a link the user has visited a:hover - a link when the user mouses over it a:active - a link the moment it is clicked Example a:link {color:#FF0000;} /* unvisited link */ a:visited {color:#00FF00;} /* visited link */ a:hover {color:#FF00FF;} /* mouse over link */ a:active {color:#0000FF;} /* selected link */

16 CSS Links (Continued) Text Decoration The text-decoration property is mostly used to remove underlines from links: Example a:link {text-decoration:none;} a:visited {text-decoration:none;} a:hover {text-decoration:underline;} a:active {text-decoration:underline;} Background Color The background-color property specifies the background color for links: Example a:link {background-color:#B2FF99;} a:visited {background-color:#FFFF85;} a:hover {background-color:#FF704D;} a:active {background-color:#FF704D;}

17 CSS List Properties PropertyDescription list-style Sets all the properties for a list in one declaration list-style-imageSpecifies an image as the list-item marker list-style-position Specifies if the list-item markers should appear inside or outside the content flow list-style-typeSpecifies the type of list-item marker

18 Example of CSS List Properties ul.a {list-style-type: circle;} ul.b {list-style-type: square;} ol.c {list-style-type: upper-roman;} ol.d {list-style-type: lower-alpha;} ul{list-style-image: url('sqpurple.gif');} ul{list-style-position:inside;}

19 CSS Tables properties Table Borders To specify table borders in CSS, use the border property. The example below specifies a black border for table, th, and td elements: Example table, th, td { border: 1px solid black; }

20 Example of CSS Tables properties table {width:100%;} th{height:50px;} td{text-align:right;} td{height:50px;vertical-align:bottom;} td{padding:15px;} table, td, th {border:1px solid green;} th{background-color:green;color:white;}

21 The CSS id Selector The id selector is used to specify a style for a single, unique element. The id selector uses the id attribute of the HTML element, and is defined with a "#". The style rule below will be applied to the element with id="para1": Example #para1 { text-align:center; color:red; }

22 The CSS Class Selector The class selector is used to specify a style for a group of elements. Unlike the id selector, the class selector is most often used on several elements. This allows you to set a particular style for many HTML elements with the same class. The class selector uses the HTML class attribute, and is defined with a "." In the example below, all HTML elements with class="center" will be center-aligned: Example.center {text-align:center;}

23 CSS Selectors SelectorExampleExample description.class.introSelects all elements with class="intro" #id#firstnameSelects the element with id="firstname" **Selects all elements elementpSelects all elements element,elementdiv,pSelects all elements and all elements element elementdiv pSelects all elements inside elements element>elementdiv>p Selects all elements where the parent is a element element+elementdiv+p Selects all elements that are placed immediately after elements

24 CSS Units UnitDescription %percentage ininch cmcentimeter mmmillimeter em 1em is equal to the current font size. 2em means 2 times the size of the current font. E.g., if an element is displayed with a font of 12 pt, then '2em' is 24 pt. The 'em' is a very useful unit in CSS, since it can adapt automatically to the font that the reader uses exone ex is the x-height of a font (x-height is usually about half the font-size) ptpoint (1 pt is the same as 1/72 inch) pcpica (1 pc is the same as 12 points) pxpixels (a dot on the computer screen)

25 Color Values ColorColor HEXColor RGB #000000rgb(0,0,0) #FF0000rgb(255,0,0) #00FF00rgb(0,255,0) #0000FFrgb(0,0,255) #FFFF00rgb(255,255,0) #00FFFFrgb(0,255,255) #FF00FFrgb(255,0,255) #C0C0C0rgb(192,192,192) #FFFFFFrgb(255,255,255)

26 Lab 8 Types of CSS Styles CSS Backgrounds CSS Text CSS Fonts CSS Links CSS Lists CSS Tables CSS Selectors CSS Units CSS Color Values


Download ppt "Chapter 8 Cascading Style Sheets (CSS). Agenda Definition of a CSS style Types of CSS Styles CSS Backgrounds CSS Text CSS Fonts CSS Links CSS Lists CSS."

Similar presentations


Ads by Google