Download presentation
Presentation is loading. Please wait.
Published byTrevor Elliott Modified over 9 years ago
1
1 What is CSS? CSS stands for Cascading Style Sheets Styles define how to display HTML elements Styles are normally stored in Style Sheets Styles were added to HTML 4.0 to solve a problem External Style Sheets can save you a lot of work External Style Sheets are stored in CSS files Multiple style definitions will cascade into one With CSS, your HTML document can be displayed using different output styles
2
2 Advantages of CSS? With CSS, you will be able to: - define the look of your pages in one place rather than repeating yourself over and over again throughout your site. (Ever get tired of defining colors and fonts each time you start a new cell in a table? Those days are over with CSS!) - easily change the look of your pages even after they're created. Since the styles are defined in one place you can change the look of the entire site at once. (Ever get tired of replacing tags throughout your site when you want to change the look of a certain element? Those days are over with CSS!)
3
3 - define font sizes and similar attributes with the same accuracy as you have with a word processor - not being limited to just the seven different font sizes defined in HTML. - position the content of your pages with pixel precision. - redefine entire HTML tags. Say for example, if you wanted the bold tag to be red using a special font - this can be done easily with CSS
4
4 - define customized styles for links - such as getting rid of the underline. - define layers that can be positioned on top of each other (often used for menus that pop up).
5
5 Disadvantages of CSS? these will only work on version 4 browsers or newer. However, more than 95% of all browsers live up to that. - these will only work on version 4 browsers or newer. However, more than 95% of all browsers live up to that.
6
6 Cascading order Style will “cascade” into a new “virtual” style sheet by the following rules, where number 4 has the highest priority 1.Browser default 2.External Style Sheet 3.Internal Style Sheet (inside the tag) 4.Inline Style (inside HTML element) So, an inline style has the highest priority, which mean that it will override every style declared inside the tag, in an external style sheet, and in a browser (a default value)
7
7 CSS syntax The syntax is made up of three parts:The syntax is made up of three parts: a selectora selector normally the element/tag you wish to define a propertya property the attribute you wish to change a valuea value each property can take a value The property and value are separated by a colon and surrounded by curly bracesThe property and value are separated by a colon and surrounded by curly braces selector { property : value } body { color : black }
8
8 CSS syntax If the value is multiple words, put quotes around the valueIf the value is multiple words, put quotes around the value If you wish to specify more than one property, you should separate each property with semi-colon.If you wish to specify more than one property, you should separate each property with semi-colon. The example below shows how to define a center aligned paragraph, with a red text colorThe example below shows how to define a center aligned paragraph, with a red text color p { font-family : “sans serif” } p { text-align : center ; color : red }
9
9 Grouping You can group selectorsYou can group selectors Each selector need to be separate with a commaEach selector need to be separate with a comma The example below have grouped all the header elements. Each header element will be greenThe example below have grouped all the header elements. Each header element will be green h1, h2, h3, h4, h5, h6 { color: green }
10
10 The class attribute With the class attribute you can define different styles for the same elementWith the class attribute you can define different styles for the same element Example below show how to set a 2 types of different paragraphExample below show how to set a 2 types of different paragraph p.right {text-align: right} p.center {text-align: center} You have to use the class attribute in your HTML documentYou have to use the class attribute in your HTML document This paragraph will be right-aligned This paragraph will be right-aligned This paragraph will be center-aligned This paragraph will be center-aligned
11
11 The class attribute You can also omit the tag name in the selector to define a style that can be used by many elementsYou can also omit the tag name in the selector to define a style that can be used by many elements eg..center {text-align: center}eg..center {text-align: center} To use the style we can look at the example belowTo use the style we can look at the example below This heading will be center-aligned This heading will be center-aligned This paragraph will also be center- aligned This paragraph will also be center- aligned
12
12 CSS comments You can insert comments in CSS to explain your code, which can help you when you edit the source code at a later date A comment will be ignored by the browser CSS comment begin with /* and end with */ eg/* This is a comment */
13
13 How to insert a Style Sheet There are 3 ways of inserting a style sheet External Style Sheet Internal Style Sheet Inline Style Sheet
14
14 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 tag The tag goes inside the head section
15
15 External Style Sheet The browser will read the style definitions from the file mystyle.css, and format the document according to it 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”) }
16
16 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 by using the tag hr { color: sienna } p { margin-left: 20px } body {background-image: url(“images/back40.gif) }
17
17 Inline Styles An inline style loses many of the advantages of style sheets by mixing content with presentation Use this method sparingly, such as when a style is to be applied to a single occurrence of an element. 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
18
18 CSS Background Properties The background properties allow you to control the background color of an element set an image as the background repeat a background image vertically or horizontally position an image on a page Example of background properties Example of background properties
19
19 CSS Text Properties 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 text, and more more Example of text properties Example of text properties
20
20 CSS Font Properties The Font properties allow you to change the font family, boldness, size, and the style of a text Example of font properties Example of font properties
21
21 CSS Border Properties The Border properties allow you to specify the style, color, and width of an element's border In HTML we used tables to create borders around a text, but with the Border properties we can create borders with nice effects, and it can be applied to any element Example of border properties Example of border properties
22
22 CSS Margin Properties The Margin properties define the space around elements It is possible to use negative values to overlap content The top, right, bottom, and left margin can be changed independently using separate properties A shorthand margin property can also be used to change all of the margins at once Example of margin properties Example of margin properties
23
23 CSS Padding Properties The Padding properties define the space between the element border and the element content Negative values are not allowed The top, right, bottom, and left padding can be changed independently using separate properties A shorthand padding property is also created to control multiple sides at once Example of padding properties Example of padding properties
24
24 CSS List Properties The List properties allow you to change between different list- item markers, set an image as a list-item marker, and set where to place a list-item marker Example of unordered lists Example of unordered lists Example of ordered list Example of ordered list
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.