23
1 CSS Tutorial CSS Tutorial CSS Tutorial CSS Tutorial Introduction Syntax How to use style specifications. Styles

CSS Tutorial 1 Introduction Syntax How to use style specifications. Styles

Embed Size (px)

Citation preview

Page 1: CSS Tutorial 1 Introduction Syntax How to use style specifications. Styles

1

CSS TutorialCSS Tutorial

CSS TutorialCSS Tutorial

•Introduction•Syntax•How to use style specifications.•Styles

Page 2: CSS Tutorial 1 Introduction Syntax How to use style specifications. Styles

2

CSS TutorialCSS Tutorial

IntroductionIntroduction•CSS

•HTML element•CSS style•Advantages of CSS versus HTML formatting

Page 3: CSS Tutorial 1 Introduction Syntax How to use style specifications. Styles

3

CSS TutorialCSS Tutorial

SyntaxSyntax selector {property: value}

Examples:

body {color: black}p {font-family: "sans serif"}p {text-align:center;color:red}

Page 4: CSS Tutorial 1 Introduction Syntax How to use style specifications. Styles

4

CSS TutorialCSS Tutorial

How to ... - External Style SheetHow to ... - External Style SheetStyles are specified in an external file. This is the most common and useful way of using style specifications.

<head><link rel="stylesheet" type="text/css" href="mystyle.css"></head>...

relationship

Page 5: CSS Tutorial 1 Introduction Syntax How to use style specifications. Styles

5

CSS TutorialCSS Tutorial

How to ... - Internal Style SheetHow to ... - Internal Style SheetStyles are specified inside the header of the HTML document.

<head><style type="text/css">

hr {color: sienna}p {margin-left: 20px}body {background-image: url("images/back40.gif")}

</style></head>...

Page 6: CSS Tutorial 1 Introduction Syntax How to use style specifications. Styles

6

CSS TutorialCSS Tutorial

How to ... - Inline stylesHow to ... - Inline stylesA style is applied to only one occurrence of an element.

<p style="color: sienna; margin-left: 20px">This is a paragraph

</p>

Use this methodsparingly!

Page 7: CSS Tutorial 1 Introduction Syntax How to use style specifications. Styles

7

CSS TutorialCSS Tutorial

How to ... - Styles PriorityHow to ... - Styles Priority

1.Browser default2.External style sheet3.Internal style sheet4.Inline style

Page 8: CSS Tutorial 1 Introduction Syntax How to use style specifications. Styles

8

CSS TutorialCSS Tutorial

Syntax - GroupingSyntax - GroupingYou can set a property for more than one element (tag) at a time.

Example:

h1, h2, h3 {color: green;}

Page 9: CSS Tutorial 1 Introduction Syntax How to use style specifications. Styles

9

CSS TutorialCSS Tutorial

Syntax – Class SelectorSyntax – Class SelectorWith the class selector you can set different styles for the same type of HTML element.Example:

<p class="right">This paragraph will be right-aligned.</p><p class="center">This paragraph will be center-aligned.</p>

p.right {text-align: right}p.center {text-align: center}

Page 10: CSS Tutorial 1 Introduction Syntax How to use style specifications. Styles

10

CSS TutorialCSS Tutorial

Syntax – Class Selector (cont.)Syntax – Class Selector (cont.)You can omit the tag name to define the style for all HTML elements with a certain class.Example:

<h1 class="center">This heading will be center-aligned</h1><p class="center">This paragraph will also be center-aligned.</p>

.center {text-align: center}

Page 11: CSS Tutorial 1 Introduction Syntax How to use style specifications. Styles

11

CSS TutorialCSS Tutorial

Syntax – id selectorSyntax – id selectorYou can define styles for HTML elements with a certain 'id' attribute.Example 1:

<h1 id="verde">This heading will be green</h1><p id="verde">This paragraph will also be green</p>

#verde {color: green}

p#rojo{ text-align: center; color: red}

Example 2

<p id=”rojo”>This paragraph is center and red.</p>

Page 12: CSS Tutorial 1 Introduction Syntax How to use style specifications. Styles

12

CSS TutorialCSS Tutorial

Syntax – Pseudo-classesSyntax – Pseudo-classesA link that is active, visited, unvisited, or when the mouse is above it can be displayed differently using CSS.selector:pseudo-class {property: value}

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 */

Page 13: CSS Tutorial 1 Introduction Syntax How to use style specifications. Styles

13

CSS TutorialCSS Tutorial

Syntax – CSS CommentsSyntax – CSS CommentsCSS comments start with a /* and end with */Example:

/* This is a comment */p{text-align: center;/* This is another comment */color: black;font-family: arial}

Page 14: CSS Tutorial 1 Introduction Syntax How to use style specifications. Styles

14

CSS TutorialCSS Tutorial

Styles - BackgroundStyles - BackgroundThe CSS background properties allows you to

•change background color of an element•set an image as the background•repeat a background image vertically or horizontally•position an image on a page.

Page 15: CSS Tutorial 1 Introduction Syntax How to use style specifications. Styles

15

CSS TutorialCSS Tutorial

Page 16: CSS Tutorial 1 Introduction Syntax How to use style specifications. Styles

16

CSS TutorialCSS Tutorial

Page 17: CSS Tutorial 1 Introduction Syntax How to use style specifications. Styles

17

CSS TutorialCSS Tutorial

Styles - TextStyles - TextThe CSS text properties allow you to control the appearance of text. It is possible to change the color of a text, increase or decrease the space between characters in a text, align a text, decorate a text, indent the first line in a paragraph, and more.

Page 18: CSS Tutorial 1 Introduction Syntax How to use style specifications. Styles

18

CSS TutorialCSS Tutorial

Page 19: CSS Tutorial 1 Introduction Syntax How to use style specifications. Styles

19

CSS TutorialCSS Tutorial

Styles - FontStyles - FontThe CSS font properties allow you to change the font family, boldness, size, and the style of a text.

Page 20: CSS Tutorial 1 Introduction Syntax How to use style specifications. Styles

20

CSS TutorialCSS Tutorial

Page 21: CSS Tutorial 1 Introduction Syntax How to use style specifications. Styles

21

CSS TutorialCSS Tutorial

Styles – Border, Margin, PaddingStyles – Border, Margin, PaddingBorder

Specify the style and color of an element's borderMargin

Specify space around elementsPadding

Specify space between the element border and the element content

Page 22: CSS Tutorial 1 Introduction Syntax How to use style specifications. Styles

22

CSS TutorialCSS Tutorial

Styles - MarginStyles - Margin

Page 23: CSS Tutorial 1 Introduction Syntax How to use style specifications. Styles

23

CSS TutorialCSS Tutorial

Styles – ListStyles – ListAllow you to change between various list item markers.