100 likes | 204 Views
Creating Web Pages. Part 3. CASCADING STYLE SHEETS (CSS): What exactly are they?. Set of rules that define how a web browser should display an HTML page. Types of Style Sheets Inline Embedded External. What is meant by “cascading”?. div {color:#FF0000;} div.style1 {color:#FF0000;}
E N D
Creating Web Pages Part 3
CASCADING STYLE SHEETS (CSS):What exactly are they? • Set of rules that define how a web browser should display an HTML page. • Types of Style Sheets • Inline • Embedded • External • What is meant by “cascading”?
div {color:#FF0000;} div.style1 {color:#FF0000;} div.style2 {color:#FF0000;} <html> <head> <title>Cascading Style Sheets</title> CASCADING STYLE SHEETS (CSS):What do they look like? cssexample.html external.css <!-- Link to EXTERNAL style sheet --> <link href="external.css" type="text/css" rel="stylesheet"> <!-- EMBEDDED style sheet --> <style> div.style2 { color:#009900;} </style> browser </head> <body> <div>div style in external sheet</div> <div class="style1">div.style1 in external sheet</div> <div class="style2">div.style2 in embedded style sheet</div> <!-- INLINE style sheet --> <div style="color:#0000FF">inline style sheet</h3> </body> </html> <html> <head> <title>Cascading Style Sheets</title> <!-- Link to EXTERNAL style sheet --> <link href="external.css" type="text/css" rel="stylesheet"> <!-- EMBEDDED style sheet --> <style> div.style2 { color:#009900;} </style> </head> <body> <div>div style in external sheet</div> <div class="style1">div.style1 in external sheet</div> <div class="style2">div.style2 in embedded style sheet</div> <!-- INLINE style sheet --> <div style="color:#0000FF">inline style sheet</h3> </body> </html>
CASCADING STYLE SHEETS (CSS):How does CSS syntax work? GENERAL RULES: The syntax is composed of three parts: a selector, a property and a value: selector {property:value} where: selector = the HTML element/tag you wish to define property = the attribute you wish to change value = the setting to be assigned to the property body {color:black} The property and value are separated bya colon and are surrounded by curly brackets: p {font-family:"sans serif"} If the value contains multiple words,it should be enclosed in quotes: If there’s more than one property, separate each pair of properties with a semi-colon. p {text-align:center;color:red} p { text-align:center; color:black; font-family:arial; } To make style definitions easy to read, put one property on each line: GROUPS:
CASCADING STYLE SHEETS (CSS):How does CSS syntax work? GROUPS: You can group selectors. Use a comma to separate each pair of selectors: h1,h2,h3,h4,h5,h6 {color: green} CLASS SELECTORS: You can use the class selector to define different styles for the same type of HTML element: p.right {text-align:right} p.center {text-align:center} To make use of these defined class selectors, you then use the class attribute in your HTML document: <p class="right"> This paragraph will be right-aligned.</p> <p class="center"> This paragraph will be center-aligned.</p> .center {text-align:center} To define a style that will be used by all HTML elements that have a certain class, omit the tag name in the selector To use the defined style in the body of the document, specify the class attribute. <h1 class="center"> This heading will be center-aligned</h1> <p class="center"> This paragraph will also be center-aligned.</p> Source:www.w3schools.com
CASCADING STYLE SHEETS (CSS):What kind of formatting can style sheets do? 1. Font and background colors 2. Background images
CASCADING STYLE SHEETS (CSS):What kind of formatting can style sheets do? 3. Text properties 4. Font properties
CASCADING STYLE SHEETS (CSS):What kind of formatting can style sheets do? 5. Box properties