210 likes | 384 Views
CSS. Dynamic HTML. Cascading style sheets, HTML, DOM and Javascript. DHTML. Collection of technologies forming dynamic clients HTML ( content ) DOM ( data structure ) JavaScript ( behaviour ) Cascading Style Sheets ( presentation ). HTML ELEMENT. Standard PROPERTIES.
E N D
Dynamic HTML Cascading style sheets, HTML, DOM and Javascript
DHTML • Collection of technologies forming dynamic clients • HTML (content) • DOM (data structure) • JavaScript (behaviour) • Cascading Style Sheets (presentation)
HTML ELEMENT Standard PROPERTIES Standard METHODS Standard EVENTS This is not the complete listing. Standard COLLECTIONS
Cascading Style Sheets • Method for specifying properties for HTML elements • default and specific fonts, colours etc. • Allows easy modification of page styles • Style sheet can be modified rather than editing the html • Style sheet can be embedded in HTML or linked via an external file
CSS Structure and Syntax • General syntax: Selector{ property:value; property:value;} • The selector is normally the HTML element you want to style. • Each declaration consists of a property and a value.
CSS Structure & Syntax • CSS declarations always ends with a semicolon, and declaration groups are surrounded by curly brackets • The comment syntax is just like in C-programming: • /* this is a comment */ • You can specify and apply CSS-style formatting to an HTML element either by using an ID selectoror a Class selector.
Incorporating CSS There are three ways of inserting a style sheet: • External style sheet • Internal style sheet • Inline style
1. Incorporating CSS • 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. • The file should not contain any html tags. • 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>
1. Incorporating CSS • Example: External style sheet mystyle.css • hr {color:red;} • p {color:orange;text-align:center;} • body {background-color:#d0e4fe;} myHTML.html • <head><link rel="stylesheet" type="text/css" href="mystyle.css“ ></head>
2. Incorporating CSS • Internal style sheet • Suitable 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:red;} • p {color:orange; text-align:center;} • body {background-color:#d0e4fe;} • </style> • </head>
3. Incorporating CSS • Inline style sheet (Inside an HTML element) • An inline style loses many of the advantages of style sheets by mixing content with presentation. • 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: <p style="color:rgb(255,0,0);margin-left:20px"> Hello! </p> Avoid using the inline style!
Cascading Order of Styles • Cascading multiple styles (the list is in increasing order of priority) • 1. Browser default • 2. External style sheet • 3. Internal style sheet (in the head section) • 4. Inline style (inside an HTML element) Note: If the link to the external style sheet is placed after the internal style sheet in HTML <head>, the external style sheet will override the internal style sheet! #4 has the highest priority.
1. Applying CSS to an HTML element • You can apply CSS-style formatting to an HTML element either by using an ID selectoror a Class selector. • 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": • Do NOT start an ID name with a number! It will not work in Mozilla/Firefox. • General Syntax: #ID-name { Property:value; Property:value; /*... and so on.. */ } ID selector application: <h1 id=”ID-name”> Internet programming </h1>
2a. Applying CSS to an HTML element • You can apply CSS-style formatting to an HTML element either by using an ID selectoror a Class selector. • 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 any HTML elements with the same class. • The class selector uses the HTML class attribute, and is defined with a "." • General Syntax: • .class-name • { • Property:value; • Property:value; • /*... and so on.. */ • } class selector application: • <h1 class=”class-name”> Internet programming </h1> • <p class=”class-name”> Dynamic HTML: CSS, HTML, DOM, Javascript </p>
2b. Applying CSS to an HTML element • You can apply CSS-style formatting to an HTML element either by using an ID selectoror a Class selector. • class SELECTOR • You can also specify that only specific HTML elements should be affected by a • class. • General Syntax: /* this class selector is only applicable to paragraphs*/ p.class-name { Property:value; Property:value; /*... and so on.. */ } class selector application: <p class=”class-name”> Dynamic HTML: CSS, HTML, DOM, Javascript </p>
CSS Properties Index A continuously updated list of CSS properties can be found here: http://meiert.com/en/indices/css-properties/ http://www.w3schools.com/cssref/default.asp CSS Text: http://www.w3schools.com/css/css_text.asp CSS Demo: http://www.w3schools.com/css/demo_default.htm CSS Tables: http://www.w3schools.com/css/css_table.asp
CSS Examples • body { • font-family: Georgia, "Times New Roman", Times, serif; • color: blue; • background-color: #FFFF00 } • Similarly any property can be specified and modified • You can define your own selectors • .myStyle {color: blue} • Use with a class=“myStyle” attribute in the element you want to modify You will find more examples in our website
Center a Table with CSS CSS definitions: Centered, Fixed-width table • div.container { • width:98%; • margin:1%; • } • table.table1 { • text-align:center; • margin-left:auto; • margin-right:auto; • width:100px; • } • tr, td { • text-align:left; • } Applying your CSS styles in a table <div class="container"> <table class="table1"> ... </table> </div> http://www.granneman.com/webdev/coding/css/centertables/
More Examples? • Maybe here: • http://www.granneman.com/webdev/coding/css/ • Or just search internet with keyword css. • Or you can use freely accessible css layout, css template, css menu, … that you can search on internet. • If you can save time on site layout, why waste it?