190 likes | 370 Views
I'm the CSS to your HTML. A quick introduction to Cascading Style Sheets. Some Simple HTML. <html> <head> </head> <body> <h1>Title Text</h1> <p>A paragraph of text for you to read....</ p> </body> </html>. Text file containing HTML. Behind the Scenes of the Browser.
E N D
I'm the CSS to your HTML A quick introduction to Cascading Style Sheets
Some Simple HTML <html> <head> </head> <body> <h1>Title Text</h1> <p>A paragraph of text for you to read....</p> </body> </html> Text file containing HTML
Behind the Scenes of the Browser Empty Browser Window
Behind the Scenes of the Browser Find first thing to display, Create a box for it at top, extending full width
Behind the Scenes of the Browser It is a h1 element, place within box and give it some simple styling Title Text
Behind the Scenes of the Browser Find next element, create a box for it, below existing Title Text
Behind the Scenes of the Browser It’s a p element, fill to width of window Title Text A paragraph of text for you to read. A paragraph of text for you to read. A paragraph of text for you to read. A paragraph of text for you to read. A paragraph of text for you to read.
HTML Summary • HTML allows us to provide document CONTENT • The browser displays this content with some basic LAYOUT and STYLING • BUT: CSS allows us complete CONTROL over both layout and styling
Linking HTML to CSS • Several ways to do this • Simplest is tolink the HTML file to a CSS file • In the <head> element of the HTML file: <link href=“style.css” rel=“stylesheet” /> Index.html Style.css
Styling HTML Elements Name of the element h1 { font: arial; color: blue; } Visual style to apply Title Text A paragraph of text for you to read. A paragraph of text for you to read. A paragraph of text for you to read. A paragraph of text for you to read. A paragraph of text for you to read.
MovingHTML Elements Instead of the “normal” position, place 30px to the right p{ position: relative; right: 30px; } Title Text A paragraph of text for you to read. A paragraph of text for you to read. A paragraph of text for you to read. A paragraph of text for you to read. A paragraph of text for you to read.
Sizing HTML Elements We can specify exact sizes, or use percentages p{ position: relative; right: 30px; width: 500px; } Title Text A paragraph of text for you to read. A paragraph of text for you to read. A paragraph of text for you to read. A paragraph of text for you to read. A paragraph of text for you to read.
CSS Summary • We can link an HTML file to a CSS file • With CSS, for each element we can control: • Its visual appearance (font, colour, etc.) • How much space it takes up (size, borders, etc.) • Where it is placed • Relative to its “normal” position • Fixed within the browser window • “Floating” around until there is space for it
<h1> and <p> Are Not Enough! • There is more to a page than headings and paragraphs… • Web pages have logical "areas" Title, links, etc How can we create these “areas”? News, Ads, links, etc. text, text, text,
The <div> Element • Allows us to "group" other bits of HTML • We can give these groups names • Names can be “id” – only one item on the page with that name • Or “class” – any number of items with the same name <div id="heading"> <imgsrc="me.jpg" .... /> <h1>Title Text</h1> </div> <div class=“links"> <a href=“http:: .... /a> • <a href=“http:: .... /a> • <a href=“http:: .... /a> </div>
Styling Divs • We style divs just like elements • But identify them by their names #heading { font-size: 32px; background-color: gray; } Name of div (note the #) Styles to apply Title Text
Styling Smaller Areas • Divs group things together into a single unit • How can we style smaller areas? • The span element groups words together HTML <p>Herman Melville, author of <span class=“booktitle”>Moby Dick</span> was…</p> CSS .booktitle { font-style: italic; font-size: 120%; } Herman Melville, author of Moby Dickwas…
Summary • A Browser lays out and styles HTML in a “default” way • By linking the HTML file to a CSS file we can: • Control the appearance of things • Control the size of things • Control the position of things • By using <divs> and <spans> we can group things together • And control layout and style as above
Where Next? • TT284 Block 1 Part 5 • http://www.w3schools.com/css/ • Get a text editor, a browser and experiment! Thank You For Watching!Music: “Eskaton Upwards” by Torleyavailable from archive.org under aCreative Commons Attribution Share-alike 3.0license