Presentation is loading. Please wait.

Presentation is loading. Please wait.

Cascading Style Sheets - Building a stylesheet

Similar presentations


Presentation on theme: "Cascading Style Sheets - Building a stylesheet"— Presentation transcript:

1 Cascading Style Sheets - Building a stylesheet
CGS 3066: Lecture 4 Cascading Style Sheets - Building a stylesheet

2 Purpose CSS defines HOW HTML elements are to be displayed.
Styles are normally saved in external “.css” files. External style sheets allow changes to the appearance of all the pages in a Web site by editing one single file!

3 CSS Syntax A CSS file consists of rule set, which define the presentation element for a particular part of the HTML document. A CSS rule set consists of a selector and a declaration block.

4 CSS Rule Set A Rule Set has a selector and a declaration block.
The declaration block is enclosed in { }. The declaration block contains one or more declarations separated by semicolons. Each declaration includes a property name and a value, separated by a colon. To make the CSS code more readable, you can put one declaration on each line.

5 CSS Comments CSS comments follow the multiline C comment syntax.
A CSS comment starts with /* and ends with */. Comments can also span multiple lines and are ignored by browsers. Single line comments can start with “//”.

6 CSS Selectors CSS selectors allow you to select and manipulate HTML elements. They are used to "find" HTML elements based on id, classes, types, attributes, values of attributes, etc. Typically, selectors are one of 3 kinds: id selector element selector class selector

7 Element Selector The element selector selects elements based on the element name. Applied to all elements with the same name (tag) p { text-align: center; color: red; }

8 ID Selector The id selector uses the id attribute of an HTML tag to find the specific element. An id should be unique within a page. To find an element with a specific id, write a hash character, followed by the id of the element. #para1 { text-align: center; color: red; }

9 Class Selector The class selector finds elements with the specific class. The class selector uses the HTML class attribute. To find elements with a specific class, write a period character, followed by the name of the class. .center { text-align: center; color: red; }

10 Class Selector You can also specify that only specific HTML elements should be affected by a class. p.center { text-align:center; color:red; }

11 Grouping Selectors In style sheets there are often elements with the same style. In the interest of code minimization, we can group selectors. Selectors are separated by commas. h1, h2, p { text-align: center; color: red; }

12 CSS Backgrounds CSS background properties are used to define the background effects of an element. CSS properties used for background effects: background: all properties in one declaration background-color: color only background-image: set an image as background background-repeat: image repeats (tiled) background-attachment: sets whether a background image is fixed or scrolls with the rest of the page. background-position: sets starting position of a background image.

13 CSS3 Background CSS3 added a few more properties:
background-clip: Specifies the painting area of the background images. background-origin: Specifies the positioning area of the background images. background-size: Specifies the size of the background images.

14 CSS Text

15 CSS Text

16 CSS3 Text effects

17 CSS Fonts

18 CSS3 Fonts


Download ppt "Cascading Style Sheets - Building a stylesheet"

Similar presentations


Ads by Google