Presentation is loading. Please wait.

Presentation is loading. Please wait.

Cascading Style Sheet.

Similar presentations


Presentation on theme: "Cascading Style Sheet."— Presentation transcript:

1 Cascading Style Sheet

2 Learning objectives Understanding css Css Syntax Css selectors Using css for web layouts Css properties Styling text and Links

3 What is CSS? Styles define how to display HTML elements
External Style Sheets can save a lot of work External Style Sheets are stored in CSS files CSS stands for Cascading Style Sheets

4 Styles Solved a Big Problem
HTML was never intended to contain tags for formatting a document. HTML was intended to define the content of a document, like: <h1>This is a heading</h1> <p>This is a paragraph.</p> When tags like <font>, and color attributes were added to the HTML 3.2 specification, it started a nightmare for web developers. Development of large web sites, where fonts and color information were added to every single page, became a long and expensive process to solve this problem, the World Wide Web Consortium (W3C) created CSS. All browsers support CSS today

5 #body {color:#fff222;} CSS Syntax
The selector is normally the HTML element you want to style. Each declaration consists of a property and a value. A CSS declaration always ends with a semicolon. Declaration groups are surrounded by curly brackets:

6 To make the CSS more readable, you can put one declaration on each line, like this:
p {color:#ffffff; text-align:center; }

7 CSS Comments Comments are used to explain your code, and may help you when you edit the source code at a later date. Comments are ignored by browsers. A CSS comment begins with "/*", and ends with "*/", like this: /*This is a comment*/ p { text-align:center; /*This is another comment*/ color:black; font-family:arial; }

8 Id and Class Selectors In addition to setting a style for a HTML element, CSS allows you to specify your own selectors called "id" and "class".

9 Three Ways to Insert CSS
External style sheet Internal style sheet Inline style

10 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 to which it is applied: <p style="color:sienna;margin-left:20px">This is a paragraph.</p>

11 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 <style> tag, like this: <head> <style type="text/css"> hr {color:sienna;} p {margin-left:20px;} body {background-image:url("images/back40.gif");} </style> </head>

12 External Style Sheet 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 <link> tag. The <link> tag goes inside the head section: <head> <link rel="stylesheet" type="text/css” href="mystyle.css" /> </head>

13 External Style sheet <DOCTYPE html> <html lang=“en”> <head> <title></title> <meta charset=“utf-8”> <link rel=“stylesheet” type=“text/css” href=“yourstyle.css”> (you can link more than one stylesheet to a web page!) </head> <body> </body> </html>

14 Multiple Style Sheets If some properties have been set for the same selector in different style sheets, the style closest to the <element> dominates. For example, an external style sheet has these properties for the h3 selector: H3 {color:red; text-align:left; font-size:8px;} And an internal style sheet has these properties for the h3 selector: H3 {text-align:right; font-size:20pxt;} If the page with the internal style sheet also links to the external style sheet the properties for h3 will be: color:red; text-align:right; font-size:20px; The color is inherited from the external style sheet and the text-alignment and the font-size is replaced by the internal style sheet.

15 Cascading Styles styles will "cascade” into a new "virtual" style sheet by the following rules in order of priority: highest priority: 1 Inline style (inside an HTML element) 2 Internal style sheet (in the head section) 3 External style sheet 4 Browser default least priority:

16 Styling your layout A web page can be thought of as a series of various shaped boxes holding information. Through css a developer/designer can modify color, shape, size transparency and so much more. Personal taste, functionality, cross browser support, trends, and client requirements all affect the way in which you approach your design. <header></header> <nav></nav> <aside> </aside> <article> </article>

17 The 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": #para1 { text-align:center; color:red;}

18 The 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;}

19 Let’s try it Create a new html5 page Create a div with an ID wrapper In the head of the document create a page style <head> <style> </style> </head>

20 Setting a Height and Width
Create a new html and create a div called wrapper #wrapper{ width: 1024px; height:1200px; }

21 Color Property The color property is used to set the color of the text. With CSS, a color is most often specified by: a HEX value – like #ff0000 an RGB value – like rgb(255,0,0) an RGB value with transperancy rgba(255,0,0,.5) a color name – like red

22 Add Some Color Create a new html and create a div called wrapper #wrapper{ width: 1024px; height:1200; background: #fffccc; }

23 Image Background #wrapper{ width: 1024px; height:1200px; background: url(../path to your image.jpg); }

24 Stop repeating image #wrapper{ width: 1024px; height:1200px; background: url(../path to your image.jpg) no-repeat; }

25 Repeat horizontally #wrapper{ width: 1024px; height:1200px; background: url(../path to your image.jpg) repeat-x; }

26 Repeat vertically #wrapper{ width: 1024px; height:1200px; background: url(../path to your image.jpg) repeat-y; }

27 RGB Gradient Background
#wrapper{ width: 1024px; height:1200px; background-image: -o-linear-gradient(bottom, rgb(31,41,37) 0%, rgb(36,108,171) 50%); background-image: -moz-linear-gradient(bottom, rgb(31,41,37) 0%, rgb(36,108,171) 50%); background-image: -webkit-linear-gradient(bottom, rgb(31,41,37) 0%, rgb(36,108,171) 50%); background-image: -ms-linear-gradient(bottom, rgb(31,41,37) 0%, rgb(36,108,171) 50%); }

28 Hexadecimal Gradient Background
#wrapper{ width: 1024px; height:1200px; background-image: -o-linear-gradient(bottom, #1F2925 0%, #246CAB 50%); background-image: -moz-linear-gradient(bottom, #1F2925 0%, #246CAB 50%); background-image: -webkit-linear-gradient(bottom, #1F2925 0%, #246CAB 50%); background-image: -ms-linear-gradient(bottom, #1F2925 0%, #246CAB 50%); }

29 CSS3 Border Radius #wrapper{ -webkit-border-radius: 25px;
width: 1024px; height:1200px; background-image: -o-linear-gradient(bottom, #1F2925 0%, #246CAB 50%); background-image: -moz-linear-gradient(bottom, #1F2925 0%, #246CAB 50%); background-image: -webkit-linear-gradient(bottom, #1F2925 0%, #246CAB 50%); background-image: -ms-linear-gradient(bottom, #1F2925 0%, #246CAB 50%); -webkit-border-radius: 25px; -moz-border-radius: 25px; border-radius: 25px; }

30 Add a Border #wrapper{ border: 1px solid red; }
width: 1024px; height:1200px; background-image: -o-linear-gradient(bottom, #1F2925 0%, #246CAB 50%); background-image: -moz-linear-gradient(bottom, #1F2925 0%, #246CAB 50%); background-image: -webkit-linear-gradient(bottom, #1F2925 0%, #246CAB 50%); background-image: -ms-linear-gradient(bottom, #1F2925 0%, #246CAB 50%); border: 1px solid red; This is a shortcut property that sets the border-width, border-style, and border-color properties in one statement. It's not necessary to provide all three values, but they must appear in that order. }

31 Floating elements whose rendering boxes are shifted to the left or right side of the current line. float:left; float:right;

32 Positionong The CSS positioning properties allow you to position an element. It can also place an element behind another, and specify what should happen when an element's content is too big. Elements can be positioned using the top, bottom, left, and right properties. However, these properties will not work unless the position property is set first. They also work differently depending on the positioning method. There are four different positioning methods.

33 Static Positioning HTML elements are positioned static by default. A static positioned element is always positioned according to the normal flow of the page.Static positioned elements are not affected by the top, bottom, left, and right properties.

34 Fixed Positioning An element with fixed position is positioned relative to the browser window.It will not move even if the window is scrolled: #some element { position:fixed; top:30px; right:5px; } Fixed positioned elements are removed from the normal flow. The document and other elements behave like the fixed positioned element does not exist. Fixed positioned elements can overlap other elements.

35 Relative Positioning A relative positioned element is positioned relative to its normal position. h2 {position:relative; left:-20px;} The content of relatively positioned elements can be moved and overlap other elements, but the reserved space for the element is still preserved in the normal flow.

36 Absolute Positioning An absolute position element is positioned relative to the first parent element that has a position other than static. If no such element is found, the containing block is <html>: H2 {position:absolute;left:100px;top:150px;} Absolutely positioned elements are removed from the normal flow. The document and other elements behave like the absolutely positioned element does not exist. Absolutely positioned elements can overlap other elements.

37 Determine your layout Before you Start

38 Things to Consider When planning a Website
Who is my audience and what do they want to know about? What is the purpose of the site? What image do you want the site to convey? Make Sure Your Site Looks Professional? Domain Name .ca .org .com Hosting

39 Things to Consider When Designing a Website
What is current? What content do I have? What image do you want the site to convey? What do you like or hate about your competitors’ websites? Copywriting. Data collection. Search Engine Optimization.

40 Questions?

41 Adding Colour to Text P { color:#3f3f3f;} Body {color:#3f3f3f;}

42 Text Align The text-align property is used to set the horizontal alignment of a text. Text can be centered, or aligned to the left or right, or justified. When text-align is set to "justify", each line is stretched so that every line has equal width, and the left and right margins are straight (like in magazines and newspapers). Example h1 {text-align:center;} p.date {text-align:right;} p.main {text-align:justify;}

43 Styling Links The browser default for links are somelink Links can be styled with any CSS property (e.g. color, font-family, background, etc.). Special for links are that they can be styled differently depending on what state they are in. The four links states are: a {color:#ffffff;} normal, unvisited link a:visited {text-decoration:none;} link the user has visited a:hover {color:rgb(36,35,35);} link when the user mouses over it a:active {your style here} link the moment it is clicked

44 text-decoration The text-decoration property is used to set or remove decorations from text. The text-decoration property is mostly used to remove underlines from links for design purposes: Example a {text-decoration:none;}


Download ppt "Cascading Style Sheet."

Similar presentations


Ads by Google