200 likes | 320 Views
WRT235: Writing in Electronic Environments. Basic CSS. Agenda. Introduce DOM Introduce basic CSS Inline styles Style sheets Start Module 4. DOM: Document Object Model. Model for parsing HTML Initiated in the browser Creates relationships between objects (parent-child nodes)
E N D
Agenda • Introduce DOM • Introduce basic CSS • Inline styles • Style sheets • Start Module 4
DOM: Document Object Model • Model for parsing HTML • Initiated in the browser • Creates relationships between objects (parent-child nodes) • Enables you to manipulate objects • CSS – styles, colors, transitions, positioning • Javascript – read, change, or remove objects in the HTML
CSS: Cascading Style Sheets • Allows us to add style to our HTML markup • Reusable • One rule for many objects • One CSS file for many pages • Cascade effect • Changes flow down to many different objects • Change all documents by changing rules • Saves time and makes revision easier
CSS: Cascading Style Sheets • CSS requires the DOM to work • CSS uses the hierarchical parent-child node and styles objects according to these relationships • Style specific objects based on names or attributes
CSS: Getting started • Prepare an HTML document in your text editor using our default structure • Add the following objects to your file: • 2 headers (<h1>) • 4 paragraphs (<p>) with lorenipsum text • A list with 4 items • 3 non-functional links (<a href=“#”>link 1</a>) • Save and test in browser
CSS: 3 Types of Styles • Inline styles • Inline embedded • External
CSS: 3 Inline styles • In your XHTML file, add the following attribute to one of your paragraphs: <p style=“color:green”;> • Save and test in browser • Generally, we don’t ever like to use inline styles • Why do you think that is?
CSS: 3 Inline Embedded Styles • In your html file or Thimble view add the following rules to the <head> section of your document. <style> p {color:green; font-size:20px:} </style> • Save and test in browser • We also don’t like to use this method. Why?
CSS: Anatomy • The basic anatomy of a CSS rule can be found in the embedded inline style method: p {color: green} {declaration block} selector property value
CSS: Anatomy The basic anatomy of a CSS rule can be found in the embedded inline style method: • Selector – indicates what object the style rule applies to • Declaration – a markup block that specific what will happen to the selector • Property – indicates what aspect of the selector will be styled • Value – determines what the property will be
CSS Property: color • Refers to the font color of the • Can take human readable values • red, green, blue, black • Ex. color:green; • Can take hex values • #FF0000, #00FF00, #0000FF, #000000 • More precise for monitor rendering • Can take rgba values • rgba(255,0,0,1)
CSS Property: color activity • Go back to your HTML file and practice changing the embedded style color with human readable, hex, and rgba values. • When using the rgba value, change the a to any number < 1. See what happens to the font color
CSS Property: border • Return to your HTML file • In the <style> section, ad the following: h1 {border:2px solid red} • See what happens
CSS Property: border Border can take 3 values after the colon • Thickness • Examples: thin, thick, 2px, 5px • Style • solid, dashed, dotted • Color • Same types of values for the color property
CSS Property: font-size Font-size can take various values • Pixels • 20px, 30px • em • 1em, 2em • Text values • Small, medium, large, xx-small
CSS: External The most desirable type of CSS is an external stylesheet that is linked to the XHTML document: • Enables separation of form and content • 1 style sheet to control the appearance of multiple webpage • Need only change the link to the .css file to change the style of a webpage
CSS: External • Open a new file in your text editor • Copy and paste the styles you have used for your embedded inline styles • Delete the <style> tags; you no longer need it here • You can retain the rules format used earlier • Personally, I prefer to space out my CSS rules p { color:red } • Save the file in the same location as your open XHTML doc as test.css
CSS: External cont. • In the <head> section of your working HTML document, include the following relative link with the appropriate file names: <link rel="stylesheet" type="text/css" media="screen" href=”mod4.css”> • Save and reload the XHTML page in your browser